<!--
  @description: 报表统计-分类采购项目数量-更多
  @Modifier：杨胜国
  @routerPath:
  @date：  2021/03/15
-->
<template>
  <el-dialog
    v-dialogDrag
    :modal="false"
    :visible.sync="dialog"
    :close-on-click-modal="false"
    title="更多信息"
    width="1090px"
  >
    <div class="con-dialig">
      <tableColorChart
        ref="tableColorDialog"
        :height="height"
        class="echart-dom"
        :option="option"
      />
    </div>
    <pagination :pagination-data="paginationData" @change="loadData" />
    <!-- 点击查看个别明细弹框 -->
    <procurementProjectDetailDialog ref="detailDialog" />
  </el-dialog>
</template>

<script>
/* api */
import { getPurchaseTotalCountAndMoney } from '@api/statisticalAnalysis/reportChart.js'
/* 組件 */
import tableColorChart from './../../components/tableColorChart'// table列表渲染组件
import pagination from '@comp/common/pagination/pagination'// 分页
import procurementProjectDetailDialog from './procurementProjectDetail-dialog'// 更多明细

/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 公共方法*/
import { filterObj } from '@/assets/js/utils'// 过滤空的key
export default {
  name: 'ProcurementProjectClassNumDialog',
  components: {
    tableColorChart, // table列表渲染组件
    pagination, // 分页
    procurementProjectDetailDialog // 项目明细
  },
  mixins: [ListMixin],
  props: {
    // height: {
    //   type: String,
    //   default: '100%'
    // }
  },
  data() {
    return {
      height: '350px', // 高度
      dialog: false, // 弹窗状态
      searchChartData: {
        pageNo: 1,
        pageSize: 10
      },
      // title: '分类采购项目数量',
      option: {
        // 标题
        countThead: [
          { lable: '项目数量（个）', prop: 'productName' },
          { lable: '公开招标', prop: 'count00', tenderMethod: '00',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '邀请招标', prop: 'count01', tenderMethod: '01',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '询比价', prop: 'count11', tenderMethod: '11',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '单一来源', prop: 'count12', tenderMethod: '12',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '竞争性谈判', prop: 'count13', tenderMethod: '13',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '竞价', prop: 'count14', tenderMethod: '14',
            handle: {
              click: this.projectDetail
            }
          }
        ],
        // 金额标题
        moneyThead: [
          { lable: '金额（万元）', prop: 'productName' },
          { lable: '公开招标', prop: 'money00', tenderMethod: '00',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '邀请招标', prop: 'money01', tenderMethod: '01',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '询比价', prop: 'money11', tenderMethod: '11',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '单一来源', prop: 'money12', tenderMethod: '12',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '竞争性谈判', prop: 'money13', tenderMethod: '13',
            handle: {
              click: this.projectDetail
            }
          },
          { lable: '竞价', prop: 'money14', tenderMethod: '14',
            handle: {
              click: this.projectDetail
            }
          }
        ],
        thead: [],
        // 渲染数据
        data: [],
        type: 'count'
      }
    }
  },
  methods: {
    /**
     * 打开弹窗
     *  @param {row} Object 供应商信息
     *  @param {searchChartData} Object 全局的查询条件
    */
    open(searchChartData, type) {
      // 弹框打开
      this.dialog = true
      this.searchChartData = searchChartData
      this.paginationData.pageNo = 1
      // 调用init
      this.loadData()
      // type赋值
      // this.option.type = type
      this.$set(this.option, 'type', type)
      this.initType()
      // 调用组件方法传值
      // this.$refs.tableColorDialog.initType(type)
    },
    // 获取数据
    loadData() {
      this.option.data = []
      const data = this.getParams()
      getPurchaseTotalCountAndMoney(data).then(res => {
        this.paginationData.total = res.data.total
        this.option.data = res.data
      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign(this.searchChartData)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)// 过滤空的key
    },
    // 切换表头
    initType() {
      // 如果是项目数量 切换表头
      if (this.option.type === 'count') {
        this.title = '分类采购项目数量'
        // 为数组赋值
        this.option.countThead.forEach((item, key) => {
          this.$set(this.option.thead, key, item)
        })
      } else if (this.option.type === 'money') {
        this.title = '分类采购项目金额'
        this.option.moneyThead.forEach((item, key) => {
          this.$set(this.option.thead, key, item)
        })
      }
    },
    // 点击查看明细
    projectDetail(row) {
      this.$refs.detailDialog.open(this.searchData, row, this.option.type)
    }
  }
}
</script>
<style lang="less" scoped>
.con-dialig{
  color: #fff;
}
</style>
