<template>
  <el-dialog
    title="驳回理由"
    :visible.sync="localVisible"
    width="40%"
    append-to-body
  >
    <el-form ref="rejectReasonForm" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="驳回理由" prop="rejectReason">
        <el-input
          v-model="form.rejectReason"
          type="textarea"
          :rows="4"
          placeholder="请输入驳回理由"
          maxlength="500"
          show-word-limit
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleConfirm">确认驳回</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "RejectReasonDialog",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    form: {
      type: Object,
      default: () => ({
        rejectReason: ''
      })
    },
    rules: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      localVisible: this.visible
    }
  },
  watch: {
    visible(newVal) {
      this.localVisible = newVal;
    }
  },
  methods: {
    handleCancel() {
      this.localVisible = false;
      this.$emit('update:visible', false);
      this.$emit('cancel');
    },
    handleConfirm() {
      this.$refs.rejectReasonForm.validate((valid) => {
        if (valid) {
          this.$emit('confirm', this.form);
        }
      });
    }
  }
};
</script>

<style scoped>
.dialog-footer {
  text-align: right;
}
</style>
