feat(crm): add frontend settlement clause helpers

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-16 15:03:44 +08:00
1 parent e1eeca0001
commit 477719c9a7
1 file changed
+57
@@ -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<string, string> = {
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<string, string> {
if (!raw) return {}
try {
const parsed = JSON.parse(raw)
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
const drafts: Record<string, string> = {}
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)
}