<!--
  @description: 集采计划分配-行项目退回
  @author: lxl/hdk
  @date： 2020-10-30 14:52
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialogVisible"
    :before-close="handleClose"
    title="整包退回"
    width="700px"
    custom-class="el-dialog__body-p0"
    top="calc((100vh - 336px) / 2)"
  >
    <div class="main mb10">
      <el-form ref="form" :model="formData" :rules="rules" :inline-message="true">
        <table class="from_table">
          <td>
            <el-form-item label="退回意见" prop="bizReason" />
          </td>
          <td colspan="3">
            <el-input
              v-model.trim="formData.bizReason"
              :autosize="{ minRows: 3, maxRows: 3 }"
              type="textarea"
              gx-maxlength="varchar500"
              show-word-limit
            />
          </td>
        </table>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="btnLoading" type="primary" @click="ensure('form')">
        确 定
      </el-button>
      <el-button @click="handleClose">
        取 消
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
/* api*/
import { returnBackToRtPlanMenuAtAssignList } from '@/api/procurement/purchasplan'
/* 公共方法 */
import { characters1_auto } from '@/assets/js/validate' // 校验输入内容

export default {
  name: 'WholeBackDialog',
  props: {
    dialogData: {
      type: Object,
      default: function() {
        return {
          dialogVisible: false,
          tenderIds: ''
        }
      }
    }
  },
  data() {
    return {
      formData: { // 表单数据
        bizReason: '' // 退回原因
      },
      btnLoading: false, // 按钮loading
      rules: {
        bizReason: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 退回原因
      }
    }
  },
  methods: {
    // 确定
    ensure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.btnLoading = true
          const params = {
            tenderIds: this.dialogData.tenderIds,
            bizReason: this.formData.bizReason
          }
          returnBackToRtPlanMenuAtAssignList(params).then(response => {
            this.btnLoading = false
            this.$message.success(response.header.msg)
            // 关闭弹窗
            this.handleClose()
          }).catch(() => {
            this.btnLoading = false
          })
        }
      })
    },
    // 关闭
    handleClose() {
      this.$emit('refreshList')
      this.dialogData.dialogVisible = false
    }
  }
}
</script>

<style scoped>

</style>
