From 477719c9a7ecd86609d0b211a174b0f80133918d Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Sun, 16 Aug 2026 15:03:44 +0800 Subject: [PATCH] feat(crm): add frontend settlement clause helpers Co-authored-by: Cursor --- .../views/crm/contract/settlementClause.ts | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 web-admin/src/views/crm/contract/settlementClause.ts diff --git a/web-admin/src/views/crm/contract/settlementClause.ts b/web-admin/src/views/crm/contract/settlementClause.ts new file mode 100644 index 000000000..ee13e5971 --- /dev/null +++ b/web-admin/src/views/crm/contract/settlementClause.ts @@ -0,0 +1,57 @@ +/** 与后端 app.services.crm_settlement_clause 保持一致 */ + +export const SETTLEMENT_ADVANCE = 'advance_payment' +export const SETTLEMENT_ARRIVE = 'arrive_payment' + +export const SETTLEMENT_CLAUSE_LABELS: Record = { + volume_settlement: '按量结算', + monthly_settlement: '月结', + quarterly_settlement: '季结', + other_settlement: '其他' +} + +const ADVANCE_CLAUSE = + '款到发货。需方付款后安排发货,需方收到货物后,供方开具13%增值税专用发票。' +const ARRIVE_CLAUSE = + '货到付款,需方收到供方货物后,供方开具13%增值税专用发票,无异议后,以现汇方式月结。' + +export function defaultSettlementClause( + settlementMethod?: string | null, + labelResolver?: (method: string) => string | undefined +): string { + const method = (settlementMethod || '').trim() || SETTLEMENT_ARRIVE + if (method === SETTLEMENT_ADVANCE) return ADVANCE_CLAUSE + if (method in SETTLEMENT_CLAUSE_LABELS) { + const label = + (labelResolver && labelResolver(method)) || SETTLEMENT_CLAUSE_LABELS[method] + return `请根据双方约定填写结算方式:${label}。供方开具13%增值税专用发票,无异议后,以现汇方式月结。` + } + return ARRIVE_CLAUSE +} + +export function parseSettlementClauseDrafts(raw?: string | null): Record { + if (!raw) return {} + try { + const parsed = JSON.parse(raw) + if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {} + const drafts: Record = {} + Object.entries(parsed).forEach(([key, value]) => { + if (typeof value === 'string' && value.trim()) { + drafts[key] = value.trim() + } + }) + return drafts + } catch { + return {} + } +} + +export function resolveSettlementClauseContent(options: { + settlementMethod?: string | null + settlementClauseDrafts?: string | null + labelResolver?: (method: string) => string | undefined +}): string { + const method = (options.settlementMethod || '').trim() || SETTLEMENT_ARRIVE + const drafts = parseSettlementClauseDrafts(options.settlementClauseDrafts) + return drafts[method] || defaultSettlementClause(method, options.labelResolver) +}