<template>
  <el-dialog
    title="反馈信息"
    v-model="formOpen"
    width="500px"
    append-to-body
    draggable
    :close-on-click-modal = "false"
    @close="cancel"
  >
    <el-form ref="dictRef" :model="form" label-width="100">
      <el-form-item label="驳回原因：">
        <el-input
          v-model="form.feedbackContent"
          type="textarea"
          maxlength="200"
          show-word-limit
          style="width: 100%"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button
          type="primary"
          icon="Finished"
          size="small"
          @click="submitForm"
          >确 定</el-button
        >
        <el-button icon="close" size="small" @click="cancel">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";

const { proxy } = getCurrentInstance();

const props = defineProps({
  verify: {
    type: Function,
    default: () => {},
  },
});

const { verify } = toRefs(props);
const currentMonth = ref(proxy.moment().format("YYYY-MM-01"));

const formOpen = ref(false);
const form = ref({});

function submitForm() {
  if (form.value.feedbackContent === "" || form.value.feedbackContent == null) {
    proxy.$modal.msg("请填写驳回原因");
    return;
  }
  proxy.$modal
    .confirm("确认审核么？")
    .then((_) => {
      verify.value(form.value);
      cancel();
    })
    .catch((_) => {
      proxy.$modal.msg("取消驳回");
    });
}

function cancel() {
  formOpen.value = false;
  reset();
}

function open(options) {
  formOpen.value = true;
  form.value = options;
}

function reset() {
  form.value = {};
}

// 暴露给父组件的方法
defineExpose({
  open,
});
</script>