<!--
  @description:评审-查看表格组件
  @Modifier:yf
  @routerPath:
  @date:2020/08/5
-->
<template>
  <div>
    <el-table
      v-loading="loading"
      :data="reviewList"
      :span-method="objectSpanMethod"
      style="width: 100%"
      @cell-click="cellClick"
    >
      <el-table-column header-align="center" align="center" type="index" width="60px" label="序号">
        <template slot-scope="scope">
          <p>{{ scope.row.serialNumber }}</p>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="left" min-width="300" label="评审点名称">
        <template slot-scope="scope">
          <p v-if="scope.row.isFixedData">
            {{ scope.row.name }}
          </p>
          <p v-else>
            {{ scope.row.factorName }}
          </p>
        </template>
      </el-table-column>
      <!-- 供应商 -->
      <el-table-column
        v-for="(item,index) in supplierList"
        :key="index"
        min-width="300px"
        align="center"
      >
        <template slot="header">
          <p>
            <el-checkbox v-model="item.checkbox" @change="checkSupplier(item)" />
            <span>{{ item.supplierName }}</span>
          </p>
        </template>
        <!-- 符合性评审 -->
        <template v-if="metaType === 'complianceReview'">
          <!-- 评审结果 -->
          <el-table-column header-align="center" column-key="radio" label="评审结果" min-width="100" align="center">
            <template slot-scope="scope">
              <template v-if="!scope.row.isFixedData">
                <p v-if="scope.row.offerData[item.prop].evaluationResult === '01'">
                  符合
                </p>
                <p v-if="scope.row.offerData[item.prop].evaluationResult === '00'" style="color:red">
                  不符合
                </p>
              </template>
              <!-- 固定底部内容 -->
              <template v-else>
                <span v-if="scope.row.offerData[item.prop].accessment === '00'">符合</span>
                <span v-if="scope.row.offerData[item.prop].accessment === '01'">不符合</span>
                <span>{{ scope.row.offerData[item.prop].accessment }}</span>
              </template>
            </template>
          </el-table-column>
          <!-- 评审意见 -->
          <el-table-column header-align="center" label="评审意见" min-width="220" align="left">
            <template v-if="!scope.row.isFixedData" slot-scope="scope">
              <p>{{ scope.row.offerData[item.prop].evaluationOpinion }}</p>
            </template>
          </el-table-column>
        </template>
        <!-- 商务经济评审 -->
        <template v-if="metaType === 'commercialTechnicalReview'" slot-scope="scope">
          <p>{{ scope.row.offerData[item.prop].evaluationScore }}</p>
        </template>
      </el-table-column>
    </el-table>
    <!-- 评分详细 -->
    <table v-if="expertInfo.evalExpertId !== ''" class="tableData">
      <tr class="singleRow">
        <td>评审点名称</td>
        <td>{{ columnKey.factorName }}</td>
      </tr>
      <!-- 商务经济评审 -->
      <tr v-if="metaType === 'commercialTechnicalReview'" class="singleRow">
        <td>分值范围</td>
        <td>{{ columnKey.factorScore }}</td>
      </tr>
      <tr class="singleRow">
        <td>评审标准</td>
        <td>{{ columnKey.evalContent }}</td>
      </tr>
    </table>
    <!--附件-->
    <!--附件表格-->
    <!-- 修改日期2020年10月10日 商务组长和技术组长，在评审时上传的附件，需要在采购员【评审管理】驱动下，对应的组长下面显示出来。 -->
    <table v-if="(expertInfo.isLeader === '01'&& driveInfo.taskNo==='06')||(expertInfo.isLeader === '01'&&(getTenderBase.taskNo==='05'|| driveInfo.taskNo==='05'))||(expertInfo.isLeader === '01'&&(getTenderBase.taskNo==='04'|| driveInfo.taskNo==='04')) || getTenderBase.taskNo==='04'&&getTenderBase.isCommerceLeader==='01' || getTenderBase.taskNo==='05'&&getTenderBase.isTechnologyLeader==='01' || (getTenderBase.taskNo==='06'&&getTenderBase.isTechnologyLeader==='01'&&getTenderBase.isCommerceLeader==='01')" class="tableData">
      <tr class="singleRow">
        <td>附件</td>
        <td>
          <downloadFile :data="procurementFile" />
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
/* api接口*/
import {
  showComplianceReview
} from '@api/procurement/procurementEvaluation'
import downloadFile from '@comp/common/updownload/downloadFile' // 文件回显组件
export default {
  name: 'ProcurementResultTableCompDetail',
  components: {
    downloadFile
  },
  mixins: [],
  props: {
    // 表格渲染数据
    tableData: {
      type: Object,
      default: function() {
        return {}
      }
    },
    // 项目经理查看单个评委评审信息
    expertInfo: {
      type: Object,
      default: function() {
        return {}
      }
    },
    // getTenderBase参数
    getTenderBase: {
      type: Object,
      default: function() {
        return {}
      }
    },
    // 项目经理查看单个评委评审信息
    driveInfo: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: false, // loading效果
      supplierList: [], // 供应商列表
      reviewList: [], // 评审列表
      supplierCheckList: [], // 选择供应商
      access: '', // 最终结果
      // 符合性评审固定底部文案
      complianceListData: [
        {
          name: '结论',
          prop: 'accessment',
          isFixedData: true
        }
      ],
      // 商务经济评审固定底部文案
      commeTechListData: [ // 底部固定文案数据列表
        {
          name: '最终得分',
          prop: 'evaluationScore',
          isFixedData: true // 是否为固定数据
        }
      ],
      columnKey: {
        evaluationName: '', // 评审点名称
        evaluationStandard: '', // 评审标准
        highestScore: null, // 评审最高分
        lowestScore: null, // 评审最低分
        factorScore: null // 评审范围
      }, // 指标类型
      metaType: this.$route.meta.type, // 路由meta type信息。complianceReview符合性评审commercialTechnicalReview商务经济评审
      bidSupplierNum: '', // 投标供应商数量
      evalExpertNum: '', // 评委数据
      evalFinishExpertNum: '', // 已完成评委数量
      evalFinishSupplierNum: '', // 已完成供应商数量
      evaluationData: {}, // 项目经理的表格数据
      procurementFile: {
        bizId: '', // 业务主键Id
        fileType: ''// 文件类型
      } // 附件信息
    }
  },
  watch: {
    expertInfo: {
      handler(newName, oldName) {
        if (newName) {
          // this.loading = false
          this.getData()
        }
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    this.fileParameters()
  },
  mounted() {
    // 判断专家登录获取信息
    if (this.tableData.tableList) {
      this.initData()
    }
  },
  methods: {
    // 初始化表格数据
    initData() {
      // 关闭loading
      // this.loading = true
      let data = {}
      if (this.tableData.tableList) {
        data = this.tableData
      }
      if (this.evaluationData.tableList) {
        data = this.evaluationData
      }
      const { tableData, tableList } = JSON.parse(JSON.stringify(data))
      const reviewList = []// 指标信息
      // 遍历指标
      tableList.forEach((reviewData) => {
        const supplierReviewList = reviewData.evalFactorResultVos || []
        let data = {}
        // 遍历供应商投标信息
        supplierReviewList.forEach(supplierReview => {
          // 遍历供应商-表头
          tableData.forEach(supplier => {
            // 遍历供应商报价信息和供应商进行匹配
            if (supplier.supplierId === supplierReview.supplierId) {
              // 设置表头prop
              supplier.prop = supplierReview.supplierId
              // 表格展示数据
              data = {
                // 投标信息
                ...reviewData,
                offerData: {
                  ...data.offerData,
                  // 供应商投标信- 设置表格展示数据
                  [supplierReview.supplierId]: {
                    accessment: supplier.accessment, // 最终结论
                    supplierId: supplier.supplierId, // 供应商id
                    supplierName: supplier.supplierName, // 供应商名称
                    evaluationScore: supplierReview.evaluationScore, // 得分
                    evaluationOpinion: supplierReview.evaluationOpinion, // 供应商评审意见
                    evaluationResult: supplierReview.evaluationResult // 供应商评审结果
                  }
                }
              }
              // 删除不需要的参数
              delete data.evalFactorResultVos
            }
          })
        })
        reviewList.push(data)
      })
      this.init(tableData, reviewList)
      // 渲染数据
      this.supplierList = tableData// 供应商列表
      this.reviewList = reviewList// 评标信息
    },
    // 初始化底部固定数据
    init(tableData, tableList) {
      // 设置符合性评审表格固定底部数据
      if (this.metaType === 'complianceReview') {
        this.complianceListData.forEach(item => {
          let offerData = {}
          tableData.forEach(supplier => {
            offerData = {
              ...offerData,
              ...item,
              [supplier.supplierId]: {
                accessment: supplier.accessment, // 结论
                evalOpinion: supplier.evalOpinion // 评审意见
              }
            }
          })
          item.offerData = offerData
        })
        tableList.push(...this.complianceListData)
      }
      // 设置商务经济评审表格底部固定数据
      if (this.metaType === 'commercialTechnicalReview') {
        this.commeTechListData.forEach(item => {
          let offerData = {}
          tableData.forEach(supplier => {
            offerData = {
              ...offerData,
              ...item,
              [supplier.supplierId]: {
                evaluationScore: supplier.score // 最终得分
              }
            }
          })
          item.offerData = offerData
        })
        tableList.push(...this.commeTechListData)
      }
    },
    // 点击单元格事件
    cellClick(row) {
      this.columnKey = {
        factorName: row.factorName, // 名称
        evalContent: row.evalContent, // 标准
        factorMinScore: row.factorMinScore, // 最低分
        factorMaxScore: row.factorMaxScore, // 最高分
        factorScore: row.factorScore // 评审范围
      }
    },
    // 单元格合并
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // const len = this.supplierList.length * 2 + 2
      const listLen = this.reviewList.length
      if (columnIndex === 0) {
        if (rowIndex === listLen) {
          return {
            rowspan: 2, // 需要合并的行数
            colspan: 1 // 需要合并的列数，设置为0，不显示该列
          }
        }
      }
    },
    // 采购员发请求获取数据
    getData() {
      // this.loading = true
      const data = {
        evalExpertId: this.expertInfo.evalExpertId, // 专家评审表ID
        driverId: this.expertInfo.driverId, // 驱动id
        packId: this.expertInfo.packId, // 标段id
        evalRule: this.expertInfo.evalRule // 评审规则 【00–整体步骤 01-单个评委步骤】
      }
      // 判断是否有空值
      if (data.evalExpertId && data.driverId && data.packId && data.evalRule) {
        // 获取查看页面数据
        showComplianceReview(data).then(res => {
          this.loading = false
          const factorList = res.data.factorList
          const supplierList = res.data.supplierList
          this.evaluationData = {
            tableList: factorList, // 评审数据渲染
            tableData: supplierList// 供应商渲染
          }
          // 渲染页面
          this.initData()
        })
      }
    },
    // 向父组件传递勾选的数据
    checkSupplier(item) {
      // 每条数据的容器
      const SupplierList = []
      SupplierList.push(item)
      this.$emit('checkSupplierList', SupplierList)
    },
    // 文件参数
    fileParameters() {
      // 判断是商务评审还是技术评审
      if (this.getTenderBase.taskNo === '04' || this.getTenderBase.taskNo === '06' || this.driveInfo.taskNo === '04' || this.driveInfo.taskNo === '06') {
        this.procurementFile.fileType = 'prot_project_procurement_eval_expert_commerce_file'
        this.procurementFile.bizId = this.getTenderBase.driverId || this.expertInfo.driverId
      }
      if (this.getTenderBase.taskNo === '05' || this.driveInfo.taskNo === '05') {
        this.procurementFile.fileType = 'prot_project_procurement_eval_expert_technology_file'
        this.procurementFile.bizId = this.getTenderBase.driverId || this.expertInfo.driverId
      }
    }
  }
}
</script>

<style lang="less" scoped>
.tableData{
  margin-top: 20px;
}
.evaluation .content .content-right .content-right_scrollbar {
    height: calc(100vh - 40px - 70px);
}
.tr td .cell p{
  overflow: hidden;
  text-overflow: ellipsis;
  /*display: -webkit-box;*/
  display: block;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  line-height: 16px;
}
</style>
