diff --git a/inventory-web/src/views/stock/stocktake/index.vue b/inventory-web/src/views/stock/stocktake/index.vue index b380a97..7a99bcb 100644 --- a/inventory-web/src/views/stock/stocktake/index.vue +++ b/inventory-web/src/views/stock/stocktake/index.vue @@ -593,25 +593,6 @@ const typeToSourceTable = (type: string): string => { } } -async function fetchBorrowedQuantities(items: StockItem[]): Promise { - const payload = items.filter(i => i.source_table && i.stock_id).map(i => ({ - source_table: i.source_table, - stock_id: i.stock_id - })) - if (payload.length === 0) return - try { - const res = await request({ - url: '/v1/inbound/stock/borrowed-quantities', - method: 'post', - data: { items: payload } - }) - // res is map of key->qty - borrowedQuantities.value = { ...borrowedQuantities.value, ...res } - } catch (e) { - console.error('获取借出数量失败', e) - } -} - onMounted(async () => { await checkServerDraft() }) @@ -656,8 +637,6 @@ const doStartNewSession = async () => { // 调用新 API 开始新会话 const res: any = await api.startNewSession() currentSessionId.value = res.session_id || '' - scannedMap.value.clear() - tableData.value = [] // 清空已扫码列表 isSessionActive.value = true // ★ 标记当前阶段为 scanning(扫码中) localStorage.setItem('stocktake_phase', 'scanning') @@ -702,21 +681,13 @@ const resumeSession = async () => { return } + // 恢复已扫描的数据 - 简化为直接激活会话 // 从草稿中获取 session_id const sessionIds = [...new Set(drafts.map((d: any) => d.session_id))] currentSessionId.value = sessionIds[0] - - // 恢复已扫描的数据 - const map = new Map() - drafts.forEach((d: any) => { - if (d.session_id === currentSessionId.value) { - map.set(d.uuid, d.quantity !== undefined ? parseFloat(d.quantity) : 1) - } - }) - scannedMap.value = map - - // 清空本地列表,用户扫码时会实时添加 - tableData.value = [] + + // 直接恢复会话状态 + isSessionActive.value = true // ★ 智能路由:根据本地记忆的阶段决定下一步 const phase = localStorage.getItem('stocktake_phase') @@ -726,7 +697,6 @@ const resumeSession = async () => { ElMessage.info('已恢复差异审核') } else { // 默认打开扫码镜头 - isSessionActive.value = true ElMessage.success('已恢复扫码,继续盘点') } } catch (e) { @@ -806,7 +776,7 @@ const onScanSuccess = async (code: string) => { uuid: foundItem.uuid || foundItem.sku || '', bar_code: foundItem.bar_code || foundItem.barcode || '', qty_stock: stock, - qty_actual: scannedMap.value.get(foundItem.uuid || foundItem.sku) || 0, + qty_actual: 1, scanned: true, uniqueKey: `${type}_${foundItem.id}`, source_table: typeToSourceTable(type), @@ -880,7 +850,7 @@ const handleManualInput = async () => { uuid: foundItem.uuid || foundItem.sku || '', bar_code: foundItem.bar_code || foundItem.barcode || '', qty_stock: stock, - qty_actual: scannedMap.value.get(foundItem.uuid || foundItem.sku) || 0, + qty_actual: 1, scanned: true, uniqueKey: `${type}_${foundItem.id}`, source_table: typeToSourceTable(type), @@ -912,19 +882,7 @@ const handleManualConfirm = () => { const val = inputQty.value === undefined ? 0 : inputQty.value const remark = inputRemark.value - // ★★★ 更新已扫码物料列表 ★★★ - currentItem.value.scanned = true - currentItem.value.qty_actual = val - scannedMap.value.set(currentItem.value.uuid, val) - - // 检查是否已存在于 tableData,如果存在则更新,否则添加 - const existingIndex = tableData.value.findIndex(i => i.uuid === currentItem.value!.uuid) - if (existingIndex >= 0) { - tableData.value[existingIndex] = { ...currentItem.value } - } else { - tableData.value.push({ ...currentItem.value }) - } - + // ★★★ 直接保存到后端,不使用本地缓存 ★★★ showQtyDialog.value = false inputRemark.value = '' ElMessage.success(`已记录实盘: ${val}`) @@ -946,17 +904,9 @@ const syncToBackend = (uuid: string, quantity: number, remark: string) => { } const updateAndSync = async (item: StockItem, quantity: number, remark: string = '') => { + // 直接保存到后端,不使用本地缓存 item.scanned = true item.qty_actual = quantity - scannedMap.value.set(item.uuid, quantity) - - // 更新 tableData - const existingIndex = tableData.value.findIndex(i => i.uuid === item.uuid) - if (existingIndex >= 0) { - tableData.value[existingIndex] = { ...item } - } else { - tableData.value.push({ ...item }) - } } const closeOverlays = () => { @@ -1001,17 +951,17 @@ const exportToExcel = async () => { } const varianceList = computed(() => { - return tableData.value - .filter(i => !i.scanned || (i.scanned && i.qty_actual !== parseFloat(i.qty_stock as any))) + return listData.value + .filter(i => !i.quantity || i.quantity !== i.stock_quantity) .map(i => ({ ...i, // 映射字段名以匹配模板 stock_name: i.name, stock_spec: i.standard, stock_location: i.location || i.warehouse_loc || '', - stock_qty: i.qty_stock, - quantity: i.qty_actual, - diff_qty: i.qty_actual - parseFloat(i.qty_stock as any) + stock_qty: i.stock_quantity, + quantity: i.quantity, + diff_qty: i.quantity - i.stock_quantity })) })