import { expenseSubjectLabel as costSubjectLabel } from "./costReimburseUtils.js";
|
import { expenseSubjectLabel as travelSubjectLabel } from "./travelReimburseUtils.js";
|
|
/** 费用科目展示(兼容 value / 中文 label / API expenseCategory) */
|
export function resolveExpenseSubjectLabel(v, { isTravel = true, subjectOptions = [] } = {}) {
|
if (!v) return "";
|
const labelFn = isTravel ? travelSubjectLabel : costSubjectLabel;
|
const t = labelFn(v);
|
if (t && t !== "—") return t;
|
const hit = subjectOptions.find(x => x.value === v || x.label === v);
|
return hit?.label || String(v);
|
}
|
|
export function formatDetailAmount(amount) {
|
if (amount === "" || amount == null) return null;
|
const n = Number(amount);
|
if (Number.isNaN(n)) return String(amount);
|
return `${n} 元`;
|
}
|
|
/** 列表行摘要 */
|
export function buildExpenseDetailSummary(row, opts = {}) {
|
const subject = resolveExpenseSubjectLabel(row?.expenseSubject, opts) || "未选科目";
|
const amount = formatDetailAmount(row?.amount);
|
const date = row?.invoiceDate || "";
|
const desc = (row?.description || "").trim();
|
const parts = [];
|
if (date) parts.push(date);
|
if (desc) parts.push(desc);
|
const sub = parts.length ? parts.join(" · ") : "点击详情完善信息";
|
const incomplete = !row?.invoiceDate || !row?.expenseSubject || row?.amount === "" || row?.amount == null;
|
return { subject, amount: amount || "金额未填", sub, incomplete };
|
}
|