<!--
  @description: 计划退回弹窗
  @Modifier: 郝定康
  @date: 2021-02-03 13:30:31
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    title="计划退回"
    width="1000px"
  >
    <el-form ref="form" :model="formData" :rules="rules" :inline-message="true" class="mb10">
      <table class="tableData">
        <tr>
          <td>
            <el-form-item label="退回意见" prop="bizReason" />
          </td>
          <td colspan="3">
            <el-input
              v-model="formData.bizReason"
              placeholder="请输入内容"
              :autosize="{ minRows: 10, maxRows: 10 }"
              type="textarea"
              maxlength="1000"
              show-word-limit
              style="width:100%"
            />
          </td>
        </tr>
        <tr>
          <td>  <el-form-item label="附件上传" /></td>
          <td>
            <upload
              ref="upload"
              :title="''"
              :data="fileData"
              :auto-delete="true"
              :auto-upload="true"
              :limit="10"
              :file-size="200"
              tip-text="上传附件格式（*.doc;*.docx;*.pdf;*.png;*.jpg;*.zip;*.xlsx;*.xls;*.rar）单个文件不得超过200M"
              accept=".doc,.docx,.pdf,.png,.jpg,.zip,.jpeg,.txt,.xls,.ppt,.pptx,.rar"
              file-ref="fileRef"
              but-text="点击上传"
            />
          </td>
        </tr>
      </table>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure('form')">
        确 定
      </el-button>
      <el-button @click="handleClose">
        取 消
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
/* api*/
import { returnBackToRtPlanMenu } from '@/api/procurement/purchasplan'
/* 公共方法 */
import { characters1_auto } from '@/assets/js/validate' // 校验输入内容
import upload from '@comp/common/updownload/upload' // 文件上传组件

export default {
  name: 'PlanReturnDialog',
  components: {
    upload
  },
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {
        return {
          dialog: false,
          bizId: '',
          id: ''
        }
      }
    }
  },
  data() {
    return {
      formData: {
        bizReason: '',
        tenderId: this.dialogData.id
      },
      // 附件信息
      fileData: {
        bizId: '',
        fileType: 'biz_type_assign_return_plan_file'
      },
      rules: {
        bizReason: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 退回原因
      }
    }
  },
  created() {
    this.fileData.bizId = this.dialogData.bizId // 附件id
  },
  methods: {
    // 确定
    ensure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 计划退回
          returnBackToRtPlanMenu(this.formData).then(res => {
            this.$message({
              type: 'success',
              message: '退回成功！'
            })
            this.$emit('callBack')
            // 关闭弹窗
            this.handleClose()
          }).catch(() => {
          })
        } else {
          this.$message({
            type: 'warning',
            message: '请填写退回意见'
          })
        }
      })
    },
    handleClose() {
      this.dialogData.dialog = false
    }
  }
}
</script>

<style scoped lang="less">

</style>

