<!--
  @description: 评标-废标-废标表决弹框
  @Modifier: yf
  @routerPath:/procurement/evaluationLobbyDrive/wasteBidVote
  @date: 2020-8-22-16:56
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    :show-close="false"
    title="废标表决"
    width="550px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <div>
      <div style="text-align:center">
        <p class="packName">
          {{ tenderName }}
        </p>
        <p style="margin-bottom:10px">
          项目编号：{{ tenderNo }}
        </p>
      </div>
      <div class="wasteBid">
        <p class="clearfix">
          <span class="fl wasteTitle">废标理由：</span>
          <span class="fr wasteContent">{{ abandonReason }}</span>
        </p>
        <p v-if="isVote" class="clearfix">
          <span class="fl wasteTitle">您的投票结果：</span>
          <span v-if="currentVoteResult === '00'" class="fr wasteContent" style="color:red">不同意</span>
          <span v-if="currentVoteResult === '01'" class="fr wasteContent" style="color:red">同意</span>
        </p>
        <p v-if="finalVoteResult" class="clearfix">
          <span class="fl wasteTitle">投票结果：</span>
          <span v-if="finalVoteResult === '00'" class="fr wasteContent" style="color:red">不废标</span>
          <span v-if="finalVoteResult === '01'" class="fr wasteContent" style="color:red">废标</span>
          <span v-if="finalVoteResult === '02'" class="fr wasteContent" style="color:red">废标表决中</span>
        </p>
      </div>
      <div style="text-align:center">
        <p>
          <span>评委总数：</span>
          <span class="effectNum">{{ partakeNum }}</span>
          <span>废标投票：</span>
          <span class="invalidNum">{{ agreeNum }}</span>
          <span>不废标投票：</span>
          <span class="effectNum">{{ refuseNum }}</span>
        </p>
      </div>
      <button type="text" class="el-button mb10 el-button--text el-button--mini">
        <!-- 投票已完成，结果废标 -->
        <p v-if="finalVoteResult === '01'" style="color:red;margin:10px auto;width:87%">
          投票结果已产生！本项目已废标！请您前往评审报表步骤完成电子签章！
        </p>
        <!-- 投票已完成，结果不废标 -->
        <p v-if="finalVoteResult === '00'" style="color:red;margin:10px auto;width:87%">
          投票结果已产生！投票结果为不废标，请继续进行评审！
        </p>
        <!-- 当前投票已完成，总结结果为产生 -->
        <p v-if="isVote && finalVoteResult === '02'" style="color:red;margin:10px auto;width:87%">
          请等待其他评委完成投票！
        </p>
      </button>
    </div>
    <!-- 底部按钮 -->
    <template>
      <!-- 评委还未投票 会有多个组长情况 所以不分是不是组长 只要没投票 就让他投票-->
      <div v-if="!isVote" class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <el-button size="small" type="primary" @click="submit('01')">
              废标
            </el-button>
            <el-button size="small" @click="submit('00')">
              不废标
            </el-button>
          </div>
        </div>
      </div>
      <!-- 如果当前评委选择不废标 -->
      <div v-if="(isVote && finalVoteResult === '00') || (isVote && finalVoteResult === '02')" class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <el-button size="small" @click="dialogVisible=false">
              我知道了
            </el-button>
          </div>
        </div>
      </div>
      <!-- 如果当前评委选择废标 -->
      <div v-if="isVote && finalVoteResult === '01'" class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <el-button size="small">
              去签章
            </el-button>
          </div>
        </div>
      </div>
    </template>
  </el-dialog>
</template>

