yyb
10 天以前 eb322fd6b88273f1dada1f850f4473d5f054dd66
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { matchBusinessTypeValue } from "./approvalTemplateType.js";
import {
  APPROVAL_MODULE_KEYS,
  getApprovalModuleConfig,
} from "./approvalModuleRegistry.js";
import { fetchFinReimbursementListItemDetail } from "./finReimbursementMappers.js";
 
export const REIMBURSE_EDIT_FROM_APPROVE_KEY = "oa_reimburse_edit_from_approve";
export const FIN_REIMBURSE_FORM_ACTION_KEY = "oa_fin_reimburse_form_action";
 
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));
}
 
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;
}
 
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 reimburseRow = await fetchFinReimbursementListItemDetail(
    { reimbursementId: id },
    mk
  );
  return {
    reimburseRow,
    instanceRow,
    moduleKey: reimburseRow.moduleKey || mk,
    reimbursementType: reimburseRow.reimbursementType,
  };
}
 
export function stashReimburseEditFromApprove(moduleKey, reimbursementId) {
  uni.setStorageSync(
    REIMBURSE_EDIT_FROM_APPROVE_KEY,
    JSON.stringify({ moduleKey, reimbursementId })
  );
}
 
export function consumeReimburseEditFromApprove() {
  const raw = uni.getStorageSync(REIMBURSE_EDIT_FROM_APPROVE_KEY);
  if (!raw) return null;
  uni.removeStorageSync(REIMBURSE_EDIT_FROM_APPROVE_KEY);
  try {
    return typeof raw === "string" ? JSON.parse(raw) : raw;
  } catch {
    return null;
  }
}
 
export function stashFinReimburseFormAction(payload) {
  uni.setStorageSync(FIN_REIMBURSE_FORM_ACTION_KEY, JSON.stringify(payload));
}
 
export function consumeFinReimburseFormAction() {
  const raw = uni.getStorageSync(FIN_REIMBURSE_FORM_ACTION_KEY);
  if (!raw) return null;
  uni.removeStorageSync(FIN_REIMBURSE_FORM_ACTION_KEY);
  try {
    return typeof raw === "string" ? JSON.parse(raw) : raw;
  } catch {
    return null;
  }
}