diff --git a/web-admin/src/utils/crm-product-brand.ts b/web-admin/src/utils/crm-product-brand.ts index 26ed4ec25..8acb1e7d4 100644 --- a/web-admin/src/utils/crm-product-brand.ts +++ b/web-admin/src/utils/crm-product-brand.ts @@ -131,6 +131,7 @@ export function applyBrandSelectChange( } type LineAliasBrand = { + productId?: string | number productName?: string standardProductName?: string aliasName?: string @@ -198,3 +199,50 @@ export function applyAliasDisplayMeta( aliasOptions ) } + +/** 主数据别名/品牌维护成功后:同步同 productId 各行的 options,并校正已选值 */ +export function applyManagedProductMetaToLines( + lines: Array, + productId: string, + product: { + productName?: string + brands?: Array<{ id?: string; brandName?: string; status?: string }> + aliases?: Array<{ aliasName?: string }> + } +) { + const pid = String(productId || '') + if (!pid) return + const meta = initLineBrandMetaFromProduct(product) + for (const line of lines || []) { + if (String(line.productId || '') !== pid) continue + + line.standardProductName = meta.standardProductName + line.aliasOptions = meta.aliasOptions + const alias = String(line.aliasName || '').trim() + if (alias && !meta.aliasOptions.includes(alias)) { + line.aliasName = undefined + } + + line.brandOptions = meta.brandOptions + if (meta.brandOptions.length) { + if (line.brandMode === 'required' && line.brandId) { + const still = meta.brandOptions.some((o) => o.id === String(line.brandId)) + if (still) { + applyBrandSelectChange(line, line.brandId, meta.brandOptions) + } else { + line.brandMode = 'any' + line.brandId = undefined + line.brandName = undefined + } + } else { + line.brandMode = 'any' + line.brandId = undefined + line.brandName = undefined + } + } else { + line.brandMode = undefined + line.brandId = undefined + line.brandName = undefined + } + } +}