
<!--
  @description: 评标大厅-有效最低价的推荐中标候选人
  @Modifier：yf
  @routerPath: /procurement/evaluationLobbyDrive/lowestPriceWinningCandidate
  @date：  2020-08-5 14:24:28
-->
<template>
  <div class="main">
    <el-table v-loading="loading" :data="pricelist.supplierEvalResultVos" border>
      <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" width="120px" label="含税总价（元）" align="right">
        <template slot-scope="scope">
          <span v-if="scope.row.offerTotal">{{ moneyFormat(scope.row.offerTotal.toFixed(2)) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="idCard" width="120px" label="评标价（元）" align="right">
        <template slot-scope="scope">
          <!-- 组长可编辑 -->
          <!-- <el-input v-if="getTenderBase.isEdit && getTenderBase.isEvalLeader==='01'&&metaType!=='managerView'" v-model="scope.row.evaluationPrice" :min="0" type="number" placeholder="请输入评标价" /> -->
          <span v-if="scope.row.evaluationPrice">{{ moneyFormat(scope.row.evaluationPrice.toFixed(2)) }}</span>
        </template>
      </el-table-column>
      <!-- 不可编辑 -->
      <el-table-column header-align="center" width="100px" prop="sortNo" label="报价排名" align="center" />
      <el-table-column header-align="center" width="100px" label="是否推荐" align="center">
        <template slot-scope="scope">
          <!-- 编辑页且为组长 isRecommendCandidate是否显示推荐中标后选人 00 不显示 01 显示 -->
          <!-- <el-checkbox v-if="!getTenderBase.isEdit" :checked="scope.row.recommend === '01'?true:false" disabled /> v-if="getTenderBase.isEvalLeader==='01'" -->
          <div v-if="isCostPerformanceEdit()">
            <el-checkbox v-model="scope.row.recommend" :checked="scope.row.recommend === '01'?true:false" true-label="01" false-label="00" />
            <span style="font-size: 13px;margin-left: 6px;">推荐</span>
          </div>
          <!-- 查看页面 -->
          <div v-if="!getTenderBase.isEdit">
            <span v-if="scope.row.recommend === '01'" style="font-size: 13px;margin-left: 6px;">推荐</span>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 推荐理由展示 -->
    <table class="evaluationBottomTb">
      <tr class="singleRow" style="min-width:200px">
        <td v-if="!getTenderBase.isEdit">
          <span>推荐理由</span>
        </td>
        <td v-if="!getTenderBase.isEdit">
          <span v-if="pricelist.supplierEvalResultVos">{{ pricelist.supplierEvalResultVos[0].evaluationOpinion }}</span>
        </td>
      </tr>
    </table>
    <!-- 推荐理由 -->
    <el-form ref="reasonForm" :model="reasonForm" :rules="rules" :inline-message="true">
      <table class="evaluationBottomTab">
        <tr v-if="isCostPerformanceEdit()" class="singleRow" style="min-width:200px">
          <td><el-form-item label="推荐理由" prop="avoidReason" /></td>
          <td>
            <gx-input
              v-if="isCostPerformanceEdit()"
              v-model.trim="reasonForm.avoidReason"
              :autosize="{ minRows: 3, maxRows: 3 }"
              gx-placeholder="placeholderText1000"
              gx-maxlength="varchar1000"
              type="textarea"
              style="width: calc(100%-50px)"
            />
            <span v-if="!isCostPerformanceEdit()">{{ reasonForm.avoidReason }}</span>
          </td>
        </tr>
      </table>
    </el-form>
    <!-- 完成推荐 -->
    <div v-if="isCostPerformanceEdit()" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button :loading="confirmLoading" type="primary" size="medium" @click="submit('reasonForm')">
            完成推荐
          </el-button>
        </div>
      </div>
    </div>
    <!-- 编辑状态下行项目报价弹框 -->
    <priceReviewLineItemInfo :dialog-data="priceReviewDialog" />
  </div>
</template>

<script>
/* api*/
import {
  saveMinRecommendCandidate,
  listMinRecommendCandidate,
  showMinRecommendCandidate
} from '@api/procurement/procurementEvaluation'
/* 组件*/
import { moneyFormat } from '@/assets/js/utils'
import { characters1_auto } from '@/assets/js/validate'
import priceReviewLineItemInfo from '../procurementPriceReview/procurementPriceReviewLineItemInfo-dialog' // 行项目报价组件
export default {
  components: {
    priceReviewLineItemInfo // 行项目报价组件
  },
  inject: ['getTenderBase', 'driveReload', 'getDriveTask'],
  mixins: [],
  props: {
    driveInfo: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: true, // loading效果
      confirmLoading: false, // btnLoading
      priceReviewDialog: {
        dialog: false, //  false 关闭   true 打开
        id: [] // 供应商报价id
      }, // 行项目报价弹框
      metaType: this.$route.meta.type, // 路由meta信息
      getTenderBase: this.getTenderBase(),
      pricelist: {}, // 价格评审表格数据
      reasonForm: { // 评审意见
        avoidReason: ''
      },
      //  校验
      rules: {
        avoidReason: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 评审意见
      }
    }
  },
  watch: {
    tableData(val) {
      if (val) {
        // 关闭loading
        this.pricelist = this.tableData
      }
      this.loading = false
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    moneyFormat, // 千分位
    /*
    * 初始化加载推荐的候选人数据
    * @params {packId：项目标段id，taskNo:驱动编号}
    */
    initData() {
      if (!this.getTenderBase.isEdit) {
        const data = {
          packId: this.getTenderBase.packId || this.driveInfo.packId, // 标段id
          taskNo: this.getTenderBase.taskNo || this.driveInfo.taskNo // 驱动编号
        }
        showMinRecommendCandidate(data).then(res => {
          this.pricelist = res.data
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
        return
      }
      const params = {
        driverId: this.getTenderBase.driverId,
        evalExpertId: this.getTenderBase.evalExpertId,
        evalRule: this.getTenderBase.evalRule || this.driveInfo.evalRule,
        packId: this.getTenderBase.packId || this.driveInfo.packId
      }
      listMinRecommendCandidate(params).then(res => {
        this.pricelist = res.data
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 评分校验
    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
    },
    // 完成推荐
    submit(formName) {
      this.loading = true // loading效果
      this.confirmLoading = true // btnLoading
      // 检验是否推选
      let isElect = false
      this.pricelist.supplierEvalResultVos.forEach(item => {
        if (item.recommend === '01') {
          isElect = true
        }
      })
      if (!isElect) {
        this.$message.warning('必须推荐中标候选人')
        this.loading = false // loading效果
        this.confirmLoading = false // btnLoading
        return false
      }
      this.$refs[formName].validate((valid) => {
        // 校验是否填写评审意见
        if (valid) {
          this.$confirm(`提交之后将不可修改，确认提交评审结果吗？`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            this.saveMinCandidate() // 保存有效最低价完成推荐后选人方法
          }).catch(() => {
            this.loading = false // loading效果
            this.confirmLoading = false // btnLoading
          })
        } else {
          this.loading = false // loading效果
          this.confirmLoading = false // btnLoading
          return false
        }
      })
    },
    /*
    * 保存有效最低价完成推荐后选人方法
    * @params{evaluationOpinion：推荐理由，expertPerformanceRateEvalList：供应商价格评审列表,driverId: 驱动id,evalExpertId:专家评审表ID【必传】,evalRule:评审规则 【00–整体步骤 01-单个评委步骤】,packId:项目标段id，stageId：阶段ID}
    * 保存推荐进入中选的供应商
    */
    saveMinCandidate() {
      // 拼装数据
      const data = {
        evaluationOpinion: this.reasonForm.avoidReason,
        expertPriceEvalList: this.pricelist.supplierEvalResultVos,
        driverId: this.getTenderBase.driverId,
        evalExpertId: this.getTenderBase.evalExpertId,
        evalRule: this.getTenderBase.evalRule,
        packId: this.getTenderBase.packId,
        stageId: this.pricelist.supplierEvalResultVos[0] ? this.pricelist.supplierEvalResultVos[0].stageId : '' // 阶段ID
      }
      saveMinRecommendCandidate(data).then(res => {
        this.getTenderBase.isEdit = false // 提交成功后不显示完成推荐按钮
        this.loading = false // loading效果
        this.confirmLoading = false // btnLoading
        // 刷新驱动
        this.driveReload()
        this.getDriveTask()
      }).catch(() => {
        this.initData() // 当提示数据有变动是刷新推荐列表
        this.loading = false // loading效果
        this.confirmLoading = false // btnLoading
      })
    },
    /*
     * 页面编辑权限判断
     * isEdit是否可编辑 布尔值(驱动节点状态 01正在进行为true 02已完成为false) isEvalLeader当前评委是为组长 00 否 01是 isRecommendCandidate 是否推荐候选人 00否不可编辑 01是可编辑
     * return true or false
     */
    isCostPerformanceEdit() {
      if (this.getTenderBase.isEdit && this.getTenderBase.isEvalLeader === '01' && this.getTenderBase.isRecommendCandidate === '01') {
        return true
      } else {
        return false
      }
    }
  }
}
</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%);
    }

/*评审指标信息*/
.evaluationBottomTb  {
  width: 100%;
  margin: 20px 0;
}
.evaluationBottomTb  td {
  border: 1px solid #E0E0E0;
  line-height: 20px;
  padding: 9px 10px;
    .el-form-item--small.el-form-item{
      margin: 0;
    }
    .el-input{
      width: 90%;
    }
}
.evaluationBottomTb  tr td:nth-child(odd) {
  background-color: #F5F7F9;
  width: 5%;
}
.evaluationBottomTb  tr td:nth-child(even) {
  width: 34%;
}
.evaluationBottomTb  tr.singleRow td:nth-child(odd) {
  background-color: #F5F7F9;
  width: 5.8%;
}
.evaluationBottomTab  {
  width: 100%;
  margin: 20px 0;
}
.evaluationBottomTab  td {
  border: 1px solid #E0E0E0;
  line-height: 20px;
  padding: 9px 10px;
    .el-form-item--small.el-form-item{
      margin: 0;
    }
    .el-input{
      width: 90%;
    }
}
.evaluationBottomTab  tr td:nth-child(odd) {
  background-color: #F5F7F9;
  width: 5%;
}
.evaluationBottomTab  tr td:nth-child(even) {
  width: 34%;
}
.evaluationBottomTab  tr.singleRow td:nth-child(odd) {
  background-color: #F5F7F9;
  width: 5.8%;
}
</style>
