diff --git a/src/views/express/returnUnpackwork/index.vue b/src/views/express/returnUnpackwork/index.vue index ab393fe8..84311081 100644 --- a/src/views/express/returnUnpackwork/index.vue +++ b/src/views/express/returnUnpackwork/index.vue @@ -37,15 +37,28 @@ - +
+ + +
(null) // 左侧快速添加 const detailBarcode = ref('') const detailBarcodeRef = ref(null) +/** 本次扫码录入数量(一次性使用,扫描后重置为 1) */ +const scanQty = ref(1) const quickAddLoading = ref(false) const quickAddPickerVisible = ref(false) const quickAddKeyword = ref('') @@ -1035,55 +1050,68 @@ async function findSameStockDetail(stockId: number, productStatus?: string): Pro return null } +/** 扫码数量校验:仅接受数字,取整并限制在 1~999 */ +function normalizeScanQty(): number { + const n = Number(scanQty.value) + if (!Number.isFinite(n) || n < 1) return 1 + return Math.min(999, Math.floor(n)) +} + async function quickAddDetail(item: any) { const unpackId = createResult.value?.id if (!unpackId) return + // 数量一次性使用:本次扫码使用当前数量,结束后重置为 1 + const qty = normalizeScanQty() const scannedBarcode = String(detailBarcode.value ?? '').trim() // 兼容商品搜索行(item_id)与商品选择弹窗返回项(id)两种字段 const rawStockId = item?.item_id ?? item?.id const stockId = rawStockId != null ? Number(rawStockId) : null - // 相同商品且相同产品状态才累加数量 - const existing = stockId != null ? await findSameStockDetail(stockId, defaultProductStatus.value) : null - if (existing) { - const res: any = await returnUnpackUpdateDetail({ + try { + // 相同商品且相同产品状态才累加数量 + const existing = stockId != null ? await findSameStockDetail(stockId, defaultProductStatus.value) : null + if (existing) { + const res: any = await returnUnpackUpdateDetail({ + id: unpackId, + detail_id: existing.id, + quantity: Number(existing.quantity || 0) + qty, + }) + if (isOk(res)) { + detailBarcode.value = '' + if (scannedBarcode) lastScannedBarcode.value = scannedBarcode + void pushOsdText() + ElMessage.success(`相同商品数量已累加 ${qty}`) + loadDetailList() + focusTarget.value = 'barcode' + nextTick(() => { + detailBarcodeRef.value?.focus() + }) + } else { + ElMessage.error(res?.message || '明细累加失败') + } + return + } + const res: any = await returnUnpackAddDetail({ id: unpackId, - detail_id: existing.id, - quantity: Number(existing.quantity || 0) + 1, + stock_id: stockId, + barcode: String(detailBarcode.value ?? '').trim() || undefined, + quantity: qty, + product_status: defaultProductStatus.value, }) if (isOk(res)) { detailBarcode.value = '' if (scannedBarcode) lastScannedBarcode.value = scannedBarcode void pushOsdText() - ElMessage.success('相同商品数量已累加') + ElMessage.success(stockId == null ? '未找到匹配商品,已按未识别商品登记' : '明细添加成功') loadDetailList() focusTarget.value = 'barcode' nextTick(() => { detailBarcodeRef.value?.focus() }) } else { - ElMessage.error(res?.message || '明细累加失败') + ElMessage.error(res?.message || '明细添加失败') } - return - } - const res: any = await returnUnpackAddDetail({ - id: unpackId, - stock_id: stockId, - barcode: String(detailBarcode.value ?? '').trim() || undefined, - quantity: 1, - product_status: defaultProductStatus.value, - }) - if (isOk(res)) { - detailBarcode.value = '' - if (scannedBarcode) lastScannedBarcode.value = scannedBarcode - void pushOsdText() - ElMessage.success(stockId == null ? '未找到匹配商品,已按未识别商品登记' : '明细添加成功') - loadDetailList() - focusTarget.value = 'barcode' - nextTick(() => { - detailBarcodeRef.value?.focus() - }) - } else { - ElMessage.error(res?.message || '明细添加失败') + } finally { + scanQty.value = 1 } } @@ -2072,6 +2100,22 @@ async function confirmRemoveDetail() { width: 100%; } +.barcode-row { + display: flex; + gap: 8px; + width: 100%; + align-items: center; + + .el-input { + flex: 1; + } +} + +.barcode-qty-input { + width: 110px; + flex-shrink: 0; +} + .right-area { flex: 1; display: flex;