| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import { getFinReimbursementDetail } from "@/api/officeProcessAutomation/finReimbursement.js"; |
| | | import { matchBusinessTypeValue } from "../../ApproveManage/approve-list/approveListConstants.js"; |
| | | import { |
| | | APPROVAL_MODULE_KEYS, |
| | | getApprovalModuleConfig, |
| | | } from "../../ApproveManage/approve-shared/approvalModuleRegistry.js"; |
| | | import { |
| | | getModuleKeyByReimbursementType, |
| | | mapFinReimbursementDetailRow, |
| | | resolveReimbursementType, |
| | | unwrapFinReimbursementDetail, |
| | | } from "./finReimbursementMappers.js"; |
| | | |
| | | export const REIMBURSE_EDIT_FROM_APPROVE_KEY = "oa_reimburse_edit_from_approve"; |
| | | |
| | | const REIMBURSE_MODULE_KEYS = [ |
| | | APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE, |
| | | APPROVAL_MODULE_KEYS.COST_REIMBURSE, |
| | | ]; |
| | | |
| | | /** 审æ¹å®ä¾æ¯å¦å·®æ
/è´¹ç¨æ¥é */ |
| | | export function inferReimburseModuleKeyFromInstance(row) { |
| | | if (!row) return ""; |
| | | for (const moduleKey of REIMBURSE_MODULE_KEYS) { |
| | | const cfg = getApprovalModuleConfig(moduleKey); |
| | | if (!cfg) continue; |
| | | if ( |
| | | cfg.businessType != null && |
| | | cfg.businessType !== "" && |
| | | matchBusinessTypeValue(row.businessType, cfg.businessType) |
| | | ) { |
| | | return moduleKey; |
| | | } |
| | | if (matchBusinessTypeValue(row.businessType, cfg.approvalType)) { |
| | | return moduleKey; |
| | | } |
| | | const text = `${row.templateName || ""}${row.title || ""}${row.businessName || ""}`; |
| | | if ((cfg.typeLabels || []).some((l) => l && text.includes(l))) { |
| | | return moduleKey; |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | export function isReimburseApprovalInstance(row) { |
| | | return Boolean(inferReimburseModuleKeyFromInstance(row)); |
| | | } |
| | | |
| | | /** 审æ¹å®ä¾å
³èç fin_reimbursement.id */ |
| | | export function resolveFinReimbursementIdFromInstance(row) { |
| | | const raw = row?.businessId ?? row?.formPayload?.reimbursementId; |
| | | if (raw == null || raw === "") return undefined; |
| | | const n = Number(raw); |
| | | return Number.isNaN(n) ? raw : n; |
| | | } |
| | | |
| | | /** æåæ¥é详æ
å¹¶æ å°ä¸ºå·®æ
/è´¹ç¨é¡µé¢è¡ï¼ä»¥æ¥å£ reimbursementType 为åï¼ */ |
| | | export async function loadReimburseDetailForInstance(instanceRow, moduleKey) { |
| | | const mk = moduleKey || inferReimburseModuleKeyFromInstance(instanceRow); |
| | | const id = resolveFinReimbursementIdFromInstance(instanceRow); |
| | | if (id == null) { |
| | | throw new Error("missing reimbursement id"); |
| | | } |
| | | const res = await getFinReimbursementDetail(id); |
| | | const raw = unwrapFinReimbursementDetail(res); |
| | | const reimburseRow = mapFinReimbursementDetailRow(raw, mk); |
| | | const reimbursementType = resolveReimbursementType(raw, mk); |
| | | const resolvedMk = |
| | | getModuleKeyByReimbursementType(reimbursementType) || mk; |
| | | return { |
| | | reimburseRow, |
| | | instanceRow, |
| | | moduleKey: resolvedMk, |
| | | reimbursementType, |
| | | }; |
| | | } |
| | | |
| | | export function stashReimburseEditFromApprove(moduleKey, reimbursementId) { |
| | | sessionStorage.setItem( |
| | | REIMBURSE_EDIT_FROM_APPROVE_KEY, |
| | | JSON.stringify({ moduleKey, reimbursementId }) |
| | | ); |
| | | } |
| | | |
| | | export function consumeReimburseEditFromApprove() { |
| | | const raw = sessionStorage.getItem(REIMBURSE_EDIT_FROM_APPROVE_KEY); |
| | | if (!raw) return null; |
| | | sessionStorage.removeItem(REIMBURSE_EDIT_FROM_APPROVE_KEY); |
| | | try { |
| | | return JSON.parse(raw); |
| | | } catch { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** ä»å·²æ³¨åè·¯ç±è§£æå·®æ
/è´¹ç¨æ¥éèå pathï¼é¿å
åæ» path å¯¼è´ 404ï¼ */ |
| | | export function resolveReimburseManageRoutePath(router, moduleKey) { |
| | | if (!router?.getRoutes) return ""; |
| | | const needle = |
| | | moduleKey === APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE |
| | | ? "travel-reimburse" |
| | | : moduleKey === APPROVAL_MODULE_KEYS.COST_REIMBURSE |
| | | ? "cost-reimburse" |
| | | : ""; |
| | | if (!needle) return ""; |
| | | const labelHint = |
| | | moduleKey === APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE ? "å·®æ
" : "è´¹ç¨"; |
| | | const hit = router.getRoutes().find((r) => { |
| | | const path = r.path || ""; |
| | | if (path.includes(needle)) return true; |
| | | const title = r.meta?.title || ""; |
| | | return title.includes(labelHint) && title.includes("æ¥é"); |
| | | }); |
| | | return hit?.path || ""; |
| | | } |
| | | |
| | | export async function navigateToReimburseManageForEdit(router, moduleKey, reimbursementId) { |
| | | stashReimburseEditFromApprove(moduleKey, reimbursementId); |
| | | const path = resolveReimburseManageRoutePath(router, moduleKey); |
| | | if (!path) { |
| | | throw new Error("route not found"); |
| | | } |
| | | await router.push(path); |
| | | } |