fix(stocktake): decouple global stats calculation from list filters and pagination
This commit is contained in:
@ -483,6 +483,7 @@ const listLoading = ref(false)
|
||||
const listData = ref<any[]>([])
|
||||
const listStatusFilter = ref<'all' | 'counted' | 'uncounted'>('all')
|
||||
const allStockItems = ref<any[]>([]) // 全量应盘物资(盘点基数)
|
||||
const allScannedDrafts = ref<any[]>([]) // 全量草稿记录(脱离分页和过滤)
|
||||
const listTotalFiltered = ref(0) // 过滤后的总数
|
||||
|
||||
// ★ 新增: 会话ID
|
||||
@ -503,39 +504,23 @@ const fetchAllStockItems = async () => {
|
||||
// 过滤后的列表数据(直接使用已过滤的 listData)
|
||||
const filteredListData = computed(() => listData.value)
|
||||
|
||||
// 统计信息:从全量应盘物资中计算
|
||||
// 统计信息:从全量数据中计算(脱离视图依赖)
|
||||
const stats = computed(() => {
|
||||
// 已盘点数量:从已扫描的记录中获取
|
||||
const total = allStockItems.value.length
|
||||
if (total === 0) return { total: 0, scanned: 0, varianceItems: 0 }
|
||||
|
||||
// 使用完整的 allScannedDrafts 来计算"已盘"数量,绝对不依赖视图数据
|
||||
const countedItems = new Set()
|
||||
listData.value.forEach(item => {
|
||||
if (item.stock_id && item.source_table) {
|
||||
countedItems.add(`${item.source_table}-${item.stock_id}`)
|
||||
allScannedDrafts.value.forEach((d: any) => {
|
||||
// 只要有实盘记录就算已盘
|
||||
if (d.quantity !== undefined && d.quantity !== null) {
|
||||
countedItems.add(`${d.source_table}-${d.stock_id}`)
|
||||
}
|
||||
})
|
||||
|
||||
// 全量应盘物资中已盘的数量
|
||||
let scanned = 0
|
||||
allStockItems.value.forEach(item => {
|
||||
const key = `${item.source_table}-${item.id}`
|
||||
if (countedItems.has(key)) {
|
||||
scanned++
|
||||
}
|
||||
})
|
||||
|
||||
// 如果 allStockItems 为空,回退到旧的统计逻辑
|
||||
if (allStockItems.value.length === 0) {
|
||||
const total = listData.value.length
|
||||
const scannedCount = listData.value.filter(i => i.quantity > 0).length
|
||||
return {
|
||||
total,
|
||||
scanned: scannedCount,
|
||||
varianceItems: 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
total: allStockItems.value.length,
|
||||
scanned: scanned,
|
||||
total,
|
||||
scanned: countedItems.size,
|
||||
varianceItems: 0
|
||||
}
|
||||
})
|
||||
@ -994,6 +979,9 @@ const fetchInventoryList = async () => {
|
||||
|
||||
const scannedDrafts = res?.items || []
|
||||
|
||||
// 保存全量草稿记录用于全局统计
|
||||
allScannedDrafts.value = scannedDrafts
|
||||
|
||||
// 2. 使用全量应盘物资列表
|
||||
// 对于每个应盘物资,检查是否有对应的盘点记录
|
||||
let mergedData = allStockItems.value.map(item => {
|
||||
|
||||
Reference in New Issue
Block a user