<template lang="html">
  <div id="charts">
    <div id="utp" :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) => {
    console.log(res)
    let arrparams = []
    let gasdata = []
    for (var i = 0; i < res.data.length; i++) {
        let item = {}
        arrparams[i] = res.data[i].name + '￥/m³'
        item.name = res.data[i].name + '￥/m³'
        item.value = res.data[i].gas_value
        gasdata.push(item)
    }
    console.log(arrparams)
    console.log(gasdata)
    self.set(arrparams,gasdata)
  })
}
export default {
  props: {
    startdate: {
    type: String,
    default: Util.toStandardDateString()
  },
  enddate: {
    type: String,
    default: Util.toStandardDateString()
  }
},
 data () {
   return {
     xc: ''
   }
 },
 methods: {
   set (arrparams,gasdata) {
     this.xc = echarts.init(document.getElementById('utp'))
     this.xc.setOption({
       tooltip: {
         trigger: 'item',
         formatter: '{a} <br/>{b}: {c}m³ ({d}%)'
       },
       legend: {
         x: 'left',
         y: 'bottom',
         data: arrparams
       },
    series : [
      {
            name: '访问来源',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:gasdata,
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
 })
},
   searchdata () {
     let getGen =getData(this)
     co(getGen)
   }
 },
 ready () {
   this.searchdata()
 },
 watch: {
   'startdate' (val) {
     this.searchdata()
   },
   'enddate' (val) {
     this.searchdata()
   }
 }

}
</script>
