<template lang="html">
  <div id="charts">
    <div id="gph" :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) {
  let load = new HttpResetClass()
  load.load('POST', 'api/af-revenue/sql/queryHouseholdsReport',
    {data: {startDate: self.startdate, endDate: self.enddate, f_orgid: self.orgid}},
    {resolveMsg: null, rejectMsg: null})
    .then((res) => {
      let arrparams = []
      let numdata = []
      for (var i = 0; i < res.data.length; i++) {
        arrparams[i] = res.data[i].name
        numdata[i] = res.data[i].num
      }
      self.set(arrparams, numdata)
    })
}
export default {
  props: {
    startdate: {
      type: String,
      default: Util.toStandardDateString()
    },
    enddate: {
      type: String,
      default: Util.toStandardDateString()
    },
    orgid: {
      type: String
    }
  },
  data () {
    title: '站点管理'
    return {
      texttile: '',
      xc: ''
    }
  },
  methods: {
    set (arrparams, numdata, gasdata, pricedata) {
      this.xc = echarts.init(document.getElementById('gph'))
      this.xc.setOption({
        title: {
          text: '户数统计散列图',
          subtext: '数据查询来源',
          x: 'left'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          x: 'left',
          y: 'bottom',
          data: ['户数']
        },
        toolbox: {
          show: true,
          feature: {
            dataView: {show: true, readOnly: false},
            magicType: {show: true, type: ['line', 'bar']},
            restore: {show: true},
            saveAsImage: {show: true}
          }
        },
        calculable: true,
        xAxis: [
          {
            type: 'category',
            data: arrparams
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '户数',
            type: 'bar',
            data: numdata,
            markLine: {
            },
            itemStyle: {
              normal: {
                // 这里设置每个柱子颜色不一样
                color: function (arrparams) {
                  // 定义一个颜色数组colorList
                  var colorList = ['#cca272', '#74608f', '#d7a02b', '#c8ba23']
                  return colorList[arrparams.dataIndex]
                }
              }
            }
          }
        ]
      })
    },
    searchdata () {
      let getGen = getData(this)
      co(getGen)
    }
  },
  ready () {
    this.searchdata()
  },
  watch: {
    'startdate' (val) {
      this.searchdata()
    },
    'enddate' (val) {
      this.searchdata()
    },
    'orgid' (val) {
      this.searchdata()
    }
  }

}
</script>

