<template>
  <div class="data-identify">
    <div>
      <p><span/>海洋种类</p>
      <span class="tips">本月识别种类：鱿鱼、鲳鱼、鲷鱼、尤头鱼</span>
      <div class="chart" ref="chart" />
    </div>
    <div>
      <p><span/>种群数量</p>
      <span class="tips">本月识别种类：鱿鱼、鲳鱼、鲷鱼、尤头鱼</span>
      <div class="chart" ref="chart2" />
    </div>
  </div>
</template>

<script>
const mock = [
  {year: '2020.01', value: 35},
  {year: '2020.02', value: 29},
  {year: '2020.03', value: 33},
  {year: '2020.04', value: 20},
  {year: '2020.05', value: 36},
  {year: '2020.06', value: 25},
  {year: '2020.07', value: 30},
  {year: '2020.08', value: 28},
]
const mock2 = [
  {year: '2020.01', value: 35000},
  {year: '2020.02', value: 29000},
  {year: '2020.03', value: 33000},
  {year: '2020.04', value: 20000},
  {year: '2020.05', value: 36000},
  {year: '2020.06', value: 25000},
  {year: '2020.07', value: 30000},
  {year: '2020.08', value: 28000},
]
import echarts from 'echarts'
export default {
  name: 'DataIdentify',
  data() {
    return {
      option: {
        tooltip: {
          trigger: 'axis',
          confine: true,
        },
        legend: {
          show: false,
          // width: '100%',
          // textStyle: {
          //   color: '#ccc',
          //   fontSize: this.fontSize,
          // },
          // data: ['综合-具有可比性', '综合-不具可比性', '海水产品-具有可比性', '海水产品-不具可比性', '淡水产品-具有可比性', '淡水产品-不具可比性'],
        },
        grid: {
          top: '20%',
          left: '3%',
          right: '3%',
          bottom: 'auto',
          width: 'auto',
          height: '60%',
          containLabel: true,
        },
        xAxis: {
          type: 'category',
          axisLine: {
            lineStyle: {
              color: 'rgba(91,213,255,0.1)'
            }
          },
          axisLabel: {
            textStyle: {
              color: '#46b9ef',
            },
            fontSize: this.fontSize,
          },
          data: mock.map(item => item.year)
        },
        yAxis: [
          {
            type: 'value',
            name: '单位：个',
            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: [
          {itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {offset: 0, color: '#0fa8f1'},
              {offset: 1, color: '#775deb'}
            ]),
            barBorderRadius: [10, 10, 10, 10],
          }, type: 'bar', barWidth: '20%', data: mock.map(item => item.value)},
        ],
        dataZoom: [{
          start: 0,
          end: 100,
          backgroundColor: '#105179',
          fillerColor: '#46b9ef',
          borderColor: 'transparent',
          left: '5%',
          right: '5%',
          bottom: '13%',
          height: 10,
          borderRadius: 10,
          handleSize: '200%',
          handleStyle: {
            color: '#fff',
          },
          textStyle: {
            color: '#fff',
          },
        }],
      },
      option2: {
        tooltip: {
          trigger: 'axis',
          confine: true,
        },
        legend: {
          show: false,
        },
        grid: {
          top: '20%',
          left: '3%',
          right: '3%',
          bottom: 'auto',
          width: 'auto',
          height: '60%',
          containLabel: true,
        },
        xAxis: {
          type: 'category',
          axisLine: {
            lineStyle: {
              color: 'rgba(91,213,255,0.1)'
            }
          },
          axisLabel: {
            textStyle: {
              color: '#46b9ef',
            },
            fontSize: this.fontSize,
          },
          data: mock2.map(item => item.year)
        },
        yAxis: [
          {
            type: 'value',
            name: '单位：尾',
            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: [
          {itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {offset: 0, color: '#ffe225'},
              {offset: 1, color: '#f6a316'}
            ]),
            barBorderRadius: [10, 10, 10, 10],
          }, type: 'bar', barWidth: '20%', data: mock2.map(item => item.value)},
        ],
        dataZoom: [{
          start: 0,
          end: 100,
          backgroundColor: '#105179',
          fillerColor: '#46b9ef',
          borderColor: 'transparent',
          left: '5%',
          right: '5%',
          bottom: '13%',
          height: 10,
          borderRadius: 10,
          handleSize: '200%',
          handleStyle: {
            color: '#fff',
          },
          textStyle: {
            color: '#fff',
          },
        }],
      },
    }
  },
  mounted() {
    setTimeout(this.init, 0)
  },
  computed: {
    sizeRate() {
      return Number((screen.height / 800).toFixed(1))
    },
    fontSize() {
      return this.sizeRate * 12
    },
  },
  methods: {
    init() {
      this.$echarts.init(this.$refs.chart).setOption(this.option)
      this.$echarts.init(this.$refs.chart2).setOption(this.option2)
    }
  },
}
</script>

<style lang="stylus" scoped>
.data-identify
  width 100%
  height 100%
  overflow hidden
  >div
    width 100%
    height 50%
    position relative
    span
      display block
      text-align center
      color $edgeColor
    p
      display flex
      font-size 1.2rem
      font-weight bold
      align-items center
      span
        display inline-block
        width .3rem
        height 1.2rem
        background $edgeColor
        margin-right .5rem
    >.chart
      height calc(100% - 2rem)
</style>
