diff --git a/src/views/plan/RealTimeInventory.vue b/src/views/plan/RealTimeInventory.vue index 8272e87..8abeaa0 100644 --- a/src/views/plan/RealTimeInventory.vue +++ b/src/views/plan/RealTimeInventory.vue @@ -3,6 +3,16 @@

实时库存表

+ + + + + { + if (!records.value.length) { + return []; + } + + switch (inventoryFilter.value) { + case 'increase': + // 库存增加:基于差值数据筛选出有正差值的记录 + if (!differenceRecords.value.length) { + return []; + } + const increaseKeys = new Set( + differenceRecords.value + .filter(diff => diff.difference > 0) + .map(diff => `${diff.specification}-${diff.model}-${diff.wire_disc || ''}`) + ); + return records.value.filter(record => { + const key = `${record.specification}-${record.model}-${record.wire_disc || ''}`; + return increaseKeys.has(key); + }); + case 'decrease': + // 库存减少:基于差值数据筛选出有负差值的记录 + if (!differenceRecords.value.length) { + return []; + } + const decreaseKeys = new Set( + differenceRecords.value + .filter(diff => diff.difference < 0) + .map(diff => `${diff.specification}-${diff.model}-${diff.wire_disc || ''}`) + ); + return records.value.filter(record => { + const key = `${record.specification}-${record.model}-${record.wire_disc || ''}`; + return decreaseKeys.has(key); + }); + case 'all': + default: + // 全部:返回所有记录 + return records.value; + } +}; + +// 方法:处理筛选条件变化 +const handleFilterChange = () => { + console.log('筛选条件变化:', inventoryFilter.value); + + // 如果筛选条件不是"全部",确保获取差值数据 + if (inventoryFilter.value !== 'all' && !differenceRecords.value.length) { + console.log('需要获取差值数据以进行筛选'); + fetchDifferenceData(); + } +}; + // WMS对话框相关状态 const wmsDialogVisible = ref(false) const currentWmsModel = ref('') @@ -248,21 +314,25 @@ const dynamicColumns = computed(() => { // 计算属性:表格数据 const tableData = computed(() => { - console.log('计算表格数据, records.value:', records.value); + console.log('计算表格数据, records.value:', records.value, 'inventoryFilter.value:', inventoryFilter.value); - if (!records.value.length) { - console.log('records为空,返回空数组'); + // 使用过滤后的记录 + const filteredRecords = getFilteredRecords(); + console.log('过滤后的记录数量:', filteredRecords.length); + + if (!filteredRecords.length) { + console.log('过滤后的records为空,返回空数组'); return []; } // 获取所有唯一的规格并从小到大排序(可选数值排序) - const specifications = [...new Set(records.value.map(item => item.specification))] + const specifications = [...new Set(filteredRecords.map(item => item.specification))] .sort((a, b) => parseFloat(a) - parseFloat(b)); // 改为数值排序,避免 "0.800" 在前 console.log('获取到的规格列表:', specifications); // 获取所有唯一的 model::wire_disc 组合 - const combinations = [...new Set(records.value.map(item => { + const combinations = [...new Set(filteredRecords.map(item => { if (item.wire_disc && item.wire_disc.trim() !== '') { return `${item.model}::${item.wire_disc}`; } else { @@ -289,7 +359,7 @@ const tableData = computed(() => { } // 查找对应的记录 - const record = records.value.find(r => { + const record = filteredRecords.find(r => { const specMatch = r.specification === specification; const modelMatch = r.model === model; const wireDiscMatch = hasWireDisc