Newer
Older
CloudBrainNew / src / views / cityConstruction / components / projects / components / projectLine.vue
wangxitong on 29 Apr 2021 2 KB 0429 submit
<!--
 * @Description: 历年各类项目数量
 * @Author: 王晓颖
 * @Date: 2020-11-30 17:00:18
 -->
<template>
  <single-layout title="历年项目数量" @click="getData">
    <div style="width: 100%;height:100%;">
      <gradient-line-chart
        :id="options.id"
        :unit="options.unit"
        :height="options.height"
        :legend="options.legend"
        :xAxisData="options.xAxisData"
        :seriesData="options.seriesData"
      />
    </div>
  </single-layout>
</template>

<script>
import GradientLineChart from '@/components/lineChart/gradientLineChart'
import {fetchProjectCountByYear} from '@/api/projectManage'
import SingleLayout from '@/components/layout/singleLayout'
export default {
  name: 'ProjectLine',
  components: {SingleLayout, GradientLineChart},
  data () {
    return {
      colors: ['255,45,85', '0,144,255', '255,204,0', '0,254,74'],
      options: {
        id: 'project_line',
        height: '100%',
        width: '100%',
        unit: '项',
        xAxisData: ['园林项目', '市政项目', '建筑项目', '交通项目', '水利项目' ],
        legend: ['2018', '2019', '2020'],
        seriesData: [
          {name: '2020', data: [ 0, 0, 0, 0, 0 ], color: '255,45,85'},
          {name: '2019', data: [0, 0, 0, 0, 0], color: '0,144,255'},
          {name: '2018', data: [0, 0, 0, 0, 0], color: '255,204,0'}
        ]
      }
    }
  },
  created () {
    this.getData()
  },
  methods: {
    getData () {
      const currentYear = new Date().getFullYear()
      const threeYear = currentYear - 2
      const yearRange = [threeYear.toString(), (currentYear).toString()]
      fetchProjectCountByYear(yearRange).then(response => {
        if (response.code === 200) {
          // debugger
          const data = response.data
          const datalength = data.length
          this.options.legend = data.map(item => { return item.year.toString() })
          this.options.xAxisData = data[0].data.map(item => { return item.type })
          const dataFilter = []
          for (let i = 0; i < datalength; i++) {
            const value = data[i].data.map(item => item.value)
            dataFilter.push({
              name: data[i].year.toString(), data: value, color: this.colors[i]
            })
          }
          this.options.seriesData = dataFilter
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>