<template>
  <div ref="dom" class="charts chart-line"></div>
</template>

<script>
import echarts from 'echarts'
import tdTheme from '../theme.json'
import { on, off } from '@/libs/tools'
echarts.registerTheme('tdTheme', tdTheme)
export default {
  name: 'AcceptLineEchart',
  props: {
    value: Object,
    text: String,
    subtext: String
  },
  data () {
    return {
      dom: null
    }
  },
  methods: {
    resize () {
      this.dom.resize()
    }
  },
  mounted () {
    this.$nextTick(() => {
      let xAxisData = this.value.xAxis
      let seriesData1 = this.value.seriesData[0].data
      let seriesData2 = this.value.seriesData[1].data
      let seriesData3 = this.value.seriesData[2].data
      let option = {
        title: {
          text: this.text,
          subtext: this.subtext,
          left: 'center'
        },
        legend: {
          data: ['受理量', '同比受理量', '环比受理量'],
          // top: 20,
          right: '0'
        },
        tooltip: {
          trigger: 'axis'
        },
        xAxis: {
          type: 'category',
          data: xAxisData
        },
        yAxis: {
          type: 'value'
        },
        toolbox: {
          // feature: {
          //   dataZoom: {
          //     yAxisIndex: 'none'
          //   },
          //   restore: {},
          //   saveAsImage: {}
          // },
          // right: 20
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        series: [{
          name: '受理量',
          data: seriesData1,
          type: 'line'
        }, {
          name: '同比受理量',
          data: seriesData2,
          type: 'line'
        }, {
          name: '环比受理量',
          data: seriesData3,
          type: 'line'
        }]
      }
      this.dom = echarts.init(this.$refs.dom, 'tdTheme')
      this.dom.setOption(option)
      on(window, 'resize', this.resize)
    })
  },
  beforeDestroy () {
    off(window, 'resize', this.resize)
  }
}
</script>
