This commit is contained in:
dxc
2026-06-25 15:21:43 +08:00
parent 8ba1ff37f0
commit c1092407ad
7 changed files with 128 additions and 43 deletions

View File

@ -437,7 +437,7 @@ import { getStockList, printSelectionList } from '@/api/inbound/stock'
import { useUserStore } from '@/stores/user'
import { submitBorrowRequest } from '@/api/transaction'
import { getApproversList } from '@/api/auth'
import { getBomList, getBomDetail } from '@/api/bom'
import { getBomList, getBomDetail, getBomWithStock } from '@/api/bom'
const userStore = useUserStore()
@ -496,7 +496,7 @@ const treeData = computed(() => {
disabled: true, // 禁止选中分类本身
children: (group.items || []).map((b: any) => ({
value: b.bom_no,
label: `${b.parent_name} - ${b.version}`
label: `${b.bom_no} - ${b.parent_name} - ${b.version}`
}))
}))
})
@ -592,6 +592,37 @@ const loadStockList = async () => {
}
}
// BOM 匹配用:全量加载库存(不分页),确保所有物料都能匹配到
const loadAllStockForBom = async () => {
stockLoading.value = true
try {
let allItems: any[] = []
let page = 1
const pageSize = 200
while (true) {
const res: any = await getStockList({
page,
pageSize,
is_aggregated: true
})
const list = (res.data?.list || []).map((item: any) => ({
...item,
uniqueKey: `${item.type}_${item.id}`,
warehouse_location: item.warehouse_location || item.warehouse_loc || item.full_path || ''
}))
allItems = allItems.concat(list)
if (list.length < pageSize) break
page++
}
stockList.value = allItems
stockTotal.value = allItems.length
} catch (e) {
ElMessage.error('加载库存列表失败')
} finally {
stockLoading.value = false
}
}
const openManualSelect = async () => {
manualDialogVisible.value = true
stockPage.value = 1
@ -674,14 +705,14 @@ const openBomSelect = async () => {
}
}
// 监听 BOM 选择变化,自动加载明细并计算齐套性
// 监听 BOM 选择变化,自动加载明细(含库存)并计算齐套性
watch(selectedBomNo, async (newBomNo) => {
if (!newBomNo) {
currentBomDetail.value = []
return
}
try {
const detailRes: any = await getBomDetail(newBomNo)
const detailRes: any = await getBomWithStock(newBomNo)
currentBomDetail.value = detailRes.data?.children || []
} catch (e) {
ElMessage.error('加载 BOM 明细失败')
@ -693,12 +724,12 @@ const confirmBomAdd = async () => {
if (!selectedBomNo.value) return ElMessage.warning('请选择 BOM')
if (stockList.value.length === 0) {
await loadStockList()
await loadAllStockForBom()
}
if (currentBomDetail.value.length === 0) {
try {
const detailRes: any = await getBomDetail(selectedBomNo.value)
const detailRes: any = await getBomWithStock(selectedBomNo.value)
currentBomDetail.value = detailRes.data?.children || []
} catch (e) {
ElMessage.error('获取 BOM 详情失败')
@ -719,7 +750,7 @@ const confirmBomAdd = async () => {
)
if (stockCandidate) {
const availableQty = stockCandidate.availableCount || 0
const availableQty = stockCandidate.available_quantity || 0
const actualAddQty = Math.min(needQty, availableQty)
if (actualAddQty > 0) {