<template lang="html">
  <div id="charts">
    <div id="info" :style="{width:'100%',height:'100%'}"></div>
  </div>
</template>

<script>
  import * as Util from '../../Util'
  import co from 'co'
  import echarts from 'echarts'
  import { HttpResetClass } from 'vue-client'

  let getData = function * (self,condition) {
    let load = new HttpResetClass()
    load.load('POST','rs/sql/getUserGasCount',
      {data:{condition:condition}},
      {resolveMsg: null, rejectMsg: null})
      .then((res) => {
        let arrparams = []
        let gasdata = []
        for (var i = 0; i < res.data.length; i++) {
          arrparams[i] = res.data[i].f_usertype
          gasdata[i] = res.data[i].f_pregas
        }
        self.set(arrparams,gasdata)
      })
  }
  export default {
    props: {
      startdate: {
        type: String,
        default: Util.toStandardDateString()
      },
      enddate: {
        type: String,
        default: Util.toStandardDateString()
      },
      condition: {
        type: String,
        default: '1=1'
      }
    },
    data () {
      title: '业务类型'
      return {
        xc: ''
      }
    },
    methods: {
      set (arrparams,gasdata) {
        this.xc = echarts.init(document.getElementById('info'))
        this.xc.setOption({
          title: {
            text: '用户用气量报表',
            subtext: '数据截止',
            x: 'center'
          },
          color: ['#3398DB'],
          tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
              type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis : [
            {
              type : 'category',
              data : arrparams,
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis : [
            {
              type : 'value'
            }
          ],
          series : [
            {
              name:'直接访问',
              type:'bar',
              barWidth: '30%',
              data:gasdata
            }
          ]
        })
      },
      searchdata (condition) {
        let getGen =getData(this,condition)
        co(getGen)
      }
    },
    watch: {
      'condition' (val) {
        console.log('ddddddd', val)
        this.searchdata(val)
      }
    }
  }
</script>
