import dayjs from "dayjs"; export const EXPENSE_CATEGORY_OPTIONS = [ { label: "差旅", value: "travel" }, { label: "办公采购", value: "office_procurement" }, { label: "业务招待", value: "business_entertainment" }, { label: "交通费", value: "transport" }, { label: "通讯费", value: "communication" }, { label: "其他", value: "other" }, ]; export const EXPENSE_SUBJECT_OPTIONS = [ { label: "交通费", value: "transport" }, { label: "住宿费", value: "hotel" }, { label: "餐饮费", value: "meal" }, { label: "办公用品", value: "office_supply" }, { label: "招待费", value: "entertainment" }, { label: "通讯费", value: "phone" }, { label: "其他", value: "other" }, ]; export const CATEGORY_TEMPLATES = { travel: { label: "差旅费用", reason: "因公出差产生的交通、住宿、餐饮等费用报销。", details: [ { expenseSubject: "transport", description: "往返交通费" }, { expenseSubject: "hotel", description: "住宿费" }, { expenseSubject: "meal", description: "出差餐饮" }, ], }, office_procurement: { label: "办公采购", reason: "部门日常办公用品、耗材采购报销。", details: [ { expenseSubject: "office_supply", description: "办公用品采购" }, { expenseSubject: "office_supply", description: "打印耗材" }, ], }, business_entertainment: { label: "业务招待", reason: "客户接待、商务宴请等费用报销。", details: [ { expenseSubject: "entertainment", description: "客户接待餐费" }, { expenseSubject: "entertainment", description: "商务礼品" }, ], }, transport: { label: "交通费", reason: "市内通勤、打车、停车等交通费用报销。", details: [{ expenseSubject: "transport", description: "市内交通" }], }, communication: { label: "通讯费", reason: "因公通讯、流量、话费补贴报销。", details: [{ expenseSubject: "phone", description: "话费/流量" }], }, other: { label: "其他费用", reason: "其他因公支出费用报销。", details: [{ expenseSubject: "other", description: "其他费用" }], }, }; export function expenseSubjectLabel(v) { return EXPENSE_SUBJECT_OPTIONS.find(x => x.value === v)?.label || "—"; } export function expenseCategoryLabel(v) { return EXPENSE_CATEGORY_OPTIONS.find(x => x.value === v)?.label || v || "—"; } export function expenseTypeToCategory(expenseType) { const t = (expenseType || "").trim(); const hit = EXPENSE_CATEGORY_OPTIONS.find(x => x.label === t || x.value === t); return hit?.value || "other"; } export function createEmptyExpenseDetail() { return { id: `ed_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`, invoiceDate: "", expenseSubject: "", amount: "", description: "", }; } export function createEmptyCostForm() { return { reimbursementId: undefined, applicantId: "", employeeNo: "", employeeName: "", expenseCategory: "other", reimburseReason: "", applyAmount: "", payee: "", payeeAccount: "", bankBranch: "", expenseDetails: [], attachmentList: [], approvalFlowNodes: [{ approverId: "", approverName: "", nodeOrder: 1, signMode: "countersign" }], deptId: "", deptName: "", }; } export function applyCategoryTemplate(form, category) { const tpl = CATEGORY_TEMPLATES[category]; if (!tpl) return; form.expenseCategory = category; if (!form.reimburseReason?.trim()) form.reimburseReason = tpl.reason; form.expenseDetails = (tpl.details || []).map(d => ({ ...createEmptyExpenseDetail(), expenseSubject: d.expenseSubject, description: d.description, invoiceDate: dayjs().format("YYYY-MM-DD"), })); }