<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
const animationDuration = 2000
export default {
  mixins: [resize],
  props: {
    paytotalfeeData: {
      type: Array,
      default: function() {
        return []
      }
    },
    monthData: {
      type: Array,
      default: function() {
        return []
      }
    },
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '80%'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  created() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        legend: {
          show: true,
          top: 0,
          right: '5%'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [{
          type: 'category',
          boundaryGap: false,
          data: this.monthData
        }],
        yAxis: [{
          type: 'value',
          axisTick: {
            show: true
          }
        }],
        series: [{
          name: '销售总额(元)',
          type: 'line',
          smooth: true,
          symbolSize: 3,
          showSymbol: false,
          symbol: 'emptyCircle',
          lineStyle: {
            color: '#417DE6'
          },
          itemStyle: {
            color: '#417DE6',
            borderWidth: 2
          },
          areaStyle: {
            color: {
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [{
                offset: 0, color: 'rgba(65, 125, 230, 0.2)' // 0% 处的颜色
              }, {
                offset: 1, color: 'rgba(65, 125, 230, 0)'// 100% 处的颜色
              }]
            }
          },
          data: this.paytotalfeeData,
          animationDuration: animationDuration
        }]
      })
    }
  }
}
</script>
