<!--
  @description: 批量审核-弹框
  @Modifier：wxy
  @routerPath:
  @date：  2020-07-08 15:00:28
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    :lock-scroll="false"
    title="批量审核"
    width="860px"
    custom-class="el-dialog_table"
  >
    <div class="el-dialog-p0">
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <td>
              <el-form-item label="审核意见" prop="auditReason" />
            </td>
            <td>
              <el-input
                v-model="formData.auditReason"
                :autosize="{ minRows: 4, maxRows: 4 }"
                type="textarea"
                maxlength="1000"
                show-word-limit
                style="width:100%"
              />
            </td>
          </tr>
        </table>
      </el-form>
      <div class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <!-- 审核按钮 -->
            <el-button :loading="confirmLoading" type="primary" @click="auditYetSignUp()">
              审核通过
            </el-button>
            <el-button :loading="confirmLoading" @click="auditNoSignUp('form')">
              审核不通过
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
/* api接口*/
import { auditWinningResult } from '@/api/procurement/procurementResult'
/* 校验方法*/
import { characters1_auto } from '@/assets/js/validate'
export default {
  name: 'PatchAuditDialog',
  mixins: [],
  props: {
    dialogData: {
      type: Object,
      default: function() {
        return
      }
    }
  },
  data() {
    return {
      confirmLoading: false, // 暂存Loding
      formData: {
        auditStatus: '', // 审核表示02驳回,01通过
        auditReason: '' // 审核意见
      },
      // 校验规则
      rules: {
        auditReason: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 审核意见
      }
    }
  },
  created() {

  },
  methods: {
    // 审核通过
    auditYetSignUp() {
      // 审核通过auditStatus 01
      this.formData.auditStatus = '01'
      this.confirmLoading = true
      if (this.dialogData.winningIds === '') {
        this.$message.error('中选id为空')
        return
      }
      this.auditWinningResultData()
    },
    // 审核不通过
    auditNoSignUp(formName) {
      // 审核通过auditStatus 02
      this.formData.auditStatus = '02'
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.confirmLoading = true
          if (this.dialogData.winningIds === '') {
            this.$message.error('中选id为空')
            return
          }
          this.auditWinningResultData()
        } else {
          this.confirmLoading = false
        }
      })
    },
    // 保存数据方法
    assestData() {
      const data = {
        winningIds: this.dialogData.winningIds,
        auditStatus: this.formData.auditStatus,
        auditReason: this.formData.auditReason
      }
      return data
    },
    // 封装审核方法
    auditWinningResultData() {
      const data = this.assestData()
      auditWinningResult(data).then(res => {
        this.confirmLoading = false
        this.dialogData.dialog = false
      }).catch(() => {
        this.confirmLoading = false
      })
    }
  }
}
</script>

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