feat(crm): add helper to refresh quote/contract lines after product alias/brand manage.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1e74057003
commit
4628738632
1 file changed
+48
@@ -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<LineAliasBrand & { productId?: string | number }>,
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user