
<!--
  @description: 评标大厅-推荐中选候选人评审页面
  @Modifier：wxy/yf
  @routerPath: /procurement/evaluationLobbyDrive/winningCandidate
  @date： 2020-08-05 20:29:09
-->
<template>
  <div class="main">
    <div>
      <!-- 是组长可编辑  isRecommendCandidate是否显示推荐中标后选人 00 不显示 01 显示 -->
      <p v-if="isCostPerformanceEdit()" style="color:red;margin:10px 0">
        提示:组长您好，请您完成中标候选人推选！
      </p>
      <!-- 不是组长可编辑 -->
      <p v-if="getTenderBase.isEdit && getTenderBase.isEvalLeader==='00' && getTenderBase.isRecommendCandidate === '00' || getTenderBase.isEdit && getTenderBase.isEvalLeader==='01' && getTenderBase.isRecommendCandidate === '00'" style="color:red;margin:10px 0">
        提示：当前步骤为组长操作，请等待组长完成中标候选人推荐！
      </p>
      <!-- <p v-if="!isEdit" style="color:red;margin:10px 0">提示：组长已经申请重新推荐中标候选人！</p> -->
      <winningCandidateTableComp ref="winningCandidateTableComp" :get-tender-base="getTenderBase" @showRecommendedReason="showRecommendedReason" />
      <el-form ref="ruleForm" :model="ruleForm" :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="ruleForm.avoidReason"
                :autosize="{ minRows: 3, maxRows: 3 }"
                gx-placeholder="placeholderText1000"
                gx-maxlength="varchar1000"
                type="textarea"
                style="width: calc(100%-50px)"
              />
              <span v-if="!isCostPerformanceEdit()">{{ ruleForm.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('ruleForm')">
              完成推荐
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* 公共校验*/
import { characters1_auto } from '@/assets/js/validate'
/* 组件*/
import winningCandidateTableComp from './procurementWinningCandidateTableComp' // 表格组件
// import driveStepRight from '../procurementEvaluationLobbyDrive/components/procurementDriveStepRight'
/* api*/
import {
  saveRecommendCandidate
} from '@api/procurement/procurementEvaluation'
export default {
  name: 'WinningCandidate',
  inject: ['getTenderBase', 'getDriveTask', 'driveReload'],
  components: {
    winningCandidateTableComp // 表格组件
    // 'drive-step-right': driveStepRight
  },
  mixins: [],
  data() {
    return {
      loading: false, // loading效果
      confirmLoading: false, // btnLoading
      ruleForm: { // 评审意见
        avoidReason: ''
      },
      //  校验
      rules: {
        avoidReason: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 评审意见
      },
      getTenderBase: this.getTenderBase() // getTenderBase参数
    }
  },
  watch: {
  },
  created() {
  },
  methods: {
    // 提交评审结果
    submit(formName) {
      this.loading = true // laoding效果
      this.confirmLoading = true // btnLoading
      // 检验是否推选
      let isElect = false
      this.$refs.winningCandidateTableComp.tableData.forEach(item => {
        if (item.recommend === '01') {
          isElect = true
        }
      })
      if (!isElect) {
        this.$message.warning('必须推荐中标候选人')
        this.loading = false // laoding效果
        this.confirmLoading = false // btnLoading
        return false
      }
      this.$refs[formName].validate((valid) => {
        // 校验是否填写评审意见
        if (valid) {
          this.$confirm(`提交之后将不可修改，确认提交评审结果吗？`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(res => {
            this.saveCandidate() // 综合评估法保存完成推荐后选人方法
          }).catch(() => {
            this.loading = false // laoding效果
            this.confirmLoading = false // btnLoading
          })
        } else {
          this.loading = false // laoding效果
          this.confirmLoading = false // btnLoading
          return false
        }
      })
    },
    /*
     * 综合评估法保存完成推荐后选人方法
    * @params assemblyData(组装保存数据方法) return {evaluationOpinion：推荐理由，expertPerformanceRateEvalList：供应商价格评审列表,driverId: 驱动id,evalExpertId:专家评审表ID【必传】,evalRule:评审规则 【00–整体步骤 01-单个评委步骤】,packId:项目标段id，stageId：阶段ID}
    * 保存推荐进入中选的供应商
    */
    saveCandidate() {
      const data = this.assemblyData()
      saveRecommendCandidate(data).then(res => {
        this.getTenderBase.isEdit = false // 提交成功后不显示完成推荐按钮
        this.loading = false // laoding效果
        this.confirmLoading = false // btnLoading
        // 刷新驱动
        this.driveReload()
        this.getDriveTask()
      }).catch(res => {
        this.$refs.winningCandidateTableComp.initData() // 当提示数据有变动是刷新推荐列表
        this.loading = false // laoding效果
        this.confirmLoading = false // btnLoading
      })
    },
    // 组装数据
    assemblyData() {
      // 统一处理task_no
      const supplierList = JSON.parse(JSON.stringify(this.$refs.winningCandidateTableComp.tableData))
      supplierList.forEach(item => {
        item.taskNo = this.getTenderBase.taskNo
      })
      const data = {
        evaluationOpinion: this.ruleForm.avoidReason,
        candidates: supplierList,
        driverId: this.getTenderBase.driverId,
        evalExpertId: this.getTenderBase.evalExpertId,
        evalRule: this.getTenderBase.evalRule,
        packId: this.getTenderBase.packId
      }
      return data
    },
    // 展示推荐理由
    showRecommendedReason(val) {
      this.ruleForm.avoidReason = val
    },
    /*
     * 页面编辑权限判断
     * 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>
  @import '~@assets/style/common/public.less';
/*评审指标信息*/
.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%;
}
// .evaluationBottomTab  tr.singleRow td:nth-child(even) {
//   width: calc(100%-8.5%);
// }
.driveStep{
  background: #ffffff;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid #E4E7ED;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
.imgBg{
  width: 16px;
  height: 16px;
  margin: 0 2px;
  color: @hyacinthine;
}
</style>
