<template>
  <div>
    <bgBox class="bgBox" bgType="g-bg2" :tabChange="tabChange" :tabIndex="1">
      <leftBox class="lefBox animated fadeInLeft" />
      <cmap />
      <HorizontalHistogram
        style="position: absolute; right: 50px; top: 115px; z-index: 10"
        v-if="isHorizontal"
        id="`各区域移栽面积1`"
        title="各区域移栽面积"
        :area="HorizontalArea"
        :dataArray="HorizontalArray"
        class="animated fadeInRight"
      />
      <wavyLineChart
        id="`本月移栽数量趋势`"
        style="position: absolute; right: 50px; top: 460px; z-index: 10"
        v-if="isTrend"
        title="本月移栽数量趋势"
        :area.sync="trendarea"
        :dataArray.sync="trendDataArray"
        class="animated fadeInRight"
      />
      <wavyLineChart
        id="`本年移栽数量趋势`"
        style="position: absolute; right: 50px; top: 760px; z-index: 10"
        v-if="isTrend"
        title="本年移栽数量趋势"
        :area.sync="trendarea"
        class="animated fadeInRight"
        :dataArray.sync="trendDataArray"
      />
    </bgBox>
  </div>
</template>

<script>
import bgBox from '@/components/bgBox/index.vue'
import cmap from './cmap.vue'
import leftBox from './leftBox.vue'
import HorizontalHistogram from '@/components/Customize/HorizontalHistogram'
import wavyLineChart from '@/components/Customize/wavyLineChart'
window.map = {}
export default {
  components: {
    bgBox,
    leftBox,
    cmap,
    wavyLineChart,
    HorizontalHistogram,
  },
  data() {
    return {
      HorizontalArea: [],
      HorizontalArray: {
        Done: [],
      },
      isHorizontal: true,
      trendarea: [],
      trendDataArray: {
        LastYear: [],
        thisYear: [],
      },
      isTrend: true,
    }
  },
  computed: {},
  async created() {
    this.$util.autoVueFn(
      [
        {
          time: 1000 * 5,
          fn: this.getAnalysisOfTransplantingSituation,
        },
        {
          time: 1000 * 5,
          fn: this.getTrendAnalysis,
        },
      ],
      this
    )
  },
  mounted() {},
  unmounted() {
    window.map.destroy()
  },
  methods: {
    tabChange(val) {
      if (val === 0) {
        this.$router.push(`/page1`)
      }
      console.log(`val`, val)
    },
    getTrendAnalysis() {
      this.$http.get(`/api/transplantTrendAnalysis`).then((res) => {
        const area = []
        const dataArray = {
          LastYear: [],
          thisYear: [],
        }
        res.forEach((element) => {
          area.push(element.时间)
          dataArray.LastYear.push(element.去年)
          dataArray.thisYear.push(element.今年)
        })
        this.trendarea = area
        this.trendDataArray = dataArray
        this.isTrend = true
      })
    },
    getAnalysisOfTransplantingSituation() {
      this.$http.get(`/api/analysisOfTransplantingSituation`).then((res) => {
        const area = []
        const dataArray = {
          Done: [],
          Percentage: [],
        }
        const date = res.sort((a, b) => b.已移载 - a.已移载)
        date.forEach((element) => {
          area.push(element.名称.slice(0, 2))
          dataArray.Done.push(element.已移载)
        })
        this.HorizontalArea = area
        this.HorizontalArray = dataArray
        this.isHorizontal = true
      })
    },
  },
}
</script>

<style lang="less" scoped>
.bgBox {
  .lefBox {
    position: absolute;
    z-index: 10;
    left: 47px;
    top: 120px;
  }
  ::v-deep {
    .bg {
      position: absolute;
      z-index: 9;
    }
  }
}
</style>
