From 66529cd5f2e58aa3852042ef1f54fb0b34c2345a Mon Sep 17 00:00:00 2001 From: zm2000 <18386612143@163.com> Date: Mon, 19 Oct 2026 18:00:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=AE=A2=E5=8D=95=E5=A4=8D=E6=A0=B8):=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=A4=8D=E6=A0=B8=E5=8F=91=E8=B4=A7=E9=93=BE?= =?UTF-8?q?=E8=B7=AF=E5=AF=B9=E9=BD=90=20WMS=5FPDA=20+=20=E7=9C=9F?= =?UTF-8?q?=E6=9C=BA=E5=85=BC=E5=AE=B9=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 发货链路:新增打印失败弹窗(发货前打印确认,打印成功才发货、可重试);团购改「打印→包材绑定→并发复核」;散单改「先复核后称重」;D 前缀波次(单品单件)与免验订单(need_recheck=N)自动推进 - 真机兼容:input 补 line-height 修复文字顶部被白底裁剪;弹窗/工具栏 flex gap 改 margin 兜底(老 WebView 不支持 gap);打印台选择器改自绘下拉,SVG 箭头改纯 CSS 箭头 - 扫码识别:plus.key 升级 Android 原生 keycode(keydown/keyup 双监听、区分扫码枪与软键盘手动输入、最短码长守卫);关闭真机隐藏 input 修复软键盘弹出又隐藏 - 商品明细:多条码完整显示与匹配;复核扫描数量按步长累计并防超总数 - 稳定性:doConfirmRecheck 弱网防重入;散单复核后称重取消可补录;扫描查询异常本地诊断(diagAnomaly) --- src/pages/order/index.vue | 1188 +++++++++++++++++++++++++++++++------ 1 file changed, 1013 insertions(+), 175 deletions(-) diff --git a/src/pages/order/index.vue b/src/pages/order/index.vue index 6f95a3f..31cc2b5 100644 --- a/src/pages/order/index.vue +++ b/src/pages/order/index.vue @@ -103,25 +103,31 @@ - + {{ selectedPrinter || '选择打印台' }} - - - + - + + + + {{ name }} + 暂无打印台 + + + + + 拣货人:{{ pickerName || '-' }} 货主:{{ storeRemark || '-' }} 波次:{{ selectedWaveNo || '-' }} @@ -175,7 +181,9 @@ - - {{ order.barcode }} + + {{ order.barcode }}{{ order.barcodeExtra }} + {{ order.spec }} {{ order.packingRequirements }} @@ -443,6 +451,27 @@ + + + + + 打印未完成 + + + + {{ printFailBodyText }} + + {{ printFailMessage }} + + + + + + + + + + @@ -546,7 +575,7 @@ import { unlockWavePlatformPrintDataByGroup, sendPrint, } from '@/api/order' -import { diagDrop, diagNote } from '@/core/scan-diag' +import { diagAnomaly, diagDrop, diagNote } from '@/core/scan-diag' // 扫码枪识别参数 // 无回车结束符时:停止输入超过该毫秒数视为一次完整扫码,自动提交 @@ -556,6 +585,29 @@ const SCAN_MIN_LENGTH = 2 // 手动输入识别:相邻按键间隔超过该毫秒数视为手动输入,不自动提交,需按回车后才查询 // 扫码枪连续按键间隔通常 <30ms,手动键盘输入间隔通常 >100ms const SCAN_BURST_MAX_GAP = 100 +// plus.key 自动提交的最短码长:运单/商品条码均 >= 8 位,短于此视为误触/单字符手动输入, +// 不自动提交(防软键盘单字符停顿触发查询),回车查询不受影响 +const PLUS_SCAN_MIN_LENGTH = 4 + +// Android KeyEvent 符号键映射(KEYCODE_* → 字符)。 +// 重要:这些 keyCode 与 ASCII 字母/数字区间重叠,必须优先于 ASCII 分支判断, +// 否则 KEYCODE_EQUALS=70 会被 ASCII 的 [65..90] 分支误读为 'F'。 +const ANDROID_PUNCT_MAP = { + 55: ',', // KEYCODE_COMMA + 56: '.', // KEYCODE_PERIOD + 62: ' ', // KEYCODE_SPACE + 68: '`', // KEYCODE_GRAVE + 69: '-', // KEYCODE_MINUS + 70: '=', // KEYCODE_EQUALS + 71: '[', // KEYCODE_LEFT_BRACKET + 72: ']', // KEYCODE_RIGHT_BRACKET + 73: '\\', // KEYCODE_BACKSLASH + 74: ';', // KEYCODE_SEMICOLON + 75: "'", // KEYCODE_APOSTROPHE + 76: '/', // KEYCODE_SLASH + 77: '@', // KEYCODE_AT + 81: '+', // KEYCODE_PLUS +} // 订单复核设置项本地存储 key(uni storage) const SETTING_KEY_BIND_PACKAGE = 'orderSettingBindPackage' @@ -594,6 +646,7 @@ export default { pageActive: true, // 原生层(plus.key)监听 plusKeyListener: null, + plusKeyUpListener: null, plusKeyBuffer: '', plusKeyTimer: null, plusKeyStartedAt: 0, @@ -677,6 +730,14 @@ export default { warehouseId: '', printRequestCode: '', printSending: false, + // 发货前打印确认(对齐 WMS_PDA ensurePrintedBeforeShip) + lastPrintError: '', + printFailVisible: false, + printFailMessage: '', + printFailDismissed: false, + pendingShipAction: '', + printFlowRunning: false, + confirmRechecking: false, selectedReviewProcess: '先打印后复核', selectedWeigh: '不称重', // 称重弹窗 @@ -748,6 +809,14 @@ export default { settingPmKeyboard: false, // 发货模式:auto 自动发货 / manual 手动发货(默认自动发货) settingShipMode: 'auto', + // D前缀波次(单品单件 pick_mode=2 / 波次号 D 前缀)自动复核 + dprefixedBarcodeVerified: false, + dprefixedAllScannedHandled: false, + sharedBarcodeDprefixed: false, + // 免验自动推进(need_recheck=N 或已扫满时点击商品卡片触发发货链路) + noRecheckAutoAdvanceHandled: false, + // 散单复核后称重:保存成功后据此切下一个未复核订单 + weighAfterReviewKey: '', } }, computed: { @@ -764,6 +833,26 @@ export default { weighDialogTitle() { return this.weighReviewMode ? '称重(复核前)' : '称重' }, + // 打印模式(对齐 WMS_PDA effectivePrintMode):散单强制先复核后打印/不打印,团购按设置 + effectivePrintMode() { + if (this.scanListType === 'single' && this.selectedReviewProcess !== '不打印') { + return 'reviewFirst' + } + if (this.selectedReviewProcess === '先打印后复核') return 'printFirst' + if (this.selectedReviewProcess === '先复核后打印') return 'reviewFirst' + return 'noPrint' + }, + // D前缀波次(单品单件):散单 + pick_mode=2 或波次号以 D 开头,无需逐件扫描。 + // 按「当前选中订单行」判定,避免混单时整批普通散单被误判为 D 前缀自动复核 + isDprefixedWave() { + if (this.scanListType !== 'single') return false + return this.isDprefixedRow(this.currentOrderHeader) + }, + printFailBodyText() { + return this.pendingShipAction === 'groupShip' + ? '打印失败或超时,未触发发货。请重试打印,打印成功后将进入包材绑定。' + : '打印失败或超时,未触发发货。请重试打印,打印成功后将自动发货。' + }, searchPlaceholder() { return this.hasSelection ? '扫描商品条码(全部扫完后回车确认)' : '输入运单号/车号,回车查询' }, @@ -775,6 +864,12 @@ export default { (item) => item?.name || (item?.id ? `打印台${item.id}` : '未命名打印台') ) }, + // 当前选中打印台在列表中的下标(-1 表示未选中),用于下拉列表高亮 + selectedPrinterIndex() { + const target = String(this.selectedPrinterId ?? '') + if (!target) return -1 + return this.printerList.findIndex((item) => String(this.getPrinterId(item) ?? '') === target) + }, reviewLocked() { // 已复核锁定:选中项为已复核订单/波次时,确认复核按钮禁用 return this.currentOrderHeader @@ -796,7 +891,8 @@ export default { return rows.every((order) => { const qty = Number(order?.quantity) || 0 const scanned = Number(order?.scannedQty) || 0 - return qty <= 0 || scanned >= qty + const exempt = String(order?.needRecheck || '').trim().toUpperCase() === 'N' + return qty <= 0 || exempt || scanned >= qty }) }, // pick_mode=3 散单分播模式:商品明细显示“篮号”列(位置在总数列前) @@ -849,7 +945,8 @@ export default { this.batchReviewVisible || this.packageMaterialDialogVisible || this.sharedBarcodeDrawerVisible || - this.settingsVisible + this.settingsVisible || + this.printFailVisible ) }, // 批量复核已解析的有效ID数(逗号/空格/换行分隔,去重) @@ -876,8 +973,8 @@ export default { }, watch: { hasSelection(val) { - // 进入商品条码流程(已选中订单)时,激活条码输入框(真机隐藏捕获时不抢占焦点) - if (val && !this.enableHiddenInputCapture) { + // 进入商品条码流程(已选中订单)时,激活条码输入框(真机不自动聚焦,避免误弹软键盘) + if (val && !this.enableHiddenInputCapture && !this.isAppPlus()) { this.activateSearchInput() } }, @@ -901,9 +998,36 @@ export default { } return '' }, + // 把条码值统一展开成字符串数组:支持 barcodes[] 数组,以及 "a;b;c" / "a,b,c" / "a,b,c" / "a|b" 等多值串 + normalizeBarcodeList(value) { + if (Array.isArray(value)) { + return value + .map((v) => String(v ?? '').trim()) + .filter((v) => v !== '') + } + const raw = String(value ?? '').trim() + if (!raw) return [] + return raw + .split(/[;,,|\s]+/) + .map((v) => v.trim()) + .filter((v) => v !== '') + }, + // 单行是否为 D 前缀单品单件:优先行内 wave_no 以 D 开头;行内 pick_mode 缺失时回退顶层 currentPickMode + isDprefixedRow(row) { + if (!row || typeof row !== 'object') return false + const src = this.getScanOrderSource(row) + if (String(this.getRowValue(src, ['wave_no', 'waveNo']) || '').startsWith('D')) return true + const rowPickMode = this.getRowValue(row, ['pick_mode', 'pickMode']) + if (rowPickMode !== '') return Number(rowPickMode) === 2 + return Number(this.currentPickMode) === 2 + }, normalizeOrderRow(row) { const rawBarcode = this.getRowValue(row, ['barcode', 'bar_code', 'goods_barcode', 'sku_barcode', 'barcodes']) - const barcode = Array.isArray(rawBarcode) ? (rawBarcode[0] || '') : rawBarcode + // 条码可能是数组(barcodes[])或多值字符串("a;b;c"):统一展开成列表,扫码匹配基于完整列表 + const barcodeList = this.normalizeBarcodeList(rawBarcode) + // 显示只展示前 5 个,多出的折叠为「+N」(单独蓝色展示);完整列表仍存 barcodeList 供扫码匹配 + const barcode = barcodeList.length > 5 ? barcodeList.slice(0, 5).join('、') : barcodeList.join('、') + const barcodeExtra = barcodeList.length > 5 ? `+${barcodeList.length - 5}` : '' const rawImage = this.getRowValue(row, ['images', 'image', 'image_url', 'imageUrl']) const image = Array.isArray(rawImage) ? (rawImage[0] || '') : rawImage return { @@ -911,12 +1035,16 @@ export default { quantity: this.getRowValue(row, ['plan_qty', 'quantity', 'qty', 'num', 'count']), scanMark: this.getRowValue(row, ['scanMark', 'scan_mark', 'scanStatus', 'scan_status']), barcode, + barcodeList, + barcodeExtra, productName: this.getRowValue(row, ['productName', 'product_name', 'goods_name', 'sku_name', 'item_name']), color: this.getRowValue(row, ['color', 'color_name']), spec: this.getRowValue(row, ['sku_property', 'spec', 'spec_name', 'size', 'sku_spec']), location: this.getRowValue(row, ['location', 'location_code', 'loc_code', 'stock_location', 'storage_location', '库位']), image, packingRequirements: this.getRowValue(row, ['recheck_requirements', 'recheckRequirements']), + // 免验标记:need_recheck=N 表示无需复核(对齐 WMS_PDA,缺失按需复核处理) + needRecheck: this.getRowValue(row, ['need_recheck', 'needRecheck']) || '', // 篮号(pick_mode=3 散单分播,明细行 box_no 等字段) basketNo: this.getRowValue(row, ['box_no', 'boxNo', 'basket_no', 'basketNo', 'seed_no', 'seedNo']), // 共享条码:库内存在相同条码的其它商品(has_shared_barcode,布尔) @@ -953,6 +1081,16 @@ export default { handleConfirm() { // 提交后重置扫码快速输入标记,下一轮输入重新识别手动/扫码 this.scanBurstConfirmed = false + // 包材绑定弹窗打开时:扫码/回车值进入包材搜索流程,而不是订单/商品条码查询 + if (this.packageMaterialDialogVisible) { + const code = (this.keyword || '').trim() + if (code) { + this.packageMaterialInput = code + this.keyword = '' + this.handlePackageMaterialSearch() + } + return + } // 已选中列表项时,回车走商品条码匹配流程;否则走关键词查询 if (this.hasSelection) { this.handleBarcodeMatch() @@ -1047,7 +1185,18 @@ export default { /** 静默防抖:距最后按键超过阈值且缓冲内容达标时,视为一次完整扫码并自动提交 */ checkScanIdle() { this.scanTimer = null - // 弹窗打开时静默防抖不触发主订单查询,避免把弹窗内扫码内容误当订单条码 + // 包材绑定弹窗打开时:扫码值应进入包材搜索流程(交给 handleConfirm 统一路由),不静默丢弃 + if (this.packageMaterialDialogVisible) { + const elapsed = Date.now() - this.lastScanKeyTime + const buffer = (this.keyword || '').trim() + if (this.scanBurstConfirmed && elapsed >= SCAN_IDLE_TIMEOUT && buffer.length >= SCAN_MIN_LENGTH) { + this.handleConfirm() + } else { + this.scanBurstConfirmed = false + } + return + } + // 其它弹窗打开时静默防抖不触发主订单查询,避免把弹窗内扫码内容误当订单条码 if (this.anyDialogOpen) { this.scanBurstConfirmed = false return @@ -1090,7 +1239,16 @@ export default { * - 真机(App / 平板浏览器):未聚焦时 WebView/浏览器不派发 keydown,改用隐藏 input 捕获 + 强制聚焦 + plus.key 原生监听 */ setupScanCaptureMode() { - this.enableHiddenInputCapture = this.isRealDevice() + // 真机(APP-PLUS)逻辑层无 DOM:document.activeElement 恒为 null, + // handleHiddenScanBlur 里「用户已聚焦其它输入框时不抢回焦点」的判断永远失效, + // 隐藏 input 会把搜索框焦点抢回并 hideKeyboard 收掉软键盘(弹一下又隐藏、无法输入)。 + // 现 plus.key 已按 Android 原生 keycode 完整捕获扫码,真机彻底关闭隐藏 input。 + if (this.isAppPlus()) { + this.enableHiddenInputCapture = false + return + } + // H5/Electron:有 DOM → 关闭隐藏捕获;小程序等无 DOM 且无 plus.key 平台 → 开启兜底 + this.enableHiddenInputCapture = !this.hasDomKeyboardSupport() }, /** 是否真机(App 或移动端浏览器/平板) */ isRealDevice() { @@ -1154,13 +1312,36 @@ export default { this.globalKeyListener = null }, parsePlusKeyCodeToChar(keyCode) { + // Android Enter=66 在 ASCII 里是 'B',必须先排除,交给 isPlusEnterKey 处理 + if (keyCode === 66) { + this._plusKeyStyle = this._plusKeyStyle || 'android' + return '' + } + // ---- Android 原生 keycode ---- + if (keyCode >= 7 && keyCode <= 16) { + this._plusKeyStyle = this._plusKeyStyle || 'android' + return String(keyCode - 7) // 0-9 + } + if (keyCode >= 29 && keyCode <= 54) { + this._plusKeyStyle = this._plusKeyStyle || 'android' + return String.fromCharCode(keyCode - 29 + 65) // A-Z + } + // Android 符号键:必须放在 ASCII 分支之前(防止 70('=') → 'F' 这类误读) + if (this._plusKeyStyle !== 'ascii' && ANDROID_PUNCT_MAP[keyCode] !== undefined) { + this._plusKeyStyle = this._plusKeyStyle || 'android' + return ANDROID_PUNCT_MAP[keyCode] + } + // ---- ASCII/DOM 风格(其它设备兑底)---- if (keyCode >= 48 && keyCode <= 57) { + this._plusKeyStyle = this._plusKeyStyle || 'ascii' return String.fromCharCode(keyCode) } if (keyCode >= 65 && keyCode <= 90) { + this._plusKeyStyle = this._plusKeyStyle || 'ascii' return String.fromCharCode(keyCode) } if (keyCode >= 96 && keyCode <= 105) { + this._plusKeyStyle = this._plusKeyStyle || 'ascii' return String(keyCode - 96) } if (keyCode === 189 || keyCode === 109) { @@ -1174,37 +1355,80 @@ export default { } return '' }, + // 判断是否为 Enter:Android 原生 Enter=66;ASCII 风格为 13 + // (13 在 Android 风格下是数字键 '6',所以用 text 能否解析来消歧) + isPlusEnterKey(keyCode, text) { + if (text) { + return false + } + if (keyCode === 66) { + return true + } + if (keyCode === 13) { + return this._plusKeyStyle !== 'android' + } + return false + }, + // 统一处理 plus.key 按键(keydown / keyup) + handlePlusKeyEvent(event, type) { + const keyCode = Number(event?.keyCode || 0) + const now = Date.now() + // 空闲超过阈值后重新锁定实际生效的事件类型(自愈「锁错就永久静默」) + if (this._plusKeyEventType && this._plusLastKeyAt && now - this._plusLastKeyAt > 1200) { + this._plusKeyEventType = null + } + this._plusLastKeyAt = now + if (!this.isPageActive()) { + return + } + // 锁定实际生效的事件类型,避免 keydown/keyup 都触发时把一个键记两次 + if (!this._plusKeyEventType) { + this._plusKeyEventType = type + } + if (this._plusKeyEventType !== type) { + return + } + const text = this.parsePlusKeyCodeToChar(keyCode) + const isEnter = this.isPlusEnterKey(keyCode, text) + if (text) { + // 相邻字符间隔过大 → 软键盘手动输入(字符已由 input 的 v-model 接收): + // 不进入扫码缓冲,避免「停顿后自动提交查询」;回车查询仍走 @confirm + const gap = this._plusLastCharAt ? now - this._plusLastCharAt : 0 + this._plusLastCharAt = now + if (gap > SCAN_BURST_MAX_GAP) { + this.clearPlusKeyTimer() + this.plusKeyBuffer = '' + this.plusKeyStartedAt = 0 + this.plusKeyLastAt = 0 + return + } + if (!this.plusKeyBuffer) { + this.plusKeyStartedAt = now + } + this.plusKeyLastAt = now + this.plusKeyBuffer += text + this.clearPlusKeyTimer() + this.plusKeyTimer = setTimeout(() => this.flushPlusKeyBuffer('timer'), 420) + return + } + if (isEnter) { + this.flushPlusKeyBuffer('enter') + } + }, attachPlusKeyboardListener() { if (!this.hasPlusKeyboardSupport()) { return } - if (this.plusKeyListener) { + if (this.plusKeyListener || this.plusKeyUpListener) { return } - this.plusKeyListener = (event) => { - if (!this.isPageActive()) { - return - } - const keyCode = Number(event?.keyCode || 0) - const isEnter = keyCode === 13 || keyCode === 66 - const text = this.parsePlusKeyCodeToChar(keyCode) - if (text) { - const now = Date.now() - if (!this.plusKeyBuffer) { - this.plusKeyStartedAt = now - } - this.plusKeyLastAt = now - this.plusKeyBuffer += text - this.clearPlusKeyTimer() - this.plusKeyTimer = setTimeout(() => this.flushPlusKeyBuffer('timer'), 420) - return - } - if (isEnter) { - this.flushPlusKeyBuffer('enter') - } - } + this._plusLastCharAt = 0 + this.plusKeyListener = (event) => this.handlePlusKeyEvent(event, 'keydown') + this.plusKeyUpListener = (event) => this.handlePlusKeyEvent(event, 'keyup') // #ifdef APP-PLUS + // 同时监听 keydown 与 keyup:部分真机只触发其一,由 handlePlusKeyEvent 锁定避免重复采集 plus.key.addEventListener('keydown', this.plusKeyListener) + plus.key.addEventListener('keyup', this.plusKeyUpListener) // #endif }, removePlusKeyboardListener() { @@ -1212,15 +1436,22 @@ export default { this.plusKeyBuffer = '' this.plusKeyStartedAt = 0 this.plusKeyLastAt = 0 - if (!this.plusKeyListener) { + this._plusKeyEventType = null + if (!this.plusKeyListener && !this.plusKeyUpListener) { return } // #ifdef APP-PLUS if (this.hasPlusKeyboardSupport()) { - plus.key.removeEventListener('keydown', this.plusKeyListener) + if (this.plusKeyListener) { + plus.key.removeEventListener('keydown', this.plusKeyListener) + } + if (this.plusKeyUpListener) { + plus.key.removeEventListener('keyup', this.plusKeyUpListener) + } } // #endif this.plusKeyListener = null + this.plusKeyUpListener = null }, flushPlusKeyBuffer(trigger = 'timer') { if (!this.isPageActive()) { @@ -1234,6 +1465,10 @@ export default { if (!code) { return } + // 过短内容(误触/软键盘单字符或短词停顿)不自动提交,回车查询不受影响 + if (code.length < PLUS_SCAN_MIN_LENGTH) { + return + } this.submitScanCode(code, 'plus') }, handleHiddenScanFocus() { @@ -1309,8 +1544,8 @@ export default { return } if (!this.enableHiddenInputCapture) { + // 无隐藏捕获:不再抢占/隐藏软键盘,避免点击操作时软键盘反复弹收 this.scanInputFocus = false - this.suppressSoftKeyboardBurst() return } if (!this.scanInputFocus) { @@ -1333,6 +1568,11 @@ export default { if (!this.isPageActive()) { return } + // 真机(APP-PLUS):订单复核页需手动输入(搜索/数量/包材条码),且已关闭隐藏 input, + // 不再压制软键盘;uni.hideKeyboard 会断开输入框按键连接,真机禁用 + if (this.isAppPlus()) { + return + } this.clearKeyboardSuppressTimers() uni.hideKeyboard?.() ;[80, 180, 320].forEach((delay) => { @@ -1451,11 +1691,15 @@ export default { normalizeScanBarcode(value) { return String(value || '').replace(/\s+/g, '').toUpperCase() }, - // 商品条码是否命中(兼容单值/分号、逗号分隔的多值条码) + // 商品条码是否命中(支持 barcodeList 数组多值,兼容单值/分号、逗号分隔的多值串) isBarcodeMatched(order, code) { if (!order || !code) { return false } + const list = order?.barcodeList + if (Array.isArray(list) && list.length) { + return list.some((part) => this.normalizeScanBarcode(part) === code) + } const raw = String(order?.barcode ?? '').trim() if (!raw) { return false @@ -1468,12 +1712,24 @@ export default { isSharedBarcode(order) { return !!order?.hasSharedBarcode }, - // 累加一个匹配商品的已扫数量(原 handleBarcodeMatch 命中逻辑) + // 累加一个匹配商品的已扫数量(原 handleBarcodeMatch 命中逻辑);步长 = 复核扫描数量设置 scanQty applyScannedMatch(target) { if (!target) { return } - target.scannedQty = (Number(target.scannedQty) || 0) + 1 + const total = Number(target.quantity) || 0 + const scanned = Number(target.scannedQty) || 0 + // 已扫满(数量>0 且已扫>=总数):不再累加,提示并语音播报「超出订单数」 + if (total > 0 && scanned >= total) { + this.keyword = '' + uni.showToast({ title: '超出订单数', icon: 'none' }) + return + } + const step = Number(this.scanQty) || 1 + // 已扫值不能大于总数(数量>0 时截断到总数) + target.scannedQty = total > 0 ? Math.min(scanned + step, total) : scanned + step + // 数量为单次生效:本次扫码用完后回到 1,避免下次扫描误按旧数量累加 + this.scanQty = 1 this.syncDetailStats(this.currentOrderHeader, this.displayOrders) this.keyword = '' // 复核命中商品:播报「数据一致」,并按商品去重追加该商品复核要求 @@ -1499,11 +1755,18 @@ export default { confirmSharedBarcodeItem(index) { const matches = this.sharedBarcodeMatches || [] const target = index >= 0 ? matches[index] : null + const dprefixed = this.sharedBarcodeDprefixed this.sharedBarcodeDrawerVisible = false this.sharedBarcodeMatches = [] this.sharedBarcodeSelectedIndex = -1 this.sharedBarcodeCode = '' this.sharedBarcodeImgError = {} + this.sharedBarcodeDprefixed = false + if (dprefixed) { + // D前缀波次自动复核:确认共享条码后继续标记全部已扫并触发发货 + this.finishDprefixedAutoReview() + return + } if (target) { this.applyScannedMatch(target) } @@ -1724,23 +1987,36 @@ export default { return } + let body = null try { // 新查询上下文:清空上一轮已复核保留项缓存 this.reviewedKeepList = [] - const body = await scanReviewOrder({ keyword: query }) + body = await scanReviewOrder({ keyword: query }) const payload = body?.data || body?.result || body || {} - this.applyScanResult(payload) + this.applyScanResult(payload, true) this.activeKeyword = query this.keyword = '' } catch (error) { + // 「接口返回成功却提示查询失败」排查: + // - hasBody=true → 接口已成功返回,异常发生在 applyScanResult 结果处理阶段(error 堆栈可定位) + // - hasBody=false → 接口请求失败或超时(timedOut 标记硬超时),与后端返回成功与否无关 + const detail = { + query, + hasBody: !!body, + timedOut: !!error?.timedOut, + errMsg: String(error?.errMsg || error?.message || ''), + } + console.error('[order scanOrder] 查询异常:', { ...detail, error }) + // 只写本地诊断(面板/logcat),避免网络波动频繁触发时刷爆服务端上报 + diagAnomaly('scan-order-query-fail', detail, { report: false }) uni.showToast({ - title: '查询失败', + title: error?.timedOut ? '查询超时,请重试' : '查询失败', icon: 'none', silentVoice: true, }) } }, - applyScanResult(payload) { + applyScanResult(payload, isBarcodeSearch = false) { const list = Array.isArray(payload?.list) ? payload.list : [] if (list.length === 0) { const message = payload?.msg || payload?.message || '未找到对应订单' @@ -1779,6 +2055,11 @@ export default { // 记录拣货任务 ID,供刷新按钮按 task_id 调用 scanTask this.currentTaskId = this.extractTaskId(payload, list) + // D前缀波次:本次查询即商品条码定位(关键词=商品条码),标记已校验,自动复核时直接标记全部已扫。 + // 按即将选中的第一行判定(混单时仅定位到的 D 前缀订单触发自动复核,普通散单不受影响) + const firstRow = this.scanOrderList.length > 0 ? this.scanOrderList[0] : null + this.dprefixedBarcodeVerified = isBarcodeSearch && this.isDprefixedRow(firstRow) + // 默认选中第一行,右侧立即展示其商品明细(不再需要手动点第一行) this.autoSelectFirstResult() }, @@ -1864,6 +2145,17 @@ export default { this.weighReviewMode = false // 复核后称重待完成状态复位 this.clearPostReviewWeighState() + // 自动复核相关标记复位 + this.dprefixedBarcodeVerified = false + this.dprefixedAllScannedHandled = false + this.sharedBarcodeDprefixed = false + this.noRecheckAutoAdvanceHandled = false + this.weighAfterReviewKey = '' + // 打印失败弹窗状态复位(清空/切单/重新扫描后清除「打印未完成」上下文,避免残留误弹) + this.printFailVisible = false + this.printFailDismissed = false + this.lastPrintError = '' + this.pendingShipAction = '' }, // 从响应顶层或列表行内提取拣货任务 ID extractTaskId(payload, list) { @@ -1928,7 +2220,16 @@ export default { uni.showToast({ title: '请先扫完所有商品,再进行复核', icon: 'none', silentVoice: true }) return } - // 确认复核:打开自绘确认弹窗(样式参考称重弹窗),确认后调用接口 + // 团购:确认复核入口重新走“打印→包材绑定/称重”链路(复核在包材确认或称重后完成) + if (this.scanListType === 'group') { + // 包材/称重弹窗已打开时不再重复重开(避免清空已选包材或打断称重) + if (this.packageMaterialDialogVisible || this.weighDialogVisible) { + return + } + this.startGroupReviewFlow() + return + } + // 散单:打开自绘确认弹窗(样式参考称重弹窗),确认后打印→发货 this.confirmReviewOrderNo = this.selectedOrderNo || this.getScanOrderNo(this.currentOrderHeader) || '' this.confirmReviewVisible = true @@ -1938,42 +2239,54 @@ export default { this.confirmReviewOrderNo = '' this.scheduleScanInputFocus(150) }, - confirmReviewConfirm() { + async confirmReviewConfirm() { this.confirmReviewVisible = false this.confirmReviewOrderNo = '' - this.doConfirmRecheck() + if (!(await this.ensurePrintedBeforeShip('manual'))) { + return + } + await this.doShip('manual') this.scheduleScanInputFocus(150) }, // 执行确认复核:调用 order.recheckOrder.confirmRecheck // 团购波次分组(scanListType==='group')传 wave_id,普通订单传 order_id // enableAutoNext=true 时复核刷新后自动选中下一个未复核订单/波次;false 则留待调用方自行切换 async doConfirmRecheck(enableAutoNext = true) { - let params - if (this.scanListType === 'group') { - const waveId = this.getRowValue(this.currentOrderHeader, ['wave_id', 'waveId']) - if (waveId === '') { - uni.showToast({ title: '未找到波次ID,无法复核', icon: 'none', silentVoice: true }) - return false - } - params = { wave_id: waveId } - } else { - const orderId = this.getScanOrderId(this.currentOrderHeader) - if (orderId === '') { - uni.showToast({ title: '未找到订单ID,无法复核', icon: 'none', silentVoice: true }) - return false - } - params = { order_id: orderId } + // 弱网防重入:上一次确认复核未完成时忽略本次触发,避免重复复核/重复发货 + if (this.confirmRechecking) { + return false } + this.confirmRechecking = true try { + let params + if (this.scanListType === 'group') { + const waveId = this.getRowValue(this.currentOrderHeader, ['wave_id', 'waveId']) + if (waveId === '') { + uni.showToast({ title: '未找到波次ID,无法复核', icon: 'none', silentVoice: true }) + return false + } + params = { wave_id: waveId } + } else { + const orderId = this.getScanOrderId(this.currentOrderHeader) + if (orderId === '') { + uni.showToast({ title: '未找到订单ID,无法复核', icon: 'none', silentVoice: true }) + return false + } + params = { order_id: orderId } + } const body = await confirmRecheck(params) const payload = body?.data || body?.result || body || {} - // 成功判定(实际接口约定):flag==='success' 且 code===1 + // 成功判定:flag==='success' 且 code 为 1 或 200(与称重/包材接口的 200 约定统一,兼容历史 1) const flagOk = body?.flag === 'success' || payload?.flag === 'success' const codeOk = body?.code === 1 || body?.code === '1' || + body?.code === 200 || + body?.code === '200' || payload?.code === 1 || - payload?.code === '1' + payload?.code === '1' || + payload?.code === 200 || + payload?.code === '200' if (!flagOk || !codeOk) { const message = body?.message || body?.msg || payload?.message || payload?.msg || '复核失败' @@ -2001,8 +2314,60 @@ export default { } catch (error) { uni.showToast({ title: '网络异常,请检查网络', icon: 'none' }) return false + } finally { + this.confirmRechecking = false } }, + // 散单:静默绑定推荐包材(失败不阻塞复核) + async bindSuggestedPackageForSingle() { + if (this.scanListType !== 'single') return null + const info = this.selectedPackageMaterialInfo + if (!info || typeof info !== 'object') return null + const waybill = this.getScanOrderNo(this.currentOrderHeader) || '' + if (!waybill) return null + const id = info.id ?? info.package_material_id + if (id === undefined || id === null || id === '') return null + return bindExpressPackageMaterialByWaybill({ + waybill_code: waybill, + package_material_id: id, + }) + }, + // 散单发货(对齐 WMS_PDA doShip):并发静默绑包材 + 确认复核;复核后按需称重/进下一单 + async doShip(action = 'autoNext') { + const pkgPromise = + this.scanListType === 'single' + ? this.bindSuggestedPackageForSingle().catch((err) => { + console.warn('[packageBinding] 散单包材绑定失败(不阻塞):', err) + }) + : null + const ok = await this.doConfirmRecheck(false) + if (!ok) return + this.printFailDismissed = false + if (pkgPromise) { + await pkgPromise + } + // 散单称重模式:复核(发货)成功后弹称重,称重完成后再进下一单 + if (this.scanListType === 'single' && this.selectedWeigh === '称重' && !this.isDprefixedWave) { + this.weighAfterReviewKey = this.getReviewKeepKey(this.currentOrderHeader) + this.weighReviewMode = false + this.weighInputValue = '' + this.weighDialogVisible = true + return + } + if (action === 'dprefixed') { + // D前缀波次:复核后清空选中、回到列表等待下一个商品条码(保留左侧列表,已复核项本地标记) + this.keyword = '' + this.clearSelection() + this.scheduleScanInputFocus(150) + return + } + if (action === 'manual' && this.settingShipMode !== 'auto') { + // 手动发货:复核完成后留在当前页,由用户继续操作 + return + } + const reviewedKey = this.getReviewKeepKey(this.currentOrderHeader) + this.autoSelectNextPendingOrder(reviewedKey) + }, // 当前订单复核完成后:自动选中「当前复核行之后的第一个」未复核订单/波次,并展示其商品详情; // reviewedKey 为刷新前记录的当前已复核行去重键,无后续未复核项时从头循环查找 autoSelectNextPendingOrder(reviewedKey = '') { @@ -2537,6 +2902,161 @@ export default { const randomPart = Math.random().toString(36).slice(2, 10) return `PRINT_${timePart}_${randomPart}` }, + // 为 Promise 增加超时控制(对齐 WMS_PDA withTimeout) + withTimeout(promise, ms = 10000) { + let timer = null + const timeoutPromise = new Promise((_, reject) => { + timer = setTimeout(() => reject(new Error('打印请求超时')), ms) + }) + return Promise.race([Promise.resolve(promise), timeoutPromise]).finally(() => { + if (timer) clearTimeout(timer) + }) + }, + // 当前订单/波次是否已打印(对齐 WMS_PDA):团购 = 未打印数量 0 且 订单数 > 0;散单 = is_printed 标志 + isAlreadyPrinted(item) { + const target = item || this.currentOrderHeader + if (!target || typeof target !== 'object') return false + if (this.scanListType === 'group') { + const unprintedCount = Number(this.getRowValue(target, ['unprinted_count', 'unprintedCount'])) || 0 + const orderCount = Number(this.getRowValue(target, ['total_orders', 'order_count', 'orderCount'])) || 0 + return unprintedCount === 0 && orderCount > 0 + } + const printed = this.getRowValue(target, ['is_printed', 'isPrinted']) + return printed === true || printed === 1 || printed === '1' || printed === '是' + }, + // 打印当前订单/波次并等待结果(含超时),返回是否成功 + async printOrderAndWait(item) { + const target = item || this.currentOrderHeader + if (!target) { + this.lastPrintError = '缺少打印目标' + return false + } + if (!this.selectedPrinterId) { + this.lastPrintError = '未绑定打印台' + return false + } + try { + let waveGroups = [] + if (this.scanListType === 'group') { + waveGroups = await this.fetchGroupWavePrintData(target) + } else { + const orderId = this.getScanOrderId(target) + if (orderId === '') { + this.lastPrintError = '未找到订单ID' + return false + } + const body = await getOrderPrintData({ order_ids: [Number(orderId)] }) + const payload = this.extractPrintPayload(body) + waveGroups = this.normalizeWaveGroups(payload) + } + if (!waveGroups.length) { + this.lastPrintError = '未获取到可打印数据' + return false + } + this.printRequestCode = this.buildPrintRequestCode() + const response = await this.withTimeout( + sendPrint({ + type: 'express', + printStationId: this.selectedPrinterId, + requestCode: this.printRequestCode, + data: { waveGroups }, + }), + 10000 + ) + const success = + response?.flag !== 'failure' && + response?.code !== '500' && + response?.code !== 500 && + response?.code !== 1001 && + response?.code !== 504 + if (!success) { + this.lastPrintError = String(response?.message || response?.msg || '打印失败') + return false + } + this.lastPrintError = '' + return true + } catch (error) { + this.lastPrintError = String(error?.message || error?.msg || error?.errMsg || '打印失败或超时') + return false + } + }, + // 本地标记当前订单/波次已打印(打印成功后同步,不刷新列表、不清空选中) + markCurrentPrinted() { + const row = this.currentOrderHeader + if (!row || typeof row !== 'object') return + const src = this.getScanOrderSource(row) + if (!src || typeof src !== 'object') return + if (this.scanListType === 'group') { + src.unprinted_count = 0 + const orderCount = this.getRowValue(src, ['total_orders', 'order_count', 'orderCount']) + if (this.getRowValue(src, ['printed_count', 'printedCount']) === '') { + src.printed_count = Number(orderCount) || 1 + } + } else { + src.is_printed = true + } + }, + // 发货前打印确认(对齐 WMS_PDA ensurePrintedBeforeShip) + async ensurePrintedBeforeShip(actionType = 'autoNext') { + this.pendingShipAction = actionType + if (this.effectivePrintMode === 'noPrint') { + return true + } + if (!this.selectedPrinterId) { + this.printFailMessage = '未绑定打印台,请先绑定打印台后再发货' + this.printFailDismissed = true + this.printFailVisible = true + return false + } + if (this.isAlreadyPrinted(this.currentOrderHeader)) { + return true + } + // 打印请求进行中:忽略并发触发,避免重复打印 + if (this.printFlowRunning) { + return false + } + this.printFlowRunning = true + try { + uni.showLoading({ title: '打印中...', mask: true }) + const printed = await this.printOrderAndWait(this.currentOrderHeader) + uni.hideLoading() + if (printed) { + this.printFailDismissed = false + this.markCurrentPrinted() + uni.showToast({ title: '打印成功', icon: 'success' }) + return true + } + this.printFailMessage = this.lastPrintError || '打印失败,未触发发货' + this.printFailDismissed = true + this.printFailVisible = true + uni.showToast({ title: '打印失败', icon: 'none' }) + return false + } finally { + this.printFlowRunning = false + } + }, + handlePrintFailClose() { + this.printFailVisible = false + }, + async handlePrintFailRetry() { + uni.showLoading({ title: '打印中...', mask: true }) + const printed = await this.printOrderAndWait(this.currentOrderHeader) + uni.hideLoading() + if (!printed) { + this.printFailMessage = this.lastPrintError || '打印失败,请重试' + uni.showToast({ title: '打印失败', icon: 'none' }) + return + } + this.printFailDismissed = false + this.printFailVisible = false + this.markCurrentPrinted() + uni.showToast({ title: '打印成功', icon: 'success' }) + if (this.pendingShipAction === 'groupShip') { + this.startGroupReviewFlow() + return + } + await this.doShip(this.pendingShipAction || 'autoNext') + }, // 解析仓库ID:面单补打团单模式按接口约定 warehouse_id 须与用户上下文 store_id 一致。 // 优先取扫码结果记录值(本次会话上下文),兜底读本地存储(含 user.info 持久化的 store_id/warehouse_id) resolveWarehouseId() { @@ -2660,20 +3180,18 @@ export default { } return waveGroups }, - // 商品明细全部扫完(allProductsScanned)且“是否称重”下拉为“称重”时, - // 自动弹出称重(复核前)弹窗;保存重量后由 confirmWeigh 直接继续执行确认复核 + // 商品明细全部扫完后进入自动复核发货链路(对齐 WMS_PDA handleDetailAllScanned) autoOpenWeighAfterScan() { - // 团购模式:无论“是否称重”下拉,商品全部扫完都强制走称重流程; - // 散单模式:仍按“是否称重=称重”才自动弹称重(复核前) - if (this.scanListType !== 'group' && this.selectedWeigh !== '称重') { - return - } // 避免与其它弹窗重叠、或在已复核/拦截锁定等状态下重复弹出 if ( this.weighDialogVisible || this.confirmReviewVisible || this.noBarcodeReviewVisible || - this.batchReviewVisible + this.batchReviewVisible || + this.packageMaterialDialogVisible || + this.sharedBarcodeDrawerVisible || + this.settingsVisible || + this.printFailVisible ) { return } @@ -2683,32 +3201,116 @@ export default { if (!this.allProductsScanned) { return } - // 团购模式:全部扫完 → 先弹“包材绑定”; - // 自动发货:绑定保存成功即触发复核;手动发货:绑定成功后再弹“称重(复核前)” - if (this.scanListType === 'group') { - if (this.settingBindPackage) { - const waybill = this.getWaveRepresentWaybill(this.currentOrderHeader) - if (waybill) { - const autoShip = this.settingShipMode === 'auto' - // 自动发货:绑定后直接复核,不再称重;手动发货:绑定后继续称重 - this.pmPendingWeigh = !autoShip - this.pmAutoRecheck = autoShip - this.pmBindWaybill = waybill - this.resetPackageMaterialSearch() - const preset = this.recommendedAsMaterial() - if (preset) { - this.pmSelectedMaterial = preset - } - this.packageMaterialDialogVisible = true - return - } - } + // D前缀波次自动复核防重入(finishDprefixedAutoReview 与明细变化可能重复触发) + if (this.isDprefixedWave && this.dprefixedAllScannedHandled) { + return + } + this.dprefixedAllScannedHandled = true + // 团购:先打印确认 → 包材绑定(或回退称重复核前) + if (this.scanListType === 'group') { + this.startGroupReviewFlow() + return + } + // 散单:不走包材弹窗,直接进入发货/称重决策 + this.afterPackageBinding() + }, + // 团单复核完成的统一入口: + // 有运单号且开包材绑定 → 打印→绑包材;有运单号但关绑定 → 打印→称重(复核前); + // 无运单号 → 无法绑包材也无法称重,打印确认后直接复核(wave_id)不称重 + startGroupReviewFlow() { + const waybill = this.getWaveRepresentWaybill(this.currentOrderHeader) + if (this.settingBindPackage && waybill) { + this.handleGroupAllScanned() + return + } + if (!waybill) { + this.handleGroupDirectReview() + return + } + this.handleGroupFallbackWeigh() + }, + // 团单无运单号:打印确认后直接复核(无法按运单号绑包材/称重) + async handleGroupDirectReview() { + if (!(await this.ensurePrintedBeforeShip('groupShip'))) { + return + } + await this.doConfirmRecheck() + }, + // 团单:全部商品复核完成时先确保打印成功,打印成功才进入包材绑定 + async handleGroupAllScanned() { + if (!(await this.ensurePrintedBeforeShip('groupShip'))) { + return + } + this.openGroupPackageBinding() + }, + // 团单回退(未开包材绑定/无运单):先打印确认 → 称重(复核前)→ 复核 + async handleGroupFallbackWeigh() { + if (!(await this.ensurePrintedBeforeShip('groupShip'))) { + return } - // 复核前自动称重模式:标题显示“称重(复核前)”,保存后直接执行复核 this.weighReviewMode = true this.weighInputValue = '' this.weighDialogVisible = true }, + // 弹包材绑定弹窗(打印成功 / 打印失败重试成功后进入) + openGroupPackageBinding() { + const waybill = this.getWaveRepresentWaybill(this.currentOrderHeader) + if (!waybill) { + // 无运单号:回退到称重(复核前) + this.weighReviewMode = true + this.weighInputValue = '' + this.weighDialogVisible = true + return + } + const autoShip = this.settingShipMode === 'auto' + this.pmPendingWeigh = !autoShip + this.pmAutoRecheck = autoShip + this.pmBindWaybill = waybill + this.resetPackageMaterialSearch() + const preset = this.recommendedAsMaterial() + if (preset) { + this.pmSelectedMaterial = preset + } + this.packageMaterialDialogVisible = true + }, + // 包材绑定 / 发货之后的分叉(对齐 WMS_PDA afterPackageBinding) + afterPackageBinding() { + if (this.isDprefixedWave) { + this.handleDprefixedAutoConfirm() + return + } + // 团购始终称重(复核已在包材绑定确认时完成);散单按“称重模式”设置 + const needWeigh = this.scanListType === 'group' || this.selectedWeigh === '称重' + if (needWeigh && this.scanListType === 'group') { + this.pmAfterReviewWeighWaybill = this.getWaveRepresentWaybill(this.currentOrderHeader) || '' + this.pmAfterReviewReviewKey = this.getReviewKeepKey(this.currentOrderHeader) + this.pmPostReviewWeighPending = true + this.weighReviewMode = false + this.weighInputValue = '' + this.weighDialogVisible = true + return + } + // 散单:自动发货则直接打印→发货(需要称重时复核后弹称重);手动发货提示点击确认复核 + if (this.settingShipMode === 'auto') { + this.handleAutoConfirmAndNext() + } else { + uni.showToast({ title: '全部商品已扫描完成,可点击确认复核', icon: 'none', duration: 2000 }) + } + }, + // 散单自动发货:先打印确认 → 发货 + async handleAutoConfirmAndNext() { + if (!(await this.ensurePrintedBeforeShip('autoNext'))) { + return + } + await this.doShip('autoNext') + }, + // D前缀波次:先打印确认 → 发货 + async handleDprefixedAutoConfirm() { + if (!(await this.ensurePrintedBeforeShip('dprefixed'))) { + return + } + await this.doShip('dprefixed') + }, handleWeigh() { // 未选中订单时提示先选择 if (!this.hasSelection) { @@ -2729,8 +3331,14 @@ export default { this.scheduleScanInputFocus(150) return } + // 散单复核后称重被取消:保留 weighAfterReviewKey 待称重状态,点商品行/手动称重可补录,保存后再切下一单 + if (this.scanListType === 'single' && this.weighAfterReviewKey) { + this.scheduleScanInputFocus(150) + return + } this.pmAfterReviewWeighWaybill = '' this.pmAfterReviewReviewKey = '' + this.weighAfterReviewKey = '' this.pmPostReviewWeighPending = false this.scheduleScanInputFocus(150) }, @@ -2848,21 +3456,23 @@ export default { this.pmSearchList = [] this.pmSearched = false }, - // 保存:按运单号绑定包材(order.bindExpressPackageMaterialByWaybill) + // 保存包材:自动流程(包材绑定后复核)走并发复核;手动「包材」按钮仅绑定 async confirmPackageMaterial() { if (this.pmBinding) { return } - if (this.scanListType !== 'group') { - uni.showToast({ title: '仅团购波次支持包材绑定', icon: 'none', silentVoice: true }) - return + if (this.pmAutoRecheck || this.pmPendingWeigh) { + await this.doGroupShip() + } else { + await this.bindPackageOnly() } - const waybill = this.pmBindWaybill || this.getWaveRepresentWaybill(this.currentOrderHeader) - if (!waybill) { - uni.showToast({ title: '未找到波次运单号,无法绑定包材', icon: 'none', silentVoice: true }) - return - } - // 未点选但搜索结果唯一命中时自动采用;仍未选时兜底采用推荐包材 + }, + // 解析本次绑定的运单号(优先弹窗打开时记录的 pmBindWaybill,兜底当前波次运单) + resolvePmBindWaybill() { + return this.pmBindWaybill || this.getWaveRepresentWaybill(this.currentOrderHeader) + }, + // 解析待绑定的包材 ID(选中 > 唯一命中 > 推荐包材) + resolvePackageMaterialId() { let material = this.pmSelectedMaterial if (!material && this.pmSearchList.length === 1) { material = this.pmSearchList[0] @@ -2870,7 +3480,20 @@ export default { if (!material) { material = this.recommendedAsMaterial() } - const materialId = material?.id ?? material?.package_material_id + return material?.id ?? material?.package_material_id + }, + // 仅绑定包材(手动「包材」按钮,不触发复核) + async bindPackageOnly() { + if (this.scanListType !== 'group') { + uni.showToast({ title: '仅团购波次支持包材绑定', icon: 'none', silentVoice: true }) + return + } + const waybill = this.resolvePmBindWaybill() + if (!waybill) { + uni.showToast({ title: '未找到波次运单号,无法绑定包材', icon: 'none', silentVoice: true }) + return + } + const materialId = this.resolvePackageMaterialId() if (materialId === undefined || materialId === null || materialId === '') { uni.showToast({ title: '请先扫描并选择包材', icon: 'none', silentVoice: true }) return @@ -2896,53 +3519,58 @@ export default { }) return } - uni.showToast({ title: '发货成功', icon: 'none' }) - const autoRecheck = this.pmAutoRecheck - const continueWeigh = this.pmPendingWeigh + uni.showToast({ title: '包材绑定成功', icon: 'none' }) this.resetPackageMaterialDialog() - if (autoRecheck) { - // 团购自动发货:包材绑定保存即触发复核;复核成功后强制按本波次运单继续称重 - this.pmAutoRecheck = false - this.pmPendingWeigh = false - // doConfirmRecheck 内部刷新会 clearSelection → clearPostReviewWeighState 清空暂存, - // 因此先用局部变量记录,复核完成后再回填,避免被刷新清掉导致不再弹称重 - const reviewWaybill = this.getWaveRepresentWaybill(this.currentOrderHeader) || '' - const reviewKey = this.getReviewKeepKey(this.currentOrderHeader) - // 复核后先不自动切波次(称重完成后由 confirmWeigh 切换) - const reviewed = await this.doConfirmRecheck(false) - if (!reviewed) { - this.scheduleScanInputFocus(150) - return - } - if (reviewWaybill) { - // 复核后称重:普通称重(不再触发复核),保存成功后切下一未复核波次; - // 取消时保留待称重状态,点商品行可再次弹称重 - this.pmAfterReviewWeighWaybill = reviewWaybill - this.pmAfterReviewReviewKey = reviewKey - this.pmPostReviewWeighPending = true - this.weighReviewMode = false - this.weighInputValue = '' - this.weighDialogVisible = true - } else { - this.scheduleScanInputFocus(150) - } - return - } - if (continueWeigh) { - // 团购手动发货:包材绑定成功后继续弹“称重(复核前)”,保存重量后走复核 - this.pmPendingWeigh = false - this.weighReviewMode = true - this.weighInputValue = '' - this.weighDialogVisible = true - } else { - this.scheduleScanInputFocus(150) - } + this.scheduleScanInputFocus(150) } catch (error) { uni.showToast({ title: '包材绑定失败,请重试', icon: 'none', silentVoice: true }) } finally { this.pmBinding = false } }, + // 团单发货:提交复核 + 包材绑定并发(包材绑定失败不阻塞发货),随后进入称重/下一波次 + async doGroupShip() { + if (this.scanListType !== 'group') { + uni.showToast({ title: '仅团购波次支持包材绑定', icon: 'none', silentVoice: true }) + return + } + const waybill = this.resolvePmBindWaybill() + if (!waybill) { + uni.showToast({ title: '未找到波次运单号,无法绑定包材', icon: 'none', silentVoice: true }) + return + } + const materialId = this.resolvePackageMaterialId() + if (materialId === undefined || materialId === null || materialId === '') { + uni.showToast({ title: '请先扫描并选择包材', icon: 'none', silentVoice: true }) + return + } + this.pmBinding = true + uni.showLoading({ title: '提交复核中...' }) + try { + // 并发提交:复核确认 + 包材绑定(包材绑定失败不阻塞) + const bindPromise = bindExpressPackageMaterialByWaybill({ + waybill_code: waybill, + package_material_id: materialId, + }).catch((pkgErr) => { + console.warn('[packageBinding] 包材绑定失败(不阻塞):', pkgErr) + }) + const [reviewed] = await Promise.all([this.doConfirmRecheck(false), bindPromise]) + uni.hideLoading() + if (!reviewed) { + // doConfirmRecheck 已弹出失败提示 + return + } + this.pmPendingWeigh = false + this.pmAutoRecheck = false + this.resetPackageMaterialDialog() + this.afterPackageBinding() + } catch (error) { + uni.hideLoading() + uni.showToast({ title: '提交复核失败,请重试', icon: 'none' }) + } finally { + this.pmBinding = false + } + }, handleWeighPlus() { this.weighInputValue = String((Number(this.weighInputValue) || 0) + 1) }, @@ -3070,10 +3698,11 @@ export default { // 复核前自动称重模式:保存成功后直接继续执行确认复核(不弹二次确认弹窗) const shouldContinueReview = this.weighReviewMode this.weighReviewMode = false - // 自动发货复核后称重成功:切到下一个未复核波次 - const nextReviewKey = this.pmAfterReviewReviewKey + // 复核后称重(团购自动发货 / 散单称重模式):保存成功后切下一个未复核订单/波次 + const nextReviewKey = this.pmAfterReviewReviewKey || this.weighAfterReviewKey this.pmAfterReviewWeighWaybill = '' this.pmAfterReviewReviewKey = '' + this.weighAfterReviewKey = '' this.pmPostReviewWeighPending = false if (shouldContinueReview) { await this.doConfirmRecheck() @@ -3094,6 +3723,34 @@ export default { if (!order) { return } + // 打印未完成被关闭后(订单未打印未发货):点商品行只重新弹出「打印未完成」弹窗,不自动重试打印 + // 「不打印」模式下不做打印拦截,避免残留状态误弹 + if ( + this.effectivePrintMode !== 'noPrint' && + this.printFailDismissed && + !this.printFailVisible + ) { + this.printFailMessage = this.lastPrintError || '打印失败,未触发发货' + this.printFailVisible = true + return + } + // 免验自动推进(对齐 WMS_PDA handleGoodsItemClick):所有商品 need_recheck=N 或已扫满时, + // 此类订单商品明细从不变化、allScanned 不会触发,点击商品卡片时主动触发一次发货链路。 + if ( + !this.isDprefixedWave && + !this.noRecheckAutoAdvanceHandled && + this.displayOrders.length > 0 && + this.getWaveReviewStatus(this.currentOrderHeader) !== '已复核' && + this.displayOrders.every( + (g) => + String(g.needRecheck || '').trim().toUpperCase() === 'N' || + Number(g.scannedQty || 0) >= Number(g.quantity || 0) + ) + ) { + this.noRecheckAutoAdvanceHandled = true + this.autoOpenWeighAfterScan() + return + } if (this.canNoBarcodeReview(order)) { diagNote('no-barcode-review-open', { item: order?.productName || order?.barcode || '', @@ -3102,6 +3759,13 @@ export default { this.openNoBarcodeReview(order) return } + // 散单复核后称重待完成(先复核后称重,取消称重后):点商品行重新弹普通称重补录 + if (this.scanListType === 'single' && this.weighAfterReviewKey) { + this.weighReviewMode = false + this.weighInputValue = '' + this.weighDialogVisible = true + return + } // 复核后称重待完成(团购自动发货,取消称重后):点商品行直接重新弹普通称重 if (this.pmPostReviewWeighPending) { this.weighReviewMode = false @@ -3189,28 +3853,26 @@ export default { // 商品明细全部扫完时:按“是否称重=称重”自动进入称重(复核前) this.autoOpenWeighAfterScan() }, - handlePrinterSelectStart() { + togglePrinterDropdown() { + if (this.printerOpened) { + this.closePrinterDropdown() + return + } // 打印台列表为空时,重新拉取 if (this.printerList.length === 0) { this.loadPrinters() } this.printerOpened = true }, - handlePrinterPickStart() { - this.printerOpened = true - }, - handlePrinterPickEnd() { + closePrinterDropdown() { this.printerOpened = false }, - handlePrinterChange(event) { - const printer = this.printerList[Number(event.detail.value)] || null + handlePrinterOptionClick(index) { + const printer = this.printerList[index] || null this.selectedPrinter = printer ? this.getPrinterName(printer) : '' this.selectedPrinterId = printer ? this.getPrinterId(printer) : '' this.printerOpened = false }, - handlePrinterCancel() { - this.printerOpened = false - }, getPrinterId(item) { return item?.id ?? item?.printer_id ?? '' }, @@ -3419,7 +4081,16 @@ export default { this.interceptLocked = false this.interceptTarget = null this.spokenRecheckKeys = [] + this.dprefixedAllScannedHandled = false + this.noRecheckAutoAdvanceHandled = false this.resetSharedBarcodeState() + // 散单复核后称重待完成:切到其它订单时取消该状态(避免残留,切回后不再自动弹称重) + if (this.scanListType === 'single' && this.weighAfterReviewKey) { + const clickedKey = this.getReviewKeepKey(item) + if (clickedKey && clickedKey !== this.weighAfterReviewKey) { + this.weighAfterReviewKey = '' + } + } const src = this.getScanOrderSource(item) this.selectedPendingOrderKey = this.getScanOrderKey(item) this.selectedOrderNo = this.getScanOrderNo(item) @@ -3469,6 +4140,18 @@ export default { orderId: this.getScanOrderId(item), } uni.showToast({ title: '此单已拦截', icon: 'none' }) + return + } + // D前缀波次(单品单件):商品条码定位进入时自动标记全部已扫并触发复核发货 + if (this.isDprefixedWave) { + if (this.dprefixedBarcodeVerified) { + this.dprefixedBarcodeVerified = false + if (this.getWaveReviewStatus(item) !== '已复核') { + this.completeDprefixedAutoReview() + } + } else if (this.getWaveReviewStatus(item) !== '已复核') { + uni.showToast({ title: '请扫描商品条码进行复核', icon: 'none' }) + } } }, getWaveKey(wave) { @@ -3491,6 +4174,8 @@ export default { this.interceptLocked = false this.interceptTarget = null this.spokenRecheckKeys = [] + this.dprefixedAllScannedHandled = false + this.noRecheckAutoAdvanceHandled = false this.resetSharedBarcodeState() this.selectedWaveKey = this.getWaveKey(wave) // 复核后称重待完成:切到其它波次时取消该状态(避免残留自动弹称重) @@ -3540,6 +4225,36 @@ export default { this.syncDetailStats(this.currentOrderHeader, rows) } }, + // D前缀波次单品单件:自动标记所有商品为已扫并触发复核发货; + // 若库内有相同商品(has_shared_barcode),先弹确认弹窗,确认后再自动复核发货 + completeDprefixedAutoReview() { + if (!this.displayOrders.length) return + const sharedGoods = this.displayOrders.find((g) => !!g?.hasSharedBarcode) + if (sharedGoods) { + this.sharedBarcodeDprefixed = true + this.sharedBarcodeMatches = [sharedGoods] + this.sharedBarcodeCode = String(sharedGoods.barcode || '') + this.sharedBarcodeSelectedIndex = 0 + this.sharedBarcodeImgError = {} + this.sharedBarcodeDrawerVisible = true + return + } + this.finishDprefixedAutoReview() + }, + // 标记所有商品为已扫并触发复核发货 + finishDprefixedAutoReview() { + if (!this.displayOrders.length) return + if (this.dprefixedAllScannedHandled) return + const rows = this.displayOrders.map((g) => ({ + ...g, + scannedQty: g.quantity, + })) + this.displayOrders = rows + this.syncDetailStats(this.currentOrderHeader, rows) + this.$nextTick(() => { + this.autoOpenWeighAfterScan() + }) + }, }, mounted() { this.loadPrinters() @@ -3550,9 +4265,9 @@ export default { this.attachGlobalKeyboardListener() this.suppressSoftKeyboardBurst() this.scheduleScanInputFocus(260) - // 页面进入即聚焦搜索框(H5 无隐藏捕获时) + // 页面进入即聚焦搜索框(仅 H5/Electron;真机不自动聚焦,避免误弹软键盘) this.$nextTick(() => { - if (!this.enableHiddenInputCapture) { + if (!this.enableHiddenInputCapture && !this.isAppPlus()) { this.activateSearchInput() } }) @@ -3785,21 +4500,25 @@ export default { /* 左栏 380px:0.9011 → 0.6rem,保证“复核扫描 + 数量步进器”能在一行内放下 */ width: 0.6rem; height: 0.36rem; /* 控件 36px */ + line-height: 0.36rem; /* 与高度一致:真机原生 input 无行高时文字顶部会被白底裁剪 */ text-align: center; border: 0.01rem solid var(--wms-border-alt); border-radius: 0.07rem; font-size: 0.2rem; background-color: var(--wms-card-bg); + box-sizing: border-box; } .search-input { flex: 1; height: 0.36rem; + line-height: 0.36rem; /* 与高度一致:真机原生 input 无行高时文字顶部会被白底裁剪 */ border: 0.01rem solid #e5e5e5; border-radius: 0.07rem; padding: 0 0.15rem; font-size: 0.2rem; background-color: var(--wms-card-bg); + box-sizing: border-box; } .table-scroll { @@ -4073,6 +4792,15 @@ export default { min-width: 0; } +.cell-barcode-value { + flex: 1; + min-width: 0; +} + +.cell-barcode-extra { + color: var(--wms-primary); +} + .cell-name { flex: 1; min-width: 0; @@ -4668,12 +5396,14 @@ export default { flex: 1; min-width: 0; height: 0.36rem; + line-height: 0.36rem; /* 与高度一致:真机原生 input 无行高时文字顶部会被白底裁剪 */ text-align: center; border: 0.01rem solid var(--wms-border-alt); border-radius: 0.07rem; font-size: 0.3rem; color: var(--wms-text); background-color: var(--wms-card-bg); + box-sizing: border-box; } /* 输入提示(placeholder)保持小字号浅色,不随输入值放大(uni-app placeholder-class 生效于各端) */ @@ -4692,7 +5422,6 @@ export default { display: flex; align-items: center; justify-content: flex-end; - gap: 0.15rem; padding: 0.15rem 0.25rem 0.25rem; border-top: 0.01rem solid #eef2f8; } @@ -4722,6 +5451,16 @@ export default { color: var(--wms-white); } +/* 弹窗底部按钮间距:不用 flex gap(老 WebView 不支持 flex 容器的 gap,真机按钮会挤在一起), + 改用子项外边距;放在 .weigh-btn 等样式之后,确保覆盖其 margin:0 */ +.weigh-dialog-footer > .weigh-btn { + margin-left: 0.15rem; +} + +.weigh-dialog-footer > .weigh-btn:first-child { + margin-left: 0; +} + /* 无条码复核弹窗内容 */ .no-barcode-review-content { padding: 0.05rem 0.04rem; @@ -4771,6 +5510,21 @@ export default { word-break: break-all; } +/* 打印失败弹窗:具体原因(对齐 WMS_PDA print-fail-popup-msg) */ +.print-fail-msg { + margin-top: 0.1rem; + padding: 0.1rem 0.12rem; + background-color: #fdf2f2; + border-radius: 0.07rem; +} + +.print-fail-msg__text { + font-size: 0.18rem; + color: var(--wms-danger-strong); + line-height: 1.5; + word-break: break-all; +} + /* 批量快捷复核弹窗 */ .batch-dialog { width: 9.01rem; @@ -5004,7 +5758,7 @@ export default { margin-bottom: 0.1rem; padding: 0.1rem 0.15rem; background-color: var(--wms-card-bg); - overflow: hidden; + /* 不能用 overflow:hidden:自绘打印台下拉框要向下展开,会被裁掉 */ } .tool-btn { @@ -5101,7 +5855,9 @@ export default { min-width: 0; font-size: 0.17rem; color: var(--wms-text); - line-height: 1; + /* 行高与控件高度一致(0.36rem):line-height:1 在真机 CJK 字体的字面上下超出 1em, + 配合 .tool-select 的 overflow:hidden 会把字头顶部裁掉 */ + line-height: 0.36rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; @@ -5117,17 +5873,99 @@ export default { } .tool-select-arrow-icon { - /* 图标要小于控件:0.2rem(20px) 放在 0.36rem(36px) 下拉里(原来是 0.3rem,几乎顶满控件) */ - display: block; - width: 0.2rem; - height: 0.2rem; + /* 纯 CSS 向下箭头:两根短斜线拼成 ⌄(对称、天然竖直居中); + inline 在真机 APP-PLUS 不渲染,这里用 ::before/::after 两条线代替 */ + position: relative; + width: 0.13rem; + height: 0.07rem; transition: transform 0.2s ease; } +.tool-select-arrow-icon::before, +.tool-select-arrow-icon::after { + content: ''; + position: absolute; + bottom: 0; + width: 0.09rem; + height: 0.02rem; + background-color: #909399; + border-radius: 0.01rem; +} + +.tool-select-arrow-icon::before { + right: 50%; + transform: rotate(45deg); + transform-origin: right center; +} + +.tool-select-arrow-icon::after { + left: 50%; + transform: rotate(-45deg); + transform-origin: left center; +} + .tool-select--open .tool-select-arrow-icon { transform: rotate(180deg); } +.tool-select-wrap { + position: relative; + flex-shrink: 0; +} + +.tool-select-dropdown { + position: absolute; + top: calc(100% + 0.06rem); + left: 0; + min-width: 100%; + max-width: 2.6rem; + background-color: var(--wms-card-bg); + border: 0.01rem solid var(--wms-border-alt); + border-radius: 0.07rem; + box-shadow: 0 0.07rem 0.26rem rgba(0, 0, 0, 0.12); + z-index: 60; + overflow: hidden; + box-sizing: border-box; +} + +.tool-select-dropdown-scroll { + max-height: 2.4rem; +} + +.tool-select-option { + padding: 0.12rem 0.15rem; + font-size: 0.17rem; + color: var(--wms-text); + line-height: 1.4; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + cursor: pointer; +} + +.tool-select-option:active { + background-color: #f0f2f5; +} + +.tool-select-option--selected { + color: var(--wms-primary); + background-color: #eaf2ff; +} + +.tool-select-option--empty { + color: var(--wms-text-placeholder); + text-align: center; +} + +.tool-select-mask { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: 59; +} + .tool-info-text { font-size: 0.18rem; color: var(--wms-text-secondary);