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

<script>
  /* eslint-disable indent,key-spacing,no-labels */

  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','rs/sql/BusinessType',
  {data: {startDate: self.startdate, endDate: self.enddate,f_orgstr: self.f_orgstr}},
  {resolveMsg: null, rejectMsg: null})
  .then((res) => {
    self.texttile = '用户类型'
    let arrparams = []
    let numdata = []
    let pricedata = []
    for (var i = 0; i < res.data.length; i++) {
        arrparams[i] = res.data[i].name
        numdata[i] = res.data[i].num
        pricedata[i] = res.data[i].money
    }
    self.set(arrparams,numdata,pricedata)
  })
}
export default {
  props: {
    startdate: {
      type: String,
      default: Util.toStandardDateString()
    },
    enddate: {
      type: String,
      default: Util.toStandardDateString()
    },
    f_orgstr: {
      type: String,
      default: ''
    }
},
 data () {
    title: '业务类型'
   return {
     texttile: '',
     xc: ''
   }
 },
 methods: {
   set (arrparams,numdata,pricedata) {
     this.xc = echarts.init(document.getElementById('sm'))
     this.xc.setOption({
       title : {
         text: '收费类型笔数金额散列图',
         subtext: '数据查询来源',
         x: 'left',
         textStyle: {color: "#333333", fontSize: "18", fontWeight: "normal"}
       },
       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 : {
            data : [
              {type : 'average', name: '平均值'}
            ]
          }
        },
        {
          name:'金额',
          type:'bar',
          data:pricedata,
          markLine : {
          data : [
              {type : 'average', name : '平均值'}
            ]
          }
        }
      ]
     })
   },
   searchdata () {
     let getGen = getData(this)
     co(getGen)
   }
 },
 ready () {
   this.searchdata()
 },
 watch: {
   'startdate' (val) {
     this.searchdata()
   },
   'enddate' (val) {
     this.searchdata()
   },
   'f_orgstr' (val) {
     this.searchdata()
   }
 }

}
</script>
