fix(inventory): 修复 BOM 齐套分析时 allStockData 未加载导致可用库存为 0
This commit is contained in:
@ -451,6 +451,31 @@ const getTypeTag = (type: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
// --- 核心逻辑 0:加载全量库存数据(BOM 齐套计算依赖此数据) ---
|
||||
const ensureAllStockLoaded = async () => {
|
||||
if (allStockData.value.length === 0) {
|
||||
try {
|
||||
const res: any = await getAllStock()
|
||||
const rawMaterials = (res.materials || []).map((i: any) => ({ ...i, type: 'material', typeLabel: '采购件' }))
|
||||
const rawSemis = (res.semis || []).map((i: any) => ({ ...i, type: 'semi', typeLabel: '半成品' }))
|
||||
const rawProducts = (res.products || []).map((i: any) => ({ ...i, type: 'product', typeLabel: '成品' }))
|
||||
const list = [...rawMaterials, ...rawSemis, ...rawProducts]
|
||||
allStockData.value = list.map((i: any) => ({
|
||||
...i,
|
||||
name: i.name || i.material_name || i.product_name || '未知名称',
|
||||
standard: i.standard || i.spec_model || '',
|
||||
warehouse_location: i.warehouse_location || i.warehouse_loc || i.full_path || '',
|
||||
uniqueKey: `${i.type}_${i.id}`,
|
||||
available_quantity: parseFloat(i.available_quantity) || 0,
|
||||
availableCount: parseFloat(i.available_quantity) || 0,
|
||||
export_quantity: 1
|
||||
}))
|
||||
} catch (e) {
|
||||
ElMessage.error('加载全量库存数据失败(BOM 功能可能受影响)')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- 核心逻辑 1:手动添加库存 ---
|
||||
|
||||
// 服务端加载库存列表
|
||||
@ -482,32 +507,9 @@ const openManualSelect = async () => {
|
||||
stockPage.value = 1
|
||||
searchKeyword.value = ''
|
||||
await loadStockList()
|
||||
|
||||
// 仅在 BOM 关联查询需要时加载全量(一次性缓存)
|
||||
if (allStockData.value.length === 0) {
|
||||
try {
|
||||
const res: any = await getAllStock()
|
||||
const rawMaterials = (res.materials || []).map((i: any) => ({ ...i, type: 'material', typeLabel: '采购件' }))
|
||||
const rawSemis = (res.semis || []).map((i: any) => ({ ...i, type: 'semi', typeLabel: '半成品' }))
|
||||
const rawProducts = (res.products || []).map((i: any) => ({ ...i, type: 'product', typeLabel: '成品' }))
|
||||
const list = [...rawMaterials, ...rawSemis, ...rawProducts]
|
||||
allStockData.value = list.map((i: any) => ({
|
||||
...i,
|
||||
name: i.name || i.material_name || i.product_name || '未知名称',
|
||||
standard: i.standard || i.spec_model || '',
|
||||
warehouse_location: i.warehouse_location || i.warehouse_loc || i.full_path || '',
|
||||
uniqueKey: `${i.type}_${i.id}`,
|
||||
available_quantity: parseFloat(i.available_quantity) || 0,
|
||||
availableCount: parseFloat(i.available_quantity) || 0,
|
||||
export_quantity: 1
|
||||
}))
|
||||
} catch (e) {
|
||||
ElMessage.error('加载全量库存数据失败(BOM 功能可能受影响)')
|
||||
}
|
||||
} else {
|
||||
await ensureAllStockLoaded()
|
||||
allStockData.value.forEach(item => item.export_quantity = 0)
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索框防抖触发服务端过滤
|
||||
const filterStock = () => {
|
||||
@ -611,6 +613,7 @@ const openBomSelect = async () => {
|
||||
} catch (e) {
|
||||
ElMessage.error('加载 BOM 列表失败')
|
||||
}
|
||||
await ensureAllStockLoaded()
|
||||
}
|
||||
|
||||
// 监听 BOM 选择变化,自动加载明细并计算齐套性
|
||||
|
||||
Reference in New Issue
Block a user