<template>
  <div class="approval-form">
    <!-- 审批表单 -->
    <el-form
      size="mini"
      :model="dialogForm"
      prop="remark"
      :rules="rules"
      ref="form"
    >
      <el-form-item label="审批意见：">
        <el-radio-group
          v-model="checkStatus"
          size="mini"
          style="margin-bottom: 20px"
        >
          <el-radio :label="1" border>同意</el-radio>
          <el-radio :label="-2" border>驳回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="驳回意见：" prop="remark" v-if="checkStatus == -2">
        <el-input
          type="textarea"
          placeholder="驳回意见"
          v-model="dialogForm.remark"
          size="mini"
          :rows="4"
        >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          size="mini"
          style="margin:0; width: 100%"
          type="primary"
          icon="el-icon-check"
          @click.native="handleCheck"
          >确定</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      checkStatus: 1,
      dialogForm: {
        remark: "", //驳回意见
      },
      rules: {
        remark: [
          {
            required: true,
            message: "请输入驳回意见",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    async handleCheck() {
      const { checkStatus } = this;
      if (checkStatus == -2) {
        this.$refs.form.validate(async (valid) => {
          if (valid) {
            this.dialogLoading = true;
            const params = {
              sourceId: this.displayDetail.exhibitionId,
              checkStatus,
              remark: this.dialogForm.remark,
              sourceType: "biz_exhibition",
              sourceName: this.displayDetail.title,
            };
            let res = await postCheck(params);
            if (res.code == 0) {
              this.$message.success("操作成功！");
              this.handleClose();
              this.$emit("refresh");
              this.$refs.form.resetFields();
            }
            this.dialogLoading = false;
            this.popoverVisible = false;
          }
        });
      } else {
        this.dialogLoading = true;
        const params = {
          sourceId: this.displayDetail.exhibitionId,
          checkStatus,
          remark: this.dialogForm.remark,
          sourceType: "biz_exhibition",
          sourceName: this.displayDetail.title,
        };
        let res = await postCheck(params);
        if (res.code == 0) {
          this.$message.success("操作成功！");
          this.handleClose();
          this.$emit("refresh");
          this.$refs.form.resetFields();
        }
        this.dialogLoading = false;
        this.popoverVisible = false;
      }
    },
  },
};
</script>

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