<template lang="html">
  <div id="charts">
    <div id="utp" :style="{width:'100%',height:'98%'}"></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/sellinggasvalue',
  {data: {startDate: self.startdate, endDate: self.enddate,key:'f_payment',f_orgid: self.orgid}},
  {resolveMsg: null, rejectMsg: null})
  .then((res) => {
    console.log(res)
    let arrparams = []
    let moneydata = []
    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].money_value
      moneydata.push(item)
    }
    console.log(arrparams)
    console.log(moneydata)
    self.set(arrparams,moneydata)
  })
}
export default {
  props: {
    startdate: {
      type: String,
      default: Util.toStandardDateString()
    },
    enddate: {
      type: String,
      default: Util.toStandardDateString()
    },
    orgid : {
      type: String
    }
},
 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()
   },
   'orgid' (val) {
     this.searchdata()
   }
 }

}
</script>
