<!--
  @description: 评标-废标-发起废标弹框
  @Modifier: yf
  @routerPath:/procurement/evaluationLobbyDrive/initiateWasteBid
  @date: 2020-8-22-16:56
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    title="发起废标"
    width="450px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <div>
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <td>
              <el-form-item>项目名称</el-form-item>
            </td>
            <td>
              <el-form-item>{{ formData.tenderName }}</el-form-item>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item>是否由专家表决</el-form-item>
            </td>
            <td>
              <el-form-item>
                <el-radio-group v-model="formData.abandonType">
                  <el-radio label="01">
                    是
                  </el-radio>
                  <el-radio label="00">
                    否
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="废标原因" prop="abandonReason" />
            </td>
            <td>
              <el-input
                v-model.trim="formData.abandonReason"
                :autosize="{ minRows: 4, maxRows: 4 }"
                type="textarea"
                maxlength="1000"
                show-word-limit
                style="width: 90%"
              />
            </td>
          </tr>
        </table>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
// 公共校验方法
import { characters1_auto } from '@/assets/js/validate'// 校验输入内容
/* api接口*/
import {
  sponsorAbandonOperation,
  queryProcurementAbandonStatus
} from '@api/procurement/procurementEvaluation'
export default {
  name: 'WasteBidDialog',
  components: {},
  inject: ['getTenderBase', 'getDriveTask', 'driveReload'],
  mixins: [],
  data() {
    return {
      formData: {
        tenderName: '北京创新电话数据清洗项目', // 项目名称
        abandonType: '01', // 是否需要专家表决, 00否01是
        abandonReason: '' // 废标原因
      },
      rules: {
        abandonReason: [
          { required: true, validator: characters1_auto, trigger: 'blur' }
        ] // 废标原因
      },
      dialogVisible: true, // 弹框是否可见
      getTenderBase: this.getTenderBase() // 项目基本信息
    }
  },
  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.formData.tenderName = res.data.tenderName
      })
    },
    // 提交开始废标
    ensure() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 判断是否需要专家表决 00否01是
          if (this.formData.abandonType === '00') {
            this.$confirm('确定不需要其他评委投票，直接废标吗？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              confirmButtonClass: 'confirmBtn',
              cancelButtonClass: 'cancelBtn',
              type: 'warning'
            }).then(() => {
              this.$confirm('本项目已废标！请您前往评审报表步骤完成电子签章！', '提示', {
                confirmButtonText: '去签章',
                confirmButtonClass: 'confirmBtn',
                showCancelButton: false,
                type: 'warning'
              }).then(() => {
                const data = {
                  ...this.formData,
                  driverId: this.getTenderBase.driverId,
                  evalExpertId: this.getTenderBase.evalExpertId,
                  evalRule: this.getTenderBase.evalRule,
                  packId: this.getTenderBase.packId
                }
                sponsorAbandonOperation(data).then(res => {
                  // 刷新驱动
                  this.driveReload()
                  this.getDriveTask()
                })
              })
            })
            return
          }
          // 需要专家表决
          this.$confirm('确定发起废标，并由专家进行表决吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            const data = {
              ...this.formData,
              driverId: this.getTenderBase.driverId,
              evalExpertId: this.getTenderBase.evalExpertId,
              evalRule: this.getTenderBase.evalRule,
              packId: this.getTenderBase.packId
            }
            sponsorAbandonOperation(data).then(res => {
              // 刷新驱动
              // this.driveReload()
              // this.getDriveTask()
              this.$router.push('/procurement/evaluationLobbyDrive/wasteBidVote')
            })
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
