<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','rs/sql/GaspriceHas',
  {data: {startDate: self.startdate, endDate: self.enddate}},
  {resolveMsg: null, rejectMsg: null})
  .then((res) => {
    self.texttile = '用户类型'
    let arrparams = []
    let gasdata = []
    let pricedata = []
    for (var i = 0; i < res.data.length; i++) {
        arrparams[i] = res.data[i].name
        gasdata[i] = res.data[i].gas_value
        pricedata[i] = res.data[i].money_value
    }
    self.set(arrparams,gasdata,pricedata)
  })
}
export default {
  props: {
    startdate: {
    type: String,
    default: Util.toStandardDateString()
  },
  enddate: {
    type: String,
    default: Util.toStandardDateString()
  }
},
 data () {
   return {
     texttile: '',
     xc: ''
   }
 },
 methods: {
   set (arrparams,gasdata,pricedata) {
     this.xc = echarts.init(document.getElementById('gph'))
     this.xc.setOption({
       title : {
         text: '气量金额散列图',
         subtext: '数据来源',
         x: 'center'
       },
       tooltip : {
         trigger: 'axis'
       },
       legend: {
         orient: 'vertical',
         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:gasdata,
          markPoint : {
            data : [
              {type : 'max', name: '最大值'},
              {type : 'min', name: '最小值'}
            ]
          },
          markLine : {
            data : [
              {type : 'average', name: '平均值'}
            ]
          }
        },
        {
          name:'金额',
          type:'bar',
          data:pricedata,
          markPoint : {
            data : [
              {type : 'max', name: '最大值'},
              {type : 'min', name: '最小值'}
            ]
          },
          markLine : {
          data : [
              {type : 'average', name : '平均值'}
            ]
          }
        }
      ]
     })
   },
   searchdata () {
     let getGen =getData(this)
     co(getGen)
   }
 },
 ready () {
   this.searchdata()
 },
 watch: {
   'startdate' (val) {
     this.searchdata()
   },
   'enddate' (val) {
     this.searchdata()
   }
 }

}
</script>
