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) {

View File

@ -433,7 +433,7 @@ import { ref, computed, watch } from 'vue'
import { Printer, Search, Plus, Download, List } from '@element-plus/icons-vue'
import { ElMessage, ElTable, ElMessageBox } from 'element-plus'
import { getStockList, printSelectionList } from '@/api/inbound/stock'
import { getBomList, getBomDetail } from '@/api/bom'
import { getBomList, getBomDetail, getBomWithStock } from '@/api/bom'
import { useUserStore } from '@/stores/user'
import { submitOutboundRequest } from '@/api/outbound'
import { getApproversList } from '@/api/auth'
@ -494,7 +494,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}`
}))
}))
})
@ -595,6 +595,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
}
}
// 手动选库存弹窗:加载服务端分页数据 + BOM 用全量数据
const openManualSelect = async () => {
manualDialogVisible.value = true
@ -707,14 +738,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 明细失败')
@ -726,12 +757,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 详情失败')
@ -752,7 +783,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) {

View File

@ -187,7 +187,7 @@
<el-descriptions-item label="审批人">{{ detail.approver_name || '-' }}</el-descriptions-item>
<el-descriptions-item label="审批时间">{{ detail.approved_at || '-' }}</el-descriptions-item>
<el-descriptions-item label="商家链接">
<a v-if="detail.supplier_link" :href="detail.supplier_link" target="_blank" style="color: #409EFF;">
<a v-if="detail.supplier_link" :href="detail.supplier_link" target="_blank" style="color: #409EFF; word-break: break-all;">
{{ detail.supplier_link }}
</a>
<span v-else>-</span>
@ -330,6 +330,7 @@ const statusTagType = (status: number) => {
const getImageUrl = (url: string) => {
if (!url) return ''
if (url.startsWith('http')) return url
if (url.startsWith('/api/v1/common/files/')) return url
return `/api/v1/common/files/${url}`
}