Просмотр исходного кода

feat(crm): add frontend settlement clause helpers

Co-authored-by: Cursor <cursoragent@cursor.com>
zlwu 3 месяцев назад
Родитель
Сommit
477719c9a7
1 измененных файлов с 57 добавлено и 0 удалено
  1. 57 0
      web-admin/src/views/crm/contract/settlementClause.ts

+ 57 - 0
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<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)
+}