<template>
    <ElDialog
      v-model="showRejectDialog"
      title="拒绝原因"
      width="400px"
      @close="showRejectDialog = false"
    >
      <ElInput
        type="textarea"
        rows="3"
        placeholder="请输入拒绝原因"
        v-model="rejectReason"
      />
      <template #footer>
        <ElButton @click="showRejectDialog = false">取消</ElButton>
        <ElButton type="danger" @click="handleReject">确认拒绝</ElButton>
      </template>
    </ElDialog>
  </template>
  
  <script lang="ts" setup name="RefuseNotification">
  import { inject } from 'vue';
  import { ElMessage } from 'element-plus';
  import * as api from '../api';
  
  const showRejectDialog = inject('showRejectDialog') as Ref<boolean>;
  const rejectReason = inject('rejectReason') as Ref<string>;
  const currentFormId = inject('currentFormId') as Ref<number | null>;
  const crudExpose = inject('crudExpose') as any;
  const closeDialog = inject('closeDialog') as () => void;
  const handleReject = async () => {
    if (!rejectReason.value.trim()) {
      ElMessage.warning("请填写拒绝原因");
      return;
    }
    await api.BorrowingReview(currentFormId.value, "reject", rejectReason.value);
    ElMessage.success("已拒绝申请");
    showRejectDialog.value = false;
    closeDialog();
    crudExpose?.doRefresh();
  };
  </script>
  
  