<template lang="html">
  <div id="charts">
    <div id="bm" :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/userfilesvalues',
    {data: {startDate: self.startdate, endDate: self.enddate, f_orgid: self.orgid}},
    {resolveMsg: null, rejectMsg: null})
    .then((res) => {
      self.texttile = '用户类型'
      // let arrparams = []
      console.log('获取数据。。', res.data)
      let num1 = []
      let num2 = []
      let num3 = []
      let naturedata = []
      for (var i = 0; i < res.data.length; i++) {
        naturedata[i] = res.data[i].f_user_nature
      }
      num1[0] = res.data[0].number
      num2[0] = res.data[1].number
      num3[0] = res.data[2].number
      self.set(naturedata, num1, num2, num3)
    })
}
export default {
  props: {
    startdate: {
      type: String,
      default: Util.toStandardDateString()
    },
    enddate: {
      type: String,
      default: Util.toStandardDateString()
    },
    orgid: {
      type: String
    }
  },
  data () {
    title: '银行管理'
    return {
      texttile: '',
      xc: '',

      minyongvalue: [],
      feiminyongvalue: []
    }
  },
  methods: {
    set (naturedata, num1, num2, num3) {
      this.xc = echarts.init(document.getElementById('bm'))
      this.xc.setOption({
        color: ['#ed7d31', '#00b050', '#5b9bd5'],
        title: {
          text: '新增用户散列图',
          subtext: '数据查询来源',
          x: 'left'
        },
        tooltip: {
          trigger: 'item',
          formatter: function (params) {
            let str = ''
            str += params.seriesName + ': ' + params.value + '户'
            return str
          }
        },
        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: ['新增用户数据']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '工业户数',
            type: 'bar',
            data: num1,
            markLine: {
              data: [
                {type: 'average', name: '平均值'}
              ]
            }
          },
          {
            name: '民用户数',
            type: 'bar',
            data: num2,
            markLine: {
              data: [
                {type: 'average', name: '平均值'}
              ]
            }
          },
          {
            name: '商业户数',
            type: 'bar',
            data: num3,
            markLine: {
              data: [
                {type: 'average', name: '平均值'}
              ]
            }
          }
        ]
      })
    },
    searchdata () {
      let getGen = getData(this)
      co(getGen)
    }
  },
  ready () {
    this.searchdata()
  },
  watch: {
    'startdate' (val) {
      this.searchdata()
    },
    'enddate' (val) {
      this.searchdata()
    },
    'orgid' (val) {
      this.searchdata()
    }
  }

}
</script>
