<template>
  <el-dialog title="反馈信息" v-model="formOpen" width="500px" append-to-body draggable @close="cancel" :close-on-click-modal = "false">
    <el-form ref="dictRef" :model="form" label-width="100">
      <el-form-item :label="`${form.status === 4 ? '驳回原因' : '反馈信息'}：`">
        <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" size="small" icon="Finished" @click="submitForm">确 定</el-button>
        <el-button @click="cancel" icon="close" size="small">取 消</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.msgError(
      `请填写${form.value.status === 4 ? "驳回原因" : "反馈信息"}`
    );
    return;
  }
  proxy.$modal
    .confirm("确认审核么？")
    .then((_) => {
      verify.value(form.value);
      cancel();
    })
    .catch((_) => {
      proxy.$modal.msg("取消驳回");
    });
}

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

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

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

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