|
|
|
|
@ -3,6 +3,16 @@
|
|
|
|
|
<div class="table-header">
|
|
|
|
|
<h3>实时库存表</h3>
|
|
|
|
|
<div class="table-actions">
|
|
|
|
|
<el-select
|
|
|
|
|
v-model="inventoryFilter"
|
|
|
|
|
placeholder="选择筛选条件"
|
|
|
|
|
style="width: 120px; margin-right: 15px;"
|
|
|
|
|
@change="handleFilterChange"
|
|
|
|
|
>
|
|
|
|
|
<el-option label="全部" value="all" />
|
|
|
|
|
<el-option label="库存增加" value="increase" />
|
|
|
|
|
<el-option label="库存减少" value="decrease" />
|
|
|
|
|
</el-select>
|
|
|
|
|
<el-switch
|
|
|
|
|
v-model="showDifference"
|
|
|
|
|
active-text="显示库存变化"
|
|
|
|
|
@ -199,6 +209,62 @@ const activeCells = ref(new Set()) // 存储当前激活的单元格键值
|
|
|
|
|
let clickTimeoutId = null; // 单击事件延时器
|
|
|
|
|
const DBL_CLICK_DELAY = 250; // 双击延时(毫秒)
|
|
|
|
|
|
|
|
|
|
// 库存筛选相关
|
|
|
|
|
const inventoryFilter = ref('all'); // 筛选类型:all-全部,increase-库存增加,decrease-库存减少
|
|
|
|
|
|
|
|
|
|
// 方法:根据筛选条件获取过滤后的记录
|
|
|
|
|
const getFilteredRecords = () => {
|
|
|
|
|
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
|
|
|
|
|
|