feat(RealTimeInventory): 添加库存变化显示切换功能

添加开关控件用于切换显示实际库存或库存变化,包括差值数据获取、样式处理和格式化显示
master
huangjinysf 2 months ago
parent ab5bb998d6
commit 945a39964a

@ -3,6 +3,13 @@
<div class="table-header"> <div class="table-header">
<h3>实时库存表</h3> <h3>实时库存表</h3>
<div class="table-actions"> <div class="table-actions">
<el-switch
v-model="showDifference"
active-text="显示库存变化"
inactive-text="显示实际库存"
style="margin-right: 15px;"
@change="handleToggleChange"
/>
<el-button @click="refreshData" type="primary" size="small">刷新数据</el-button> <el-button @click="refreshData" type="primary" size="small">刷新数据</el-button>
</div> </div>
</div> </div>
@ -36,10 +43,27 @@
:key="column.key" :key="column.key"
:label="column.label" :label="column.label"
:prop="column.prop" :prop="column.prop"
min-width="100" min-width="120"
> >
<template #default="scope"> <template #default="scope">
{{ scope.row[column.prop] || '-' }} <div class="cell-content">
<span v-if="!showDifference">
{{ scope.row[column.prop] || '-' }}
</span>
<span v-else>
{{ scope.row[column.prop] || '-' }}
<span
v-if="scope.row[column.prop + '_difference'] !== undefined && scope.row[column.prop + '_difference'] !== null"
:class="getDifferenceClass(scope.row[column.prop + '_difference'])"
style="margin-left: 5px; font-size: 12px;"
>
({{ formatDifference(scope.row[column.prop + '_difference']) }})
</span>
<span v-else class="no-data" style="margin-left: 5px; font-size: 12px;">
(-)
</span>
</span>
</div>
</template> </template>
<template #header> <template #header>
<div v-html="column.label"></div> <!-- 使 v-html HTML <br> 生效 --> <div v-html="column.label"></div> <!-- 使 v-html HTML <br> 生效 -->
@ -87,6 +111,7 @@ import WmsTable from '@/components/WmsTable/index.vue'
// //
const loading = ref(false) const loading = ref(false)
const records = ref([]) const records = ref([])
const differenceRecords = ref([])
// WMS // WMS
const wmsDialogVisible = ref(false) const wmsDialogVisible = ref(false)
@ -94,6 +119,9 @@ const currentWmsModel = ref('')
const currentWmsSpecification = ref('') const currentWmsSpecification = ref('')
const wmsTableRef = ref(null) const wmsTableRef = ref(null)
//
const showDifference = ref(false)
// //
const dynamicColumns = computed(() => { const dynamicColumns = computed(() => {
if (!records.value.length) return []; if (!records.value.length) return [];
@ -172,8 +200,24 @@ const tableData = computed(() => {
return specMatch && modelMatch && wireDiscMatch; return specMatch && modelMatch && wireDiscMatch;
}); });
//
row[comb] = record ? record.total_number : null; row[comb] = record ? record.total_number : null;
if (record) total += record.total_number; if (record) total += record.total_number;
//
if (showDifference.value && differenceRecords.value.length > 0) {
const differenceRecord = differenceRecords.value.find(r => {
const specMatch = r.specification === specification;
const modelMatch = r.model === model;
const wireDiscMatch = hasWireDisc
? (r.wire_disc === wire_disc)
: (!r.wire_disc || r.wire_disc.trim() === '');
return specMatch && modelMatch && wireDiscMatch;
});
//
row[comb + '_difference'] = differenceRecord ? differenceRecord.difference : null;
}
}); });
row.total = total; row.total = total;
@ -207,9 +251,62 @@ const fetchData = async () => {
} }
}; };
//
const fetchDifferenceData = async () => {
const today = new Date().toISOString().split('T')[0]; // YYYY-MM-DD
const targetDate = today;
try {
console.log('正在请求差值API:', `/api/wms/difference/type1-records?target_date=${targetDate}`);
const response = await fetch(`${API_CONFIG.BASE_URL}/api/wms/difference/type1-records?target_date=${targetDate}`);
const result = await response.json();
console.log('差值API返回结果:', result);
if (result.code === 200 && result.data && result.data.records) {
differenceRecords.value = result.data.records;
console.log('设置差值records:', differenceRecords.value);
} else {
console.error('获取差值数据失败:', result.message);
differenceRecords.value = [];
}
} catch (error) {
console.error('差值API调用失败:', error);
differenceRecords.value = [];
}
};
// //
const refreshData = () => { const refreshData = () => {
fetchData(); fetchData();
if (showDifference.value) {
fetchDifferenceData();
}
};
// toggle
const handleToggleChange = (value) => {
if (value) {
//
fetchDifferenceData();
} else {
//
differenceRecords.value = [];
}
};
//
const formatDifference = (difference) => {
if (difference === 0) return '0';
if (difference > 0) return `+${difference}`;
return `${difference}`;
};
//
const getDifferenceClass = (difference) => {
if (difference > 0) return 'difference-positive'; // 绿
if (difference < 0) return 'difference-negative'; //
return 'difference-zero'; //
}; };
// //
@ -308,6 +405,30 @@ onMounted(() => {
white-space: nowrap; white-space: nowrap;
} }
/* 库存变化样式 */
.cell-content {
text-align: center;
}
.difference-positive {
color: #67c23a;
font-weight: bold;
}
.difference-negative {
color: #f56c6c;
font-weight: bold;
}
.difference-zero {
color: #606266;
font-weight: normal;
}
.no-data {
color: #c0c4cc;
}
/* Webkit 浏览器的滚动条样式 */ /* Webkit 浏览器的滚动条样式 */
.table-wrapper::-webkit-scrollbar { .table-wrapper::-webkit-scrollbar {
height: 10px; height: 10px;

Loading…
Cancel
Save