
<!--
  @description: 评标大厅-有效最低价价格评审公共表格组件
  @Modifier：wxy/yf
  @routerPath:/procurement/procurementDrive/procurementDocumentsPurchase/evaluationResults/priceReview
  @date：  2020-08-5 14:24:28
-->
<template>
  <div style="margin-top: 10px">
    <el-table v-loading="loading" :data="pricelist.supplierEvalResultVos" :span-method="objectSpanMethod" style="width: 100%;" class="mb10">
      <!-- 序号 -->
      <el-table-column header-align="center" type="index" label="序号" width="50px" align="center" />
      <!-- 供应商名称 -->
      <el-table-column header-align="center" prop="supplierName" min-width="220px" label="供应商名称" align="left" />
      <!-- 含税总价（元） -->
      <el-table-column header-align="center" prop="offerTotal" label="含税总价（元）" align="right" width="150px">
        <template slot-scope="scope">
          <span v-if="scope.row.offerTotal">{{ moneyFormat(scope.row.offerTotal.toFixed(2)) }}</span>
        </template>
      </el-table-column>
      <!-- 基准价 metaPath区分综合/最有效最低价/性价比  priceReview综合评估法的价格评审 才显示基准价 其他发方式不显示 -->
      <el-table-column v-if="metaPath === 'priceReview'" header-align="center" prop="basePrice" label="基准价" align="right">
        <template slot-scope="scope">
          <!-- 商务组长可编辑   暂时改成不可以编辑 只能看-->
          <!-- <el-input v-if="getTenderBase.isEdit && getTenderBase.isEvalLeader==='01' && getTenderBase.isCommerceLeader === '01'" v-model="scope.row.basePrice" :min="0" type="number" title="" placeholder="请输入基准价" @change="reckonPriceReview" /> -->
          <span v-if="scope.row.basePrice">{{ moneyFormat(scope.row.basePrice.toFixed(2)) }}</span>
        </template>
      </el-table-column>
      <!-- 评标价（元） -->
      <el-table-column header-align="center" prop="idCard" min-width="120px" label="评标价（元）" align="center">
        <template slot-scope="scope">
          <!-- 评标价编辑暂时修改为只读 -->
          <!-- 可编辑 isEdit 布尔值根据驱动节点状态判断 （00未开启 02已完成）return false 01正在进行  true isEvalLeader当前评委是否是组长 00 否 01是 isCommerceLeader是否商务组长 00否 01是-->
          <!-- <money
            v-if="getTenderBase.isEdit && getTenderBase.isEvalLeader==='01' && getTenderBase.isCommerceLeader === '01'"
            size="mini"
            :unit-fixed="6"
            width="auto"
            :money-value="scope.row"
            name="evaluationPrice"
            @change="reckonPriceReview()"
          /> -->
          <!-- 不是组长 或者已完成只能查看 -->
          <!-- <span v-else>{{ moneyFormat(scope.row.evaluationPrice) }}</span> -->
          <span v-if="scope.row.evaluationPrice!==null">{{ moneyFormat(scope.row.evaluationPrice) }}</span>
        </template>
      </el-table-column>
      <!-- 报价得分 metaPath区分综合/最有效最低价/性价比  priceReview综合评估法的价格评审 才显示基准价 其他发方式不显示 -->
      <el-table-column v-if="metaPath === 'priceReview'" header-align="center" prop="evaluationScore" label="报价得分" align="right">
        <template slot-scope="scope">
          <!-- 编辑 isEdit 布尔值根据驱动节点状态判断 （00未开启 02已完成）return false 01正在进行  true isEvalLeader当前评委是否是组长 00 否 01是 isCommerceLeader是否商务组长 00否 01是-->
          <el-input-number v-if="getTenderBase.isEdit && getTenderBase.isEvalLeader==='01' && getTenderBase.isCommerceLeader === '01'" v-model="scope.row.evaluationScore" :min="0" :precision="2" :controls="false" type="number" placeholder="请输入报价得分" style="width:120px" @blur="scoreClick(scope.row,'evaluationScore')" />
          <span v-else>{{ moneyFormat(scope.row.evaluationScore) }}</span>
        </template>
      </el-table-column>
      <!-- 报价排名 metaPath区分综合/最有效最低价/性价比  priceReview综合评估法的价格评审 才显示基准价 其他发方式不显示 -->
      <el-table-column v-if="!getTenderBase.isEdit&&metaPath === 'priceReview'" header-align="center" prop="sortNo" label="报价排名" align="center" />
      <!-- 报价单 -->
      <el-table-column
        header-align="center"
        label="报价单"
        align="center"
        width="150px"
      >
        <template slot-scope="scope">
          <el-link
            :underline="false"
            size="mini"
            type="primary"
            @click="offerSingleClick(scope.row)"
          >
            {{ scope.row.negRecordCode }}
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <!-- 评审点名称 metaPath区分综合/最有效最低价/性价比  priceReview综合评估法的价格评审 才显示基准价 其他发方式不显示 -->
    <table v-if="metaPath === 'priceReview'" class="evaluationBottom">
      <tr>
        <td class="singleRow">
          评审点名称:
        </td>
        <td>价格评审</td>
      </tr>
      <tr>
        <td class="singleRow">
          分值范围:
        </td>
        <td>
          {{ pricelist.minScore }}-{{ pricelist.maxScore }}分
        </td>
      </tr>
      <tr>
        <td class="singleRow">
          评审标准:
        </td>
        <td>
          <p v-if="pricelist.evaluationStandard!==null && pricelist.evaluationStandard!==''" v-html="preText(pricelist.evaluationStandard)" />
        </td>
      </tr>
    </table>
    <!-- 编辑状态下行项目报价弹框 -->
    <!-- <priceReviewLineItemInfo :dialog-data="priceReviewDialog" /> -->
    <!--  查看供应商报价信息弹框-->
    <procurementSuplierOffer :dialog-data="supplierOfferDialog" />
  </div>
</template>

<script>
/* api*/
import {
  showPriceReview,
  reckonProtProjectProcurementPriceReview,
  queryPriceReview
} from '@api/procurement/procurementEvaluation'
/* 公共方法*/
import { moneyFormat } from '@/assets/js/utils' // 常用方法
/* 公共组件*/
import money from '@comp/common/money/money' // 金币组件
// import priceReviewLineItemInfo from './procurementPriceReviewLineItemInfo-dialog' // 行项目报价组件
import procurementSuplierOffer from '@/views/procurement/components/procurementLookSupplierOffer-dialog'// 查看供应商报价弹框

export default {
  components: {
    // priceReviewLineItemInfo // 行项目报价组件
    procurementSuplierOffer, // 查看供应商报价弹框
    money // 金额组件
  },
  mixins: [],
  props: {
    tableData: {
      type: Object,
      default: function() {
        return {}
      }
    },
    // 是否可编辑
    getTenderBase: {
      type: Object,
      default: function() {
        return {}
      }
    },
    driveInfo: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: true, // loading效果
      priceReviewDialog: {
        dialog: false, //  false 关闭   true 打开
        id: [] // 供应商报价id
      }, // 行项目报价弹框
      metaPath: this.$route.meta.path, // 路由meta信息
      metaType: this.$route.meta.type, // 路由meta信息
      pricelist: {}, // 价格评审表格数据
      // 供应商报价单查看弹框
      supplierOfferDialog: {
        dialog: false,
        stageId: '', // 轮次id
        packId: '', // 标段id
        supplierId: '' // 供应商id
      }
    }
  },
  watch: {
    tableData(val) {
      if (val) {
        // 关闭loading
        this.pricelist = this.tableData
      }
      this.loading = false
    }
  },
  created() {
    this.initData()
  },
  methods: {
    moneyFormat, // 千分位
    // 初始化加载页面
    initData() {
      if (!this.getTenderBase.isEdit || this.metaType === 'managerView') {
        const data = {
          packId: this.getTenderBase.packId || this.driveInfo.packId, // 标段id
          taskNo: this.getTenderBase.taskNo || this.driveInfo.taskNo // 驱动编号
        }
        // 查看页面
        showPriceReview(data).then(res => {
          const tableData = res.data
          this.loading = false
          if (this.metaPath === 'priceReview' && tableData.supplierEvalResultVos) {
            const basePriceArr = tableData.supplierEvalResultVos.filter(item => {
              return item.basePrice
            })
            tableData.supplierEvalResultVos.forEach(item => {
              item.basePrice = basePriceArr[0].basePrice
            })
          }
          this.pricelist = tableData
        })
        return
      }
      const data = {
        evalExpertId: this.getTenderBase.evalExpertId, // 专家评审表ID
        driverId: this.getTenderBase.driverId, // 驱动id
        packId: this.getTenderBase.packId, // 标段id
        evalRule: this.getTenderBase.evalRule // 评审规则 【00–整体步骤 01-单个评委步骤】
      }
      // 编辑页面
      queryPriceReview(data).then(res => {
        this.loading = false
        const tableData = res.data
        tableData.supplierEvalResultVos.forEach(item => {
          if (!item.evaluationScore) {
            item.evaluationScore = undefined
          }
        })
        this.pricelist = tableData
      })
    },
    // 单元格合并 非综合评估法的价格评审需要合并但愿个
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (this.metaPath !== 'priceReview') return
      if (columnIndex === 3) {
        if (rowIndex % this.pricelist.supplierEvalResultVos.length === 0) {
          return {
            rowspan: this.pricelist.supplierEvalResultVos.length,
            colspan: 1
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0
          }
        }
      }
    },
    // 提交-校验
    scoreChecks() {
      let is_score = true// 是否通过校验
      // 分数的校验
      this.pricelist.supplierEvalResultVos.forEach((item, index) => {
        item.basePrice = this.pricelist.supplierEvalResultVos[0].basePrice
        // 判断是否填写评标价
        if (!item.evaluationPrice) {
          is_score = false
          this.$message.warning(`请填写${item.supplierName}下的评标价`)
        }
        if (this.metaPath !== 'priceReview') return
        // 判断是否填写基准价
        if (!item.basePrice) {
          this.$message.warning(`请完整${item.supplierName}的基准价`)
          is_score = false
          return
        }
        if (!item.evaluationScore) {
          this.$message.warning(`请填写${item.supplierName}下的评审得分`)
          is_score = false
        }
        if (is_score) {
          if (item.evaluationScore < Number(item.factorMinScore) || item.evaluationScore > Number(item.factorMaxScore)) {
            this.$message({
              message: `评分分数在${item.factorMinScore}-${item.factorMaxScore}分之间，请重新评分`,
              type: 'warning'
            })
            item.evaluationScore = ''
            is_score = false
          }
        }
      })
      // 金额的校验
      if (is_score) {
        this.pricelist.supplierEvalResultVos.forEach((item, index) => {
          if (is_score) {
            if (item.evaluationPrice < 0 || !item.evaluationPrice) {
              this.$message({
                message: '输入的金额不能小于0元，请您重新输入',
                type: 'warning'
              })
              is_score = false
            }
          }
        })
      }
      return is_score
    },
    // 评分校验
    scoreClick(row, name, index) {
      row[name] = Math.round(row[name] * 100) / 100
      if (name === 'evaluationScore') {
        if (row[name] * 1 < this.pricelist.minScore * 1 || row[name] * 1 > this.pricelist.maxScore * 1) {
          this.$message({
            message: `评分分数在${this.pricelist.minScore}-${this.pricelist.maxScore}分之间，请重新评分`,
            type: 'warning'
          })
          row[name] = undefined
        }
      } else {
        if (row[name] < 0) {
          this.$message({
            message: '输入的金额不能小于0元，请您重新输入',
            type: 'warning'
          })
          row[name] = 0
          return
        }
      }
    },
    // 打开行项目报价弹框
    // openDialog(row) {
    //   this.priceReviewDialog.dialog = true
    //   this.priceReviewDialog.id = row.offerId
    // },
    // 报价单弹框打开
    offerSingleClick(row) {
      this.supplierOfferDialog.stageId = row.stageId // 轮次id
      this.supplierOfferDialog.packId = this.driveInfo.packId || this.getTenderBase.packId // 项目标段id
      this.supplierOfferDialog.supplierId = row.supplierId // 项目标段id
      this.supplierOfferDialog.dialog = true
    },
    // 计算价格评审基准价、评审得分
    reckonPriceReview() {
      if (this.metaPath !== 'priceReview') return
      const data = this.assemblyData()
      reckonProtProjectProcurementPriceReview(data).then(res => {
        this.pricelist = res.data
      })
    },
    // 封装数据
    assemblyData() {
      // 拼装数据
      const data = {
        id: this.pricelist.id, // 指标ID
        evaluationStandard: this.pricelist.evaluationStandard, // 评审标准
        evaluationName: this.pricelist.evaluationName, // 评审名称
        expertPriceEvalList: this.pricelist.supplierEvalResultVos, // 供应商价格评审列表
        driverId: this.getTenderBase.driverId, // 驱动id
        evalExpertId: this.getTenderBase.evalExpertId, // 专家评审表ID【必传】
        evalRule: this.getTenderBase.evalRule, // 评审规则 【00–整体步骤 01-单个评委步骤】
        packId: this.getTenderBase.packId, // 标段id
        stageId: this.pricelist.supplierEvalResultVos[0] ? this.pricelist.supplierEvalResultVos[0].stageId : '' // 阶段ID
      }
      // 供应商价格评审列表评标价处理2位小数
      data.expertPriceEvalList.forEach((item) => {
        // 错误处理
        if (item.evaluationPrice === '' || item.evaluationPrice === null || item.evaluationPrice === undefined) {
          item.evaluationPrice = 0
        } else {
          item.evaluationPrice = Number(item.evaluationPrice).toFixed(2)
        }
      })
      return data
    },
    // 将文本域的文本进行处理让文本保存换行空格形式，传递给后端
    preText(pretext) {
      if (pretext) {
        if (pretext.match(/\r\n/g) === null) { // 如果包含特殊字符返回false
          return
        } else {
          return pretext.replace(/\r\n/g, '<br />')
        }
      }
    }
  }
}
</script>

<style lang='less' scoped>
/*评审指标信息*/
.evaluationBottom  {
  width: 100%;
  margin: 20px 0;
}
.evaluationBottom  td {
  border: 1px solid #E0E0E0;
  line-height: 20px;
  padding: 9px 10px;
}
.evaluationBottom  tr td:nth-child(odd) {
  background-color: #F5F7F9;
  width: 5%;
}
.evaluationBottom  tr td:nth-child(even) {
  width: 34%;
}
.evaluationBottom  tr.singleRow td:nth-child(odd) {
  background-color: #F5F7F9;
  width: 6.5%;
}
.evaluationBottom  tr.singleRow td:nth-child(even) {
  width: calc(100%-6.5%);
}
</style>
