<template>
  <div id="container" :style="`background-image: url(${require('@/assets/images/stars-bg.png')})`">
    <GuangdongMap />
    <ThemeTitle>广东省生产专题</ThemeTitle>
    <div class="area">
      <p>当前广东省养殖面积</p>
      <b v-if="area"><m-flip :value="area"/></b>
      <span>公顷</span>
    </div>
    <div class="box1">
      <m-card mode="2" title="各种类养殖产量(吨)">
        <DataList :list="production"/>
      </m-card>
    </div>
    <div class="box2">
      <m-card mode="2" title="各市养殖面积(亩)">
        <ProductionList :list="cityData"/>
      </m-card>
    </div>
    <div class="box3">
      <m-card mode="2" title="特色品种养殖产量">
        <m-chart :showLegend="false" :options="options" :data="data" />
      </m-card>
    </div>
  </div>
</template>

<script>
import DataList from './components/list'
import ProductionList from './components/production-list'
import ThemeTitle from './components/title'
import GuangdongMap from './components/map'
import axios from 'axios'
export default {
  name: 'GDProduction',
  components: {
    DataList,
    ProductionList,
    ThemeTitle,
    GuangdongMap,
  },
  data() {
    return {
      area: 0,
      production: [],
      specialProduction: [],
      cityData: [],
      options: {
        xAxis: {
          data: [],
        },
        yAxis: {
          name: '(吨)',
        },
        series: {
          type: 'bar',
          barWidth: '40%',
          itemStyle: {
            shadowColor: '#0076FF',
            shadowBlur: 6,
            color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {offset: 0, color: '#1FECFF'},
              {offset: 1, color: '#B645FF'}
            ])
          },
        }
      },
      data: [],
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      axios.get(this.$api.FILE_URL + 'gd-production.json').then(res => {
        for(let key in res.data) {
          this[key] = res.data[key]
        }
        const chartData = []
        this.specialProduction.forEach(item => {
          this.options.xAxis.data.push(item.name)
          chartData.push(item.value)
        })
        this.data = [{data: chartData}]
      })
    }
  }
}
</script>

<style lang="stylus" scoped>
#container
  $gd-layout()
  grid-template-areas \
    'box1 . box2'\
    'box1 . box2'\
    'box3 box3 box2'
  grid-template-rows 1fr 1fr 1fr
  grid-template-columns 1fr 3fr 1fr
  .box1
    grid-area box1
  .box2
    grid-area box2
  .box3
    grid-area box3
  .area
    font-size 1.8rem
    color $color-map(1)
    position absolute
    top 10%
    left 0
    right 0
    text-align center
    p
      color #fff
      font-family $font-pang
    b
      font-size 3rem
    >span
      font-family $font-pang
</style>
