<!--
 @description: 评审大厅-符合性评审-评审汇总
 @author: yf
 @routerPath:
 @date: 2020-8-6 14:36:58
-->
<template>
  <div>
    <button v-if="metaType === 'commercialTechnicalReview'" type="button" class="el-button mb10 el-button--text el-button--mini">
      <span class="text">分数统计方式：<span style="color:red">{{ scoreStatisticsWay }}</span></span>
    </button>
    <el-table
      :data="supplierList"
      style="width: 100%"
    >
      <el-table-column
        type="index"
        align="center"
        width="80px"
        label="序号"
      />
      <el-table-column
        align="center"
        prop="supplierName"
        min-width="120px"
        label="供应商"
      />
      <!-- 符合性评审 -->
      <el-table-column
        v-if="metaType === 'complianceReview'"
        align="center"
        prop="conclusion"
        width="90px"
        label="结论"
      >
        <template slot-scope="scope">
          <p>
            <span v-if="scope.row.conclusion==='01'">合格</span>
            <span v-if="scope.row.conclusion==='00'" style="color:red">不合格</span>
          </p>
        </template>
      </el-table-column>
      <!-- 商务经济评审 -->
      <el-table-column
        v-if="metaType === 'commercialTechnicalReview'"
        align="center"
        prop="sortNo"
        min-width="120px"
        label="排名"
      />
      <!-- 商务经济评审 -->
      <el-table-column
        v-if="metaType === 'commercialTechnicalReview'"
        align="center"
        prop="evaluationFinalScore"
        min-width="120px"
        label="最终得分"
      />
      <el-table-column
        v-for="(item,index) in exportList"
        :key="index"
        :label="item.expertName"
        :prop="item.prop"
        align="center"
        min-width="90px"
      >
        <template slot-scope="scope">
          <p v-if="metaType === 'complianceReview'">
            <span v-if="scope.row[item.prop]==='01'">合格</span>
            <span v-if="scope.row[item.prop]==='00'" style="color:red">不合格</span>
          </p>
          <p v-else>
            {{ scope.row[item.prop] }}
          </p>
        </template>
      </el-table-column>
      <el-table-column
        v-if="metaType === 'complianceReview'"
        align="left"
        prop="name"
        label="统计"
        min-width="200px"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.allAccessment }}</span>
          <!-- <span v-if="scope.row.qualified>0">{{ scope.row.qualified }}专家评审合格</span>
          <span v-if="scope.row.unqualified>0">，{{ scope.row.unqualified }}专家评审不合格</span> -->
        </template>
      </el-table-column>
      <el-table-column
        v-if="metaType === 'complianceReview'"
        align="center"
        prop="name"
        label="操作"
        width="100px"
      >
        <template slot-scope="scope">
          <el-link
            class="tablebutton"
            type="primary"
            @click="dialogReviewClick(scope.row,scope.$index)"
          >
            [评审意见]
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <!-- 评审意见弹框 -->
    <evaluationOpinionsDialog :dialog-data="dialogData" :get-tender-base="getTenderBase" />
  </div>
</template>

<script>
import {
  expertEvalResultSummary
} from '@api/procurement/procurementEvaluation'
/* 评审意见弹框*/
import evaluationOpinionsDialog from './procurementEvaluationOpinions-dialog.vue'
export default {
  name: 'ComplianceReviewSummary',
  components: { evaluationOpinionsDialog },
  mixins: [],
  props: {
    // getTenderBase评标驱动下获取项目参数
    getTenderBase: {
      type: Object,
      default: function() {
        return {}
      }
    },
    driveInfo: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      supplierList: [], // 供应商列表
      dialogData: {
        dialogReview: false, // 评审意见-弹框
        supplierOpinionList: [], // 评审意见
        opinionSupplier: '', // 评审意见查看的供应商
        conclusion: '', // 符合性评审最终结论
        allAccessment: ''
      },
      exportList: [], // 专家列表
      metaType: this.$route.meta.type, // 路由meta type参数 complianceReview 符合性评审 commercialTechnicalReview 商务经济
      tableData: [], // 评审汇总列表
      scoreStatisticsWay: '' // 分数计算方式
    }
  },
  mounted() {
    if (!this.getTenderBase.isEdit) {
      this.initData()
    }
  },
  methods: {
    // 初始化
    initData() {
      const data = {
        packId: this.driveInfo.packId || this.getTenderBase.packId,
        taskNo: this.driveInfo.taskNo || this.getTenderBase.taskNo
      }
      expertEvalResultSummary(data).then(res => {
        // 设置分数统计方式
        this.scoreStatisticsWay = res.data.scoreStatisticsWay
        // 表格数据
        this.tableData = res.data.summaryVos
        if (this.tableData && this.tableData.length) {
          // 循环专家
          this.tableData.forEach((item, index) => {
            this.exportList.push({
              expertName: item[0].expertName,
              prop: 'prop' + index
            })
          })
          // 循环供应商
          this.tableData[0].forEach((supplier, index) => {
            const data = {
              ...supplier,
              qualified: 0,
              unqualified: 0
            }
            // 循环专家
            this.tableData.forEach((item, i) => {
              // 符合性评审
              if (this.metaType === 'complianceReview') {
                data['prop' + i] = item[index].accessment
                if (item[index].accessment === '01') {
                  data.qualified++
                } else if (item[index].accessment === '00') {
                  data.unqualified++
                }
              }
              // 商务经济评审
              if (this.metaType === 'commercialTechnicalReview') {
                data['prop' + i] = item[index].evaluationScore
              }
            })
            this.supplierList.push(data)
          })
        }
      })
    },
    // 评分意见-查看
    dialogReviewClick(row, index) {
      // 显示弹框
      this.dialogData.dialogReview = true
      // 评审意见查看的供应商
      this.dialogData.opinionSupplier = row.supplierName
      // 符合性评审的最终结论
      this.dialogData.conclusion = row.conclusion
      // 符合性评审统计信息
      this.dialogData.allAccessment = row.allAccessment
      const data = JSON.parse(JSON.stringify(this.tableData))
      // 初始化评审意见
      this.dialogData.supplierOpinionList = []
      data.forEach((item, i) => {
        this.dialogData.supplierOpinionList.push({
          supplierOpinion: item[index].supplierOpinion,
          expertName: item[index].expertName
        })
      })
    },
    // 评分排名-排序
    f1(number) {
      return function(a, b) {
        return b[number] - a[number]
      }
    },
    // 评分排名
    scoreSort() {
      const SupplierData = JSON.parse(JSON.stringify(this.supplierList))
      // 第一步排序
      SupplierData.sort(this.f1('evaluationFinalScore'))
      // 第二步 进行并排并赋值
      let index = 1
      for (let i = 0; i < SupplierData.length; i++) {
        if (i > 0) {
          if (SupplierData[i].evaluationFinalScore === SupplierData[i - 1].evaluationFinalScore) {
            SupplierData[i].sortNo = index
          } else {
            index++
            SupplierData[i].sortNo = index
          }
        } else {
          SupplierData[i].sortNo = index
        }
        this.supplierList = SupplierData
      }
    }
  }
}
</script>

<style lang="less" scoped>
  @import '~@assets/style/common/public.less';
.text{
  color: @dark-font;
}
</style>

