Newer
Older
CloudBrainNew / src / views / cityConstruction / components / construction / components / constructionBar.vue
wangxitong on 29 Apr 2021 1 KB 0429 submit
<!--
 * @Description:
 * @Author: 王晓颖
 * @Date:
 -->
<template>
  <single-layout title="各类工地统计">
    <colorful-bar-chart
      :id="options.id"
      :unit="options.unit"
      :height="options.height"
      :xAxisData="options.xAxisData"
      :seriesData="options.seriesData"
    />
  </single-layout>
</template>

<script>
import ColorfulBarChart from '@/components/barChart/colorfulBarChart'
import SingleLayout from '@/components/layout/singleLayout'
import {fetchConstructionByType} from '@/api/construction'
import {getYear} from '@/utils/formatDate'

export default {
  name: 'ConstructionBar',
  components: {SingleLayout, ColorfulBarChart},
  data () {
    return {
      options: {
        id: 'construction_bar',
        height: '100%',
        width: '100%',
        unit: '个',
        xAxisData: ['房屋建设', '市政道路', '园林绿化', '桥梁隧道', '其他工程'],
        seriesData: [0, 0, 0, 0, 0, 0]
      }
    }
  },
  created () {
    this.getData()
  },
  methods: {
    getData () {
      console.log('fetchConstructionByType')
      let year = getYear()
      fetchConstructionByType(year).then(res => {
        console.log('fetchConstructionByType', res.data)
        this.options.xAxisData = []
        this.options.seriesData = []
        for (const item of res.data) {
          this.options.xAxisData.push(item.type)
          this.options.seriesData.push(item.value)
        }
      })
    }
  }
}
</script>

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

</style>