<!--
  @description: 报表统计-完成项目数量
  @Modifier：肖文龙
  @routerPath:
  @date：  2021/02/25
-->
<template>
  <dl
    class="reportChart_crud"
    :style="{'height':height}"
  >
    <dt>
      本年完成项目数量
      <p class="right">
        <span>
          <i class="iconfont icon-xiazai1" @click="dowloadClick" />
        </span>
      </p>
    </dt>
    <dd>
      <pieChart
        ref="pieChart"
      />
    </dd>
  </dl>
</template>

<script>
/* api */
import { getCompleteProjectNumListByItemType, exportCompleteProjectNumListByItemType } from '@api/statisticalAnalysis/reportChart.js'
/* 公用方法*/
import { filterDictText, download } from '@/assets/js/utils'// 常用方法
/* 混入 */
import { itemsGroupMixin } from './../../mixins/reportChartGroup.js'

/* 組件 */
import pieChart from './../../components/pieChart.vue'// 饼图-图表
export default {
  name: 'CompleteProjectNumberChart',
  components: {
    pieChart// 饼图-图表
  },
  inject: ['chartData'],
  props: {
    height: {
      type: String,
      default: '100%'
    }
  },
  data() {
    return {
      /* 字典信息-start */
      ...itemsGroupMixin,
      /* 字典信息-end */
      // 查询条件
      searchData: {

      }
    }
  },
  methods: {
    /**
     * 获取数据
     *  @param {searchData} Object 查询条件
    */
    initChart(searchData) {
      this.searchData = searchData
      const data = {
        ...searchData
      }
      getCompleteProjectNumListByItemType(data).then(res => {
      // 图表数据
        const option = {
          unit: '个', // 计量单位
          title: {
            text: '完成项\n目数量'
          },
          color: ['#f5c04c', '#9eca7f', '#de6e6a', '#617acb'],
          series: {
            data: res.data.map(item => {
              return {
                value: item.tenderNumber, // 项目数量
                name: filterDictText(this.itemsTypeList, item.itemType)// 品目方式
              }
            })
          }
        }
        this.$refs.pieChart.init(option)
      })
    },
    // 下载导出
    dowloadClick() {
      exportCompleteProjectNumListByItemType(this.searchData).then(res => {
        download(res, '完成项目数量.xls')
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
