<template>
  <div class="price-trend">
    <div class="chart" ref="chart" />
    <Select class="custom-select" v-model="disease">
      <Option v-for="item in options" :key="item" :value="item">{{item}}</Option>
    </Select>
  </div>
</template>

<script>
export default {
  name: 'PriceTrend',
  data() {
    return {
      disease: '2019',
      options: ['2019', '2020'],
      chart: null,
      option: {
        tooltip: {
          trigger: 'axis',
          confine: true,
        },
        legend: {
          width: '100%',
          textStyle: {
            color: '#ccc',
            fontSize: this.fontSize,
          },
          data: ['综合-具有可比性', '综合-不具可比性', '海水产品-具有可比性', '海水产品-不具可比性', '淡水产品-具有可比性', '淡水产品-不具可比性'],
        },
        grid: {
          top: '30%',
          left: '5%',
          right: '1%',
          bottom: 'auto',
          width: 'auto',
          height: '60%',
          containLabel: true,
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          axisLine: {
            lineStyle: {
              color: 'rgba(91,213,255,0.1)'
            }
          },
          axisLabel: {
            textStyle: {
              color: '#46b9ef',
            },
            fontSize: this.fontSize,
          },
          data: ['2019-01', '2019-02', '2019-03', '2019-04', '2019-05', '2019-06', '2019-07', '2019-08', '2019-09', '2019-10', '2019-11', '2019-12', ],
        },
        yAxis: [
          {
            type: 'value',
            // name: '单位：个',
            max: 1.20,
            min: 0.95,
            interval: 0.05,
            axisLine: {
              show: false,
            },
            axisLabel: {
              textStyle: {
                color: '#fff',
              },
              fontSize: this.fontSize,
            },
            nameTextStyle: {
              color: '#ccc',
              fontSize: this.fontSize,
            },
            splitLine: {
              lineStyle: {
                color: 'rgba(91,213,255,0.1)'
              }
            },
          },
        ],
        series: [
          {name: '综合-具有可比性', itemStyle: {color: '#e052fc'}, type: 'line', data: [1, 1.02, 1.05, 1.03, 1.04, 1, 1.1, 1.05, 1.02, 1, 1.1, 1.08]},
          {name: '综合-不具可比性', itemStyle: {color: '#8078fb'}, type: 'line', data: [1.05, 1.04, 1.15, 1.08, 1.14, 1, 1, 1.05, 1.12, 1, 1.12, 1.08]},
          {name: '海水产品-具有可比性', itemStyle: {color: '#43befc'}, type: 'line', data: [1, 1.06, 1.03, 1.13, 1.04, 1.02, 1, 1.05, 1.02, 1, 1.1, 1.05]},
          {name: '海水产品-不具可比性', itemStyle: {color: '#1ef9f4'}, type: 'line', data: [1.03, 1.08, 1.05, 1.05, 1.04, 1.07, 1.01, 1.12, 1.02, 1, 1, 1.08]},
          {name: '淡水产品-具有可比性', itemStyle: {color: '#3afe85'}, type: 'line', data: [1.08, 1.1, 1.02, 1.06, 1.04, 1.05, 1.12, 1.05, 1.05, 1, 1.12, 1.02]},
          {name: '淡水产品-不具可比性', itemStyle: {color: '#fcee38'}, type: 'line', data: [1.02, 1.05, 1.05, 1.1, 1.04, 1.1, 1.01, 1, 1.02, 1, 1.11, 1.04]},
        ],
        dataZoom: [{
          start: 10,
          end: 80,
          backgroundColor: '#105179',
          fillerColor: '#46b9ef',
          borderColor: 'transparent',
          bottom: '2%',
          height: 10,
          borderRadius: 10,
          handleSize: '200%',
          handleStyle: {
            color: '#fff',
          },
          textStyle: {
            color: '#fff',
          },
        }],
      }
    }
  },
  mounted() {
    // this.$nextTick(this.init)
    setTimeout(this.init, 0)
  },
  computed: {
    fontSize() {
      return Math.floor(screen.height * 1.48 / 100)
    },
  },
  methods: {
    init() {
      this.chart = this.$echarts.init(this.$refs.chart)
      this.chart.setOption(this.option)
    }
  }
}
</script>

<style lang="stylus" scoped>
.price-trend
  width 100%
  height 100%
  >.chart
    width 100%
    height 95%
</style>
