<template>
  <el-dialog :title="title" :visible="show" width="500px" center @open="open" @close="close">
    <el-form :model="form" :rules="rules" ref="form">
      <el-form-item label="审核意见" prop="remark">
        <el-input
          type="textarea"
          maxlength="200"
          show-word-limit
          v-model="form.remark"
          placeholder="请输入审核意见，该审核意见会反馈给申请用户"
          :rows="5"
        />
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button type="success" icon="el-icon-check" plain @click="handlePass">通过</el-button>
      <el-button type="danger" icon="el-icon-close" plain @click="handleReject">驳回</el-button>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: 'SimpleVerifyDialog',
  props: {
    title: {
      type: String,
      default: '审核',
    },
    show: {
      type: Boolean,
      default: false,
    },
    requiredRemark: {
      type: Boolean,
      default: true,
    },
    reset: {
      type: Boolean,
      default: true,
    }
  },
  data() {
    return {
      form: {},
      rules: {
        remark: [
          {required: this.requiredRemark, message: '审核意见不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  created() {
    this.resetForm();
  },
  methods: {
    open() {
      if (this.reset) {
        this.resetForm();
      }
    },
    close() {
      this.$emit('update:show', false);
    },
    resetForm() {
      this.form = {
        remark: null,
      }
    },
    handleReject() {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return;
        }
        this.$confirm('确认驳回吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          this.$emit('reject', this.form);
        });
      });
    },
    handlePass() {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return;
        }
        this.$confirm('确认通过吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          this.$emit('pass', this.form);
        });
      })
    },
  }
}
</script>

<style scoped lang="scss">

</style>
