
<!--
  @description: 评标大厅-经济评审行项目报价申请退回弹框
  @Modifier：wxy/yf
  @routerPath:
  @date：   2020-08-05 16:02:13
-->
<template>
  <el-dialog
    :visible.sync="dialogData.dialog"
    title="申请退回"
    width="40%"
  >
    <el-form ref="formData" :model="formData" :inline-message="true" :rules="rules">
      <table class="from_table">
        <tr>
          <td><el-form-item label="评审步骤" prop="taskName" /></td>
          <td>{{ getTenderBase.taskName }}</td>
        </tr>
        <tr>
          <td><el-form-item label="申请原因" prop="auditReason" /></td>
          <td>
            <el-form-item>
              <el-input
                v-model="formData.auditReason"
                :autosize="{ minRows: 4, maxRows: 4 }"
                type="textarea"
                maxlength="1000"
                show-word-limit
                style="width: 85%"
              />
            </el-form-item>
          </td>
        </tr>
      </table>
    </el-form>
    <p class="content">
      提示：退回操作不会丢失已评审数据！
    </p>
    <span slot="footer" class="dialog-footer">
      <el-button :loading="confirmLoading" type="primary" @click="submit('formData')">申请退回</el-button>
      <el-button @click="dialogData.dialog=false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* api*/
import {
  reevaluationProcedureApply
} from '@/api/procurement/procurementEvaluation.js'
/* 公共方法*/
import { restoreInitialValue } from '@assets/js/utils'
import { characters1_auto } from '@/assets/js/validate'
export default {
  props: {
    dialogData: {
      type: Object,
      default: function() {
        return {
          dialog: false
        } // false 关闭 true 打开
      }
    },
    // 项目信息
    getTenderBase: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  inject: [],
  data() {
    return {
      confirmLoading: false, // btnLoading
      formData: {
        auditReason: '' // 申请原因
      },
      rules: {
        auditReason: [{ required: true, validator: characters1_auto, trigger: 'blur' }]
      }
    }
  },
  watch: {
    // 弹框打开状态
    'dialogData.dialog'(val) {
      if (val === false) {
        // 清空 value
        restoreInitialValue(this.formData)
        // 清空校验
        this.$refs.formData.clearValidate()
      }
    }
  },
  mounted() {
  },
  methods: {
    // 提交退回申请
    submit(formName) {
      // 是否通过必填校验
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 判断是否为符合性评审回退
          if (this.getTenderBase.taskNo === '03') {
            // 确定提交
            this.$confirm('申请退回之后，所有专家须重评全部步骤。确认申请退回吗？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              confirmButtonClass: 'confirmBtn',
              cancelButtonClass: 'cancelBtn',
              type: 'warning'
            }).then(() => {
              this.rollbackRequest()
            })
            return
          }
          this.rollbackRequest()
        } else {
          return false
        }
      })
    },
    // 回退请求
    rollbackRequest() {
      this.confirmLoading = true // btnLoading
      const data = {
        evalExpertId: this.getTenderBase.evalExpertId,
        driverId: this.getTenderBase.driverId,
        packId: this.getTenderBase.packId,
        reevaluationReason: this.formData.auditReason
      }
      reevaluationProcedureApply(data).then(res => {
        // 关闭弹框
        this.confirmLoading = false // btnLoading
        this.dialogData.dialog = false // 关闭弹框
        this.$emit('reloadDrive')
      }).catch(() => {
        this.confirmLoading = false // btnLoading
      })
    }
  }
}
</script>

<style lang='less' scoped>
.content{
  margin: 5px 0;
  font-size: 12px;
}
</style>
