<template lang="html">
  <div id="charts">
    <div id="sm" :style="{width:'100%',height:'98%'}"></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','api/af-revenue/sql/BusinessType',
  {data: {startDate: self.startdate, endDate: self.enddate,f_orgid: self.orgid}},
  {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()
    },
    orgid: {
      type: String
    }
  },
 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'
       },
        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()
   },
   'orgid' (val) {
     this.searchdata()
   }
 }

}
</script>