<script>
/* api接口*/
import {
  partakeAbandonVotes,
  queryProcurementAbandonStatus
} from '@api/procurement/procurementEvaluation'
export default {
  name: 'WasteBidDialog',
  components: {},
  inject: ['getTenderBase', 'getDriveTask', 'driveReload'],
  mixins: [],
  data() {
    return {
      dialogVisible: true, // 弹框是否可见
      getTenderBase: this.getTenderBase(), // 项目基本信息
      isVote: false, // 是否已投票
      currentVoteResult: null, // 当前评委投票结果 00 不废标 01 废标
      finalVoteResult: null, // 最终投票结果 00 不废标 01 废标
      abandonReason: '', // 废标原因
      agreeNum: null, // 同意废标数量
      partakeNum: null, // 评委数量
      refuseNum: null, // 拒绝数量
      tenderName: '', // 项目名称
      tenderNo: '' // 项目编号
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    initData() {
      // 评委查看废标原因、投票情况
      const data = {
        evalExpertId: this.getTenderBase.evalExpertId,
        driverId: this.getTenderBase.driverId,
        packId: this.getTenderBase.packId,
        evalRule: this.getTenderBase.evalRule
      }
      queryProcurementAbandonStatus(data).then(res => {
        this.dialogVisible = true
        // 是否已投票
        if (res.data.isVotes === '01' && res.data.isVotes !== null) {
          this.isVote = true
        } else if (res.data.isVotes === '00' && res.data.isVotes !== null) {
          this.isVote = false
        }
        // 最终投票结果
        if (res.data.abandonStatus === '01' && res.data.abandonStatus !== null) {
          this.finalVoteResult = '01'
        } else if (res.data.abandonStatus === '00' && res.data.abandonStatus !== null) {
          this.finalVoteResult = '00'
        } else if (res.data.abandonStatus === '02' && res.data.abandonStatus !== null) {
          this.finalVoteResult = '02'
        }
        // 当前评委投票结果
        if (res.data.isAgreeAbandon === '01' && res.data.isAgreeAbandon !== null) {
          this.currentVoteResult = '01'
        } else if (res.data.isAgreeAbandon === '00' && res.data.isAgreeAbandon !== null) {
          this.currentVoteResult = '00'
        }
        this.abandonReason = res.data.abandonReason
        this.agreeNum = res.data.agreeNum
        this.partakeNum = res.data.partakeNum
        this.refuseNum = res.data.refuseNum
        this.tenderName = res.data.tenderName
        this.tenderNo = res.data.tenderNo
      })
    },
    // 监视票数
    monitoringWasteBid() {
      // 判断当前评委是否完成投票
      if (this.isVote) {
        this.initData()
      }
    },
    // 提交开始废标
    submit(val) {
      let text = '' // 动态提示文本
      // 00不废标
      if (val === '00') {
        text = '不废标'
      }
      if (val === '01') {
        text = '废标'
      }
      // 01废标
      this.$confirm(`确定${text}吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = {
          evalExpertId: this.getTenderBase.evalExpertId,
          driverId: this.getTenderBase.driverId,
          packId: this.getTenderBase.packId,
          evalRule: this.getTenderBase.evalRule,
          isAgreeAbandon: val
        }
        partakeAbandonVotes(data).then(res => {
          // 已投票
          this.isVote = true
          // 设置当前评委投票结果
          this.currentVoteResult = val
          this.initData()
        })
      })
    }
  }
}
</script>

<style lang='less' scoped>
  @import '~@assets/style/common/public.less';
.packName {
  font-size:16px;
  font-family:Microsoft YaHei;
  font-weight:bold;
  color:@dark-font;
  margin-bottom: 10px;
}
.wasteBid {
  width: 96%;
  height: 100%;
  margin: 0 auto;
  background-color: #F1F1F1;
  padding: 10px 10px;
  margin-bottom: 10px;
}
.wasteTitle{
  display: inline-block;
  width: 20%;
  color: @light-font;
  line-height:21px;
  font-weight:400;
}
.wasteContent{
  display: inline-block;
  width: 80%;
  color: @dark-font;
  font-weight:400;
  line-height:21px;
}
.invalidNum {
  color: @orange;
}
.effectNum {
  color: @hyacinthine;
}
</style>
