| | |
| | | import useUserStore from "@/store/modules/user"; |
| | | import { Search } from "@element-plus/icons-vue"; |
| | | import { ElMessage, ElMessageBox } from "element-plus"; |
| | | import { computed, reactive, ref } from "vue"; |
| | | import { computed, getCurrentInstance, reactive, ref } from "vue"; |
| | | import { |
| | | inferReimburseModuleKeyFromInstance, |
| | | loadReimburseDetailForInstance, |
| | | navigateToReimburseManageForEdit, |
| | | resolveFinReimbursementIdFromInstance, |
| | | } from "../../ReimburseManage/shared/reimburseApproveBridge.js"; |
| | | import { |
| | | fetchBusinessTypeOptions, |
| | | formatDisplayTime, |
| | |
| | | } from "./approveListConstants.js"; |
| | | |
| | | export function useApproveList() { |
| | | const { proxy } = getCurrentInstance() || {}; |
| | | const userStore = useUserStore(); |
| | | |
| | | const tableData = ref([]); |
| | |
| | | const approveOpinion = ref(""); |
| | | const approveSubmitting = ref(false); |
| | | |
| | | /** 差旅/费用报销专用详情、审批弹窗 */ |
| | | const reimburseDialog = reactive({ |
| | | visible: false, |
| | | mode: "detail", |
| | | moduleKey: "", |
| | | loading: false, |
| | | reimburseRow: {}, |
| | | instanceRow: null, |
| | | }); |
| | | |
| | | const submitDialog = reactive({ visible: false, step: 1, mode: "add" }); |
| | | const submitEditRow = ref(null); |
| | | const submitForm = reactive(createEmptySubmitForm("")); |
| | | const submitFormRef = ref(); |
| | | const submitSaving = ref(false); |
| | | |
| | | // 批量删除相关 |
| | | const selectedRows = ref([]); |
| | | |
| | | const isSubmitEdit = computed(() => submitDialog.mode === "edit"); |
| | | const submitDialogTitle = computed(() => { |
| | |
| | | fetchApprovalList(); |
| | | } |
| | | |
| | | function openDetail(row) { |
| | | async function openReimburseDetail(row, mode) { |
| | | const moduleKey = inferReimburseModuleKeyFromInstance(row); |
| | | if (!moduleKey) return false; |
| | | reimburseDialog.mode = mode; |
| | | reimburseDialog.moduleKey = moduleKey; |
| | | reimburseDialog.instanceRow = row; |
| | | reimburseDialog.visible = true; |
| | | reimburseDialog.loading = true; |
| | | reimburseDialog.reimburseRow = {}; |
| | | try { |
| | | const { reimburseRow, moduleKey: resolvedMk } = |
| | | await loadReimburseDetailForInstance(row, moduleKey); |
| | | reimburseDialog.moduleKey = resolvedMk || moduleKey; |
| | | reimburseDialog.reimburseRow = reimburseRow; |
| | | return true; |
| | | } catch { |
| | | ElMessage.error("加载报销详情失败"); |
| | | reimburseDialog.visible = false; |
| | | return false; |
| | | } finally { |
| | | reimburseDialog.loading = false; |
| | | } |
| | | } |
| | | |
| | | async function openDetail(row) { |
| | | if (isReimburseApprovalInstance(row)) { |
| | | await openReimburseDetail(row, "detail"); |
| | | return; |
| | | } |
| | | detailRow.value = { ...row }; |
| | | detailDialog.visible = true; |
| | | } |
| | | |
| | | function openApprove(row) { |
| | | async function openApprove(row) { |
| | | if (inferReimburseModuleKeyFromInstance(row)) { |
| | | approveOpinion.value = ""; |
| | | await openReimburseDetail(row, "approve"); |
| | | return; |
| | | } |
| | | approveDialog.row = { ...row }; |
| | | approveOpinion.value = ""; |
| | | approveDialog.visible = true; |
| | | } |
| | | |
| | | function isReimburseApprovalInstance(row) { |
| | | return Boolean(inferReimburseModuleKeyFromInstance(row)); |
| | | } |
| | | |
| | | function resetSubmitDialogState() { |
| | |
| | | loadSubmitTemplates(); |
| | | } |
| | | |
| | | function openEditDialog(row) { |
| | | async function openEditDialog(row) { |
| | | if (row?.approvalStatus !== "pending") { |
| | | ElMessage.warning("仅审核中的审批可修改"); |
| | | return; |
| | | } |
| | | const moduleKey = inferReimburseModuleKeyFromInstance(row); |
| | | if (moduleKey) { |
| | | const rid = resolveFinReimbursementIdFromInstance(row); |
| | | if (rid == null) { |
| | | ElMessage.warning("无法修改:缺少报销单 ID"); |
| | | return; |
| | | } |
| | | try { |
| | | await navigateToReimburseManageForEdit(proxy?.$router, moduleKey, rid); |
| | | } catch { |
| | | ElMessage.warning("未找到差旅/费用报销菜单路由,请从左侧菜单进入后再编辑"); |
| | | } |
| | | return; |
| | | } |
| | | if (!row?.id) { |
| | |
| | | } |
| | | } |
| | | |
| | | async function submitReimburseApprove(result) { |
| | | const row = reimburseDialog.instanceRow; |
| | | if (!row?.id) return { ok: false }; |
| | | if (result === "rejected" && !(approveOpinion.value || "").trim()) { |
| | | return { needOpinion: true }; |
| | | } |
| | | if (approveSubmitting.value) return { ok: false }; |
| | | approveSubmitting.value = true; |
| | | try { |
| | | await approveApprovalInstance( |
| | | buildApproveInstanceDto(row, result, approveOpinion.value) |
| | | ); |
| | | reimburseDialog.visible = false; |
| | | await fetchApprovalList(); |
| | | return { ok: true, result }; |
| | | } catch { |
| | | ElMessage.error("审批操作失败"); |
| | | return { ok: false }; |
| | | } finally { |
| | | approveSubmitting.value = false; |
| | | } |
| | | } |
| | | |
| | | async function submitApprove(result) { |
| | | const row = approveDialog.row; |
| | | if (!row?.id) return { ok: false }; |
| | |
| | | return "待处理"; |
| | | } |
| | | |
| | | // 批量删除审批实例 |
| | | async function batchDelete() { |
| | | if (!selectedRows.value?.length) { |
| | | ElMessage.warning("请选择要删除的记录"); |
| | | return; |
| | | } |
| | | try { |
| | | await ElMessageBox.confirm( |
| | | `确定删除选中的 ${selectedRows.value.length} 条审批记录吗?删除后不可恢复。`, |
| | | "删除确认", |
| | | { |
| | | type: "warning", |
| | | confirmButtonText: "确定删除", |
| | | cancelButtonText: "取消", |
| | | distinguishCancelAndClose: true, |
| | | autofocus: false, |
| | | } |
| | | ); |
| | | } catch { |
| | | return; |
| | | } |
| | | const ids = selectedRows.value.map((row) => row.id).filter(Boolean); |
| | | if (!ids.length) { |
| | | ElMessage.warning("无法删除:缺少审批实例 ID"); |
| | | return; |
| | | } |
| | | try { |
| | | await deleteApprovalInstance(ids); |
| | | ElMessage.success("删除成功"); |
| | | selectedRows.value = []; |
| | | // 关闭可能打开的详情弹窗 |
| | | if (detailDialog.visible) { |
| | | detailDialog.visible = false; |
| | | } |
| | | if (approveDialog.visible) { |
| | | approveDialog.visible = false; |
| | | } |
| | | await fetchApprovalList(); |
| | | } catch { |
| | | /* 错误由拦截器提示 */ |
| | | } |
| | | } |
| | | |
| | | return { |
| | | Search, |
| | | APPROVAL_TYPE_OPTIONS, |
| | |
| | | tableColumn, |
| | | detailDialog, |
| | | detailRow, |
| | | reimburseDialog, |
| | | approveDialog, |
| | | approveOpinion, |
| | | approveSubmitting, |
| | | submitReimburseApprove, |
| | | isReimburseApprovalInstance, |
| | | submitDialog, |
| | | isSubmitEdit, |
| | | submitDialogTitle, |
| | |
| | | openDetail, |
| | | openApprove, |
| | | fetchApprovalList, |
| | | selectedRows, |
| | | batchDelete, |
| | | }; |
| | | } |