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

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-30 10:57:09 +08:00
1 parent 1959394223
commit e9fd94de03
1 file changed
+26
@@ -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()))
}