新增按套餐版本查询销售附加费关联,优化产品附加费展示逻辑

This commit is contained in:
wuweihua
2026-11-20 14:48:08 +08:00
parent a98c8a6c42
commit 8c3e7f8616
6 changed files with 131 additions and 34 deletions
@@ -295,26 +295,19 @@ function normalizeProducts(list) {
productCode: p.productCode || p.code,
productName: p.productName || p.name || p.productCode || p.code,
taxMode: p.taxMode,
surcharges: []
surcharges: Array.isArray(p.surcharges) ? p.surcharges : []
}))
}
/** 按产品汇总版本明细上的附加费(scId 去重) */
function attachProductSurcharges(productList, detailRows) {
function mergeProductSurcharges(productList, optionProducts) {
const byCode = new Map()
for (const d of detailRows || []) {
if (!d?.productCode) continue
if (!byCode.has(d.productCode)) byCode.set(d.productCode, new Map())
const map = byCode.get(d.productCode)
for (const s of d.surcharges || []) {
if (!s || s.scId == null) continue
const key = String(s.scId)
if (!map.has(key)) map.set(key, s)
}
for (const p of optionProducts || []) {
if (!p?.productCode) continue
byCode.set(p.productCode, p.surcharges || [])
}
return (productList || []).map(p => ({
...p,
surcharges: [...(byCode.get(p.productCode)?.values() || [])]
surcharges: byCode.get(p.productCode) || p.surcharges || []
}))
}
@@ -327,14 +320,15 @@ async function loadProducts() {
}
loading.value = true
try {
// 轻量:options 带产品+附加费,不再拉整版 byVersion 明细
const res = await api.listSetDetailOptions(psvId)
const optList = normalizeProducts((res.data || {}).products || [])
let list = normalizeProducts(v.products)
if (!list.length) {
const res = await api.listSetDetailOptions(psvId)
const data = res.data || {}
list = normalizeProducts(data.products || [])
products.value = optList
} else {
products.value = mergeProductSurcharges(list, optList)
}
const detailRes = await api.listSetDetailByVersion(psvId)
products.value = attachProductSurcharges(list, detailRes.data || [])
} catch (e) {
products.value = normalizeProducts(v.products)
} finally {