<template>
  <div id="container" :style="`background-image: url(${require('@/assets/images/stars-bg.png')})`">
    <ThemeTitle class="theme">广东省产业布局分析专题</ThemeTitle>
    <div class="box1">
      <m-card mode="2" title="渔业经济产值">
        <m-chart :options="options1" :data="data1"/>
      </m-card>
    </div>
    <div class="box2">
      <m-card mode="2" title="渔业经济产量">
        <m-chart :options="options2" :data="data2"/>
      </m-card>
    </div>
    <div class="box3">
      <m-card mode="2" title="渔业加工产量">
        <m-chart :options="options3" :data="data3"/>
      </m-card>
    </div>
    <div v-for="(item, index) in fishChartData.value" :key="item.name" :class="`box${4 + index}`">
      <m-card mode="2" :title="`特色品种鱼苗数量 - ${item.name}`">
        <m-chart :options="getOptions(item)" :data="[item]" :showLegend="false"/>
      </m-card>
    </div>
  </div>
</template>

<script>
import ThemeTitle from './components/title'
import axios from 'axios'
export default {
  name: 'GDIndustry',
  components: {
    ThemeTitle,
  },
  data() {
    return {
      options1: {
        legend: {
          // top: '2%',
          left: '24%',
          top: '10%',
          itemWidth: 10,
          itemHeight: 10,
        },
        xAxis: {
          data: [],
        },
        yAxis: {
          name: '(万元)',
        },
        series: {
          type: 'bar',
          barWidth: '40%',
          stack: '总量',
        }
      },
      data1: [],
      options2: {
        legend: {
          // top: '2%',
          left: '38%',
          top: '10%',
          itemWidth: 10,
          itemHeight: 10,
        },
        xAxis: {
          data: [],
        },
        yAxis: {
          name: '(吨)',
        },
        series: {
          type: 'bar',
          barWidth: '40%',
          stack: '总量',
        }
      },
      data2: [],
      options3: {
        colors: ['#71C012', '#FFCE34', '#F47C1F'],
        legend: {
          // top: '2%',
          left: '32%',
          top: '10%',
          itemWidth: 10,
          itemHeight: 10,
        },
        grid: {
          right: '5%',
        },
        xAxis: {
          data: [],
          boundaryGap: false,
        },
        yAxis: {
          name: '(吨)',
        },
        series: {
          type: 'line',
          stack: '总量',
          areaStyle: {},
          symbol: 'circle',
        }
      },
      data3: [],
      fishChartData: {
        name: [],
        value: [],
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      axios.get(this.$api.FILE_URL + 'gd-industry.json').then(res => {
        const {output, production, processProduction, fishProduction} = res.data
        const textStyle = {
          color: '#ccc',
          fontSize: this.fontSize,
        }
        this.options1.xAxis.data = output.name
        this.options1.legend.textStyle = textStyle
        this.data1 = output.value
        this.options2.xAxis.data = production.name
        this.options2.legend.textStyle = textStyle
        this.data2 = production.value
        this.options3.xAxis.data = processProduction.name
        this.options3.legend.textStyle = textStyle
        this.data3 = processProduction.value
        this.fishChartData = fishProduction
      })
    },
    getOptions(data) {
      return {
        colors: [['#1FECFF', '#0076FF']],
        xAxis: {
          data: this.fishChartData.name,
        },
        yAxis: {
          name: `(${data.unit})`,
        },
        series: {
          type: 'bar',
          barWidth: '40%',
        }
      }
    },
  },
  computed: {
    fontSize() {
      return Math.floor(screen.height * 1.48 / 100) / 1.2
    },
  }
}
</script>

<style lang="stylus" scoped>
#container
  $gd-layout()
  grid-template-areas \
    '. theme .'\
    'box1 box2 box3'\
    'box4 box5 box6'\
    'box7 box8 box9'
  grid-template-rows 4rem 1fr 1fr 1fr
  grid-template-columns 1fr 1fr 1fr
  .theme
    grid-area theme
    width 120%
    margin-left -10%
  .box1
    grid-area box1
  .box2
    grid-area box2
  .box3
    grid-area box3
  .box4
    grid-area box4
  .box5
    grid-area box5
  .box6
    grid-area box6
  .box7
    grid-area box7
  .box8
    grid-area box8
  .box9
    grid-area box9
</style>
