/** * SKU 组合工具函数(管理端商品选择器 / SKU 编辑器共用) */ /** * 组合摘要:'商品A×2;商品B×1',超出 max 项追加 ' 等N项'。 * items 为空/缺失时返回空串。 */ export function formatComboSummary(items, max = 3) { if (!items || !items.length) return '' const shown = items.slice(0, max).map(it => { const name = it.childProductName || it.name || ('商品#' + (it.childProductId || it.productId)) const qty = it.quantity == null ? 1 : it.quantity return name + '×' + qty }) return shown.join(';') + (items.length > max ? ' 等' + items.length + '项' : '') } /** * 组合保存载荷:归一化为 [{ childProductId, childSkuId, quantity }]。 * childSkuId 为空时为 null(按互品扣减)。 */ export function normalizeComboPayload(items) { return (items || []).map(it => ({ childProductId: it.childProductId || it.id, childSkuId: it.childSkuId || null, quantity: it.quantity == null ? 1 : it.quantity })) }