Sfoglia il codice sorgente

feat(web-admin): add helpers to filter plan products by contract

Co-authored-by: Cursor <cursoragent@cursor.com>
zlwu 2 mesi fa
parent
commit
e9fd94de03
1 ha cambiato i file con 26 aggiunte e 0 eliminazioni
  1. 26 0
      web-admin/src/utils/pl-plan-contract-product.ts

+ 26 - 0
web-admin/src/utils/pl-plan-contract-product.ts

@@ -0,0 +1,26 @@
+/** 从合同明细行收集 CRM productId */
+export function collectContractProductIds(
+  products?: Array<{ productId?: string | null }> | null
+): string[] {
+  const ids: string[] = []
+  const seen = new Set<string>()
+  for (const row of products || []) {
+    const id = String(row?.productId || '').trim()
+    if (!id || seen.has(id)) continue
+    seen.add(id)
+    ids.push(id)
+  }
+  return ids
+}
+
+/** 保留 productId 落在 allowed 内的装货行;allowed 为空则全部移除(换合同且新合同无产品) */
+export function filterProductsByAllowedProductIds<T extends { productId?: string | null }>(
+  products: T[],
+  allowedProductIds: string[]
+): T[] {
+  const allowed = new Set(
+    (allowedProductIds || []).map((id) => String(id).trim()).filter(Boolean)
+  )
+  if (!allowed.size) return []
+  return (products || []).filter((row) => allowed.has(String(row.productId || '').trim()))
+}