From a448958e47bc501cb6dcf62b071bf6dd54ef3245 Mon Sep 17 00:00:00 2001 From: zm2000 <18386612143@163.com> Date: Fri, 4 Sep 2026 15:46:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=8D=E6=A0=B8=E5=8F=91?= =?UTF-8?q?=E8=B4=A7=E3=80=81=E6=95=A3=E5=8D=95=E6=8B=A3=E8=B4=A7=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E3=80=81=E5=95=86=E5=93=81=E6=9F=A5=E8=AF=A2=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/work/order/order-review.vue | 58 +++- pages/work/order/scatter-picking-detail.vue | 364 +++++++++++++++----- pages/work/product/query.vue | 19 +- 3 files changed, 343 insertions(+), 98 deletions(-) diff --git a/pages/work/order/order-review.vue b/pages/work/order/order-review.vue index 812c9e9..22a0376 100644 --- a/pages/work/order/order-review.vue +++ b/pages/work/order/order-review.vue @@ -2147,9 +2147,11 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue'; const normalizedKeyword = this.normalizeKeyword(keyword); if (!normalizedKeyword) { uni.showToast({ - title: '请输入快递单号或车号', + title: '扫描关键词不能为空', icon: 'none' }); + // 对应接口 400「扫描关键词不能为空」:同步语音提示 + this.speakVoice('扫描关键词不能为空'); return; } @@ -2159,35 +2161,61 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue'; }); } try { - const response = await this.$http('order.recheckOrder.scanOrder', this.buildScanOrderParams(normalizedKeyword)); + // 第4参 toastAfter=false:关闭请求层全局错误 toast,由 handleScanOrderError 统一按 silent 控制提示与语音 + const response = await this.$http('order.recheckOrder.scanOrder', this.buildScanOrderParams(normalizedKeyword), '', false); // 检测接口返回的错误信息 if (response?.flag === 'failure') { + // 依据后端提示(400 扫描关键词不能为空 / 404 未找到对应订单 / 400 订单未拣货不允许复核等)toast + 语音播报 const errorMsg = String(response?.message || response?.msg || '').trim(); - if (!silent) { - uni.showToast({ - title: errorMsg || '订单查询失败', - icon: 'none' - }); - } + this.handleScanOrderError(errorMsg || '订单查询失败', silent); return; } const payload = this.extractScanOrderPayload(response); const result = this.normalizeScanOrderResult(payload); this.handleScanOrderSuccess(result, silent); } catch (error) { - if (!silent) { - const message = String(error?.message || error?.msg || error?.errMsg || '').trim(); - uni.showToast({ - title: message || '订单查询失败', - icon: 'none' - }); - } + const message = String(error?.message || error?.msg || error?.errMsg || '').trim(); + this.handleScanOrderError(message || '订单查询失败', silent); } finally { if (!silent) { uni.hideLoading(); } } }, + // scanOrder 接口业务失败:toast 展示后端提示,并按提示内容语音播报 + handleScanOrderError(message, silent = false) { + const raw = String(message || '').trim(); + // 去除后端常见包装前缀:如 "接口错误: 未找到对应订单" -> "未找到对应订单" + const cleaned = raw.replace(/^接口错误\s*[::]\s*/, '').trim(); + const toastText = cleaned || '订单查询失败'; + if (!silent) { + uni.showToast({ + title: toastText, + icon: 'none', + // 业务错误提示(如未找到对应订单/订单未拣货等)展示 5s,便于 PDA 现场确认 + duration: 5000 + }); + } + const voiceText = this.resolveScanOrderErrorVoice(toastText); + if (voiceText) { + this.speakVoice(voiceText); + } + }, + // 将 scanOrder 返回的业务提示映射为语音播报文本(对应接口 400/404 常见错误) + resolveScanOrderErrorVoice(message) { + const text = String(message || '').trim(); + if (/未拣货/.test(text)) { + return '订单未拣货,不允许复核'; + } + if (/未找到对应订单|未查询到订单|无匹配订单|未找到订单/.test(text)) { + return '未找到对应订单'; + } + if (/扫描关键词不能为空|关键词为空|请输入快递单号或车号/.test(text)) { + return '扫描关键词不能为空'; + } + // 其他未识别的业务提示:仅 toast 不额外播报,避免朗读非预期文案 + return ''; + }, async toggleUnboundPrintStationOnly() { this.showUnboundPrintStationOnly = true; this.selectedStationId = this.printStationId || ''; diff --git a/pages/work/order/scatter-picking-detail.vue b/pages/work/order/scatter-picking-detail.vue index 5d0c1ff..a80b6c7 100644 --- a/pages/work/order/scatter-picking-detail.vue +++ b/pages/work/order/scatter-picking-detail.vue @@ -93,32 +93,29 @@ 打印设置 打印台 - - {{ printStationName || '--' }} - - - - - {{ station.name }} - + + 打印 - - 打印 - + + + 打印 + + 打印消息 @@ -143,7 +140,7 @@ currentPage: 1, paginationTotal: 0, showPrintPopup: false, - showPrintStationDropdown: false, + printStationInputKeyword: '', printStationName: '--', printStationId: '', printStationList: [], @@ -462,6 +459,109 @@ .map(group => (group && typeof group === 'object' ? group : null)) .filter(group => !!group); }, + /** + * 提取 getWavePlatformPrintData 返回的 locked_wave_groups(打印锁占用的分组) + * 已打印面单的数据会出现在 locked_wave_groups,而 waveGroups 为空 + * @param {object} payload + */ + extractLockedWaveGroups(payload) { + const groups = Array.isArray(payload?.locked_wave_groups) ? payload.locked_wave_groups : []; + return groups + .map(group => (group && typeof group === 'object' ? group : null)) + .filter(group => !!group); + }, + /** + * 判断锁定订单是否为拦截订单(无需解锁,禁止打印) + * 当 locked_orders 的 order_id 与 intercepted_orders 的 order_id 一致(拦截集合覆盖全部锁定集合)时返回 true + * @param {object} payload getWavePlatformPrintData 返回的数据 + * @returns {boolean} + */ + isInterceptedPrintBlock(payload) { + const lockedOrders = Array.isArray(payload?.locked_orders) ? payload.locked_orders : []; + const interceptedOrders = Array.isArray(payload?.intercepted_orders) ? payload.intercepted_orders : []; + const lockedIds = new Set( + lockedOrders.map(order => order?.order_id ?? order?.orderId ?? '').filter(id => id !== '' && id != null) + ); + const interceptedIds = new Set( + interceptedOrders.map(order => order?.order_id ?? order?.orderId ?? '').filter(id => id !== '' && id != null) + ); + if (!lockedIds.size || !interceptedIds.size) { + return false; + } + // 拦截集合覆盖全部锁定集合 → 锁定订单均为拦截订单,不支持打印 + for (const id of lockedIds) { + if (!interceptedIds.has(id)) { + return false; + } + } + return true; + }, + /** + * 将 locked_wave_groups 转换为 unlockWavePlatformPrintDataByGroup 所需的 groups 分组条件 + * 每个(波次 + 平台 + 系统快递编码)组合为一个分组 + * @param {Array} lockedWaveGroups 打印锁占用的波次平台分组 + */ + buildUnlockGroups(lockedWaveGroups) { + const groups = []; + (Array.isArray(lockedWaveGroups) ? lockedWaveGroups : []).forEach(waveGroup => { + const waveId = waveGroup?.wave_id ?? waveGroup?.waveId ?? waveGroup?.id ?? ''; + const platforms = Array.isArray(waveGroup?.platforms) ? waveGroup.platforms : []; + if (platforms.length) { + platforms.forEach(platform => { + groups.push({ + wave_id: waveId, + platform: platform?.platform ?? platform?.platform_code ?? '', + sys_logistics_code: platform?.sys_logistics_code ?? platform?.sysLogisticsCode ?? platform?.logistics_code ?? '', + order_ids: Array.isArray(platform?.order_ids) ? platform.order_ids : [] + }); + }); + } else if (waveId !== '' && waveId != null) { + // 无平台嵌套时按波次兜底 + groups.push({ wave_id: waveId, platform: '', sys_logistics_code: '', order_ids: [] }); + } + }); + return groups.filter(group => group.wave_id !== '' && group.wave_id != null); + }, + /** + * 按分组解锁波次平台打印锁(order.print.unlockWavePlatformPrintDataByGroup) + * 将传入的分组中已锁定的订单 print_lock_status 置为 none + * @param {Array} lockedWaveGroups 打印锁占用的波次平台分组(用于构建 groups 条件) + * @returns {Promise} 解锁结果(summary / unlocked_order_ids / unlocked_orders 等) + */ + async unlockWavePlatformPrintDataByGroup(lockedWaveGroups) { + const warehouseId = this.resolveWarehouseId(); + if (!warehouseId) { + throw new Error('缺少仓库ID'); + } + const groups = this.buildUnlockGroups(lockedWaveGroups); + if (!groups.length) { + throw new Error('缺少可解锁的分组条件'); + } + const waveIds = Array.from(new Set( + groups.map(g => g.wave_id).filter(id => id !== '' && id != null) + )); + const params = { + warehouse_id: warehouseId, + wave_ids: waveIds, + group_type: 'platform_express', + unlock_scope: 'group', + groups + }; + const response = await this.$http('order.print.unlockWavePlatformPrintDataByGroup', params); + const unlockPayload = response?.data?.data + || response?.data + || response?.result + || response + || {}; + const unlockedIds = unlockPayload?.unlocked_order_ids || []; + const unlockedCount = Array.isArray(unlockedIds) ? unlockedIds.length : 0; + console.log(`[ScatterPickingDetail] 波次平台打印锁解锁成功,解锁订单数: ${unlockedCount}`); + return response; + }, + async fetchWavePlatformPrintPayload(params) { + const response = await this.$http('order.print.getWavePlatformPrintData', params); + return this.extractWavePlatformPrintPayload(response); + }, buildPrintRequestCode() { const timePart = Date.now().toString(36); const randomPart = Math.random().toString(36).slice(2, 10); @@ -475,9 +575,25 @@ if (!params.wave_ids.length) { throw new Error('缺少波次ID'); } - const response = await this.$http('order.print.getWavePlatformPrintData', params); - const payload = this.extractWavePlatformPrintPayload(response); - const waveGroups = this.normalizeWaveGroups(payload); + + let payload = await this.fetchWavePlatformPrintPayload(params); + let waveGroups = this.normalizeWaveGroups(payload); + const lockedWaveGroups = this.extractLockedWaveGroups(payload); + // 打印锁占用:waveGroups 为空 + locked_wave_groups 有值 → 先按分组解锁打印锁,解锁后重新获取可打印数据 + if (!waveGroups.length && lockedWaveGroups.length) { + // 拦截订单与锁定订单 order_id 一致 → 拦截订单不支持打印,无需解锁 + if (this.isInterceptedPrintBlock(payload)) { + throw new Error('拦截订单,不支持打印'); + } + try { + await this.unlockWavePlatformPrintDataByGroup(lockedWaveGroups); + } catch (error) { + throw new Error(`解锁打印锁失败:${String(error?.message || error?.msg || error?.errMsg || '请稍后重试')}`); + } + payload = await this.fetchWavePlatformPrintPayload(params); + waveGroups = this.normalizeWaveGroups(payload); + } + if (!waveGroups.length) { throw new Error('未获取到可打印的waveGroups'); } @@ -506,35 +622,108 @@ const source = item && typeof item === 'object' ? item : {}; const id = String(source.id ?? source.print_station_id ?? source.printStationId ?? '').trim(); const name = String(source.name || source.station_name || source.print_station_name || '').trim(); + const customBarcode = String(source.custom_barcode || source.bar_code || source.barcode || source.station_code || source.print_station_code || '').trim(); return { id, - name + name, + customBarcode }; }) .filter(item => !!item.id && !!item.name); }, - async loadPrintStations() { + async loadPrintStations(autoAssign = false) { const response = await this.$http('print.getList', this.buildPrintRecordParams()); const list = this.extractPrintRecordList(response); const stations = this.normalizePrintStations(list); this.printStationList = stations; - this.printStationId = stations[0]?.id || ''; - this.printStationName = stations[0]?.name || '--'; + // 输入框模式:不再默认分配打印台,需扫码/输入精确匹配 + if (autoAssign && stations.length && !this.printStationId) { + this.printStationId = stations[0]?.id || ''; + this.printStationName = stations[0]?.name || '--'; + } }, - togglePrintStationDropdown() { - if (!this.printStationList.length) { - uni.showToast({ - title: '暂无可用打印台', - icon: 'none' - }); + async ensurePrintStationsLoaded() { + if (Array.isArray(this.printStationList) && this.printStationList.length) { + return true; + } + try { + uni.showLoading({ title: '加载打印台...' }); + await this.loadPrintStations(false); + return Array.isArray(this.printStationList) && this.printStationList.length; + } catch (error) { + console.warn('[ScatterPickingDetail] 加载打印台列表失败:', error); + return false; + } finally { + uni.hideLoading(); + } + }, + resolvePrintStationByKeyword(keyword) { + const list = Array.isArray(this.printStationList) ? this.printStationList : []; + if (!list.length) { + return null; + } + const kw = this.normalizeKeyword(keyword).toLowerCase(); + if (!kw) { + return null; + } + return list.find(station => + String(station.name || '').toLowerCase() === kw + || String(station.id || '').toLowerCase() === kw + || String(station.customBarcode || '').toLowerCase() === kw + ) || null; + }, + applyPrintStation(station) { + if (!station) { + return false; + } + this.printStationId = String(station.id || ''); + this.printStationName = String(station.name || '--'); + // 仅回显打印台名称,不追加条码 + this.printStationInputKeyword = String(station.name || ''); + return true; + }, + handlePrintStationInput(value) { + const keyword = this.normalizeKeyword(value); + if (!keyword) { return; } - this.showPrintStationDropdown = !this.showPrintStationDropdown; + const matched = this.resolvePrintStationByKeyword(keyword); + if (matched) { + this.applyPrintStation(matched); + uni.showToast({ title: `已匹配打印台:${matched.name}`, icon: 'none' }); + } }, - handlePrintStationSelect(station) { - this.printStationId = String(station?.id || ''); - this.printStationName = String(station?.name || '--'); - this.showPrintStationDropdown = false; + async matchPrintStationByKeyword(keyword) { + const text = this.normalizeKeyword(keyword); + if (!text) { + return; + } + // 打印台列表未加载时自动加载,保证广播扫描可直接匹配 + const loaded = await this.ensurePrintStationsLoaded(); + if (!loaded) { + uni.showToast({ title: '暂无可用打印台', icon: 'none' }); + return; + } + const matched = this.resolvePrintStationByKeyword(text); + if (matched) { + this.applyPrintStation(matched); + uni.showToast({ title: `已匹配打印台:${matched.name}`, icon: 'success' }); + } else { + uni.showToast({ title: '未匹配到打印台', icon: 'none' }); + } + }, + handlePrintStationInputConfirm() { + const keyword = this.normalizeKeyword(this.printStationInputKeyword); + if (!keyword) { + return; + } + const matched = this.resolvePrintStationByKeyword(keyword); + if (matched) { + this.applyPrintStation(matched); + uni.showToast({ title: `已匹配打印台:${matched.name}`, icon: 'success' }); + } else { + this.matchPrintStationByKeyword(keyword); + } }, safeDispatchBroadcast(action, payload) { try { @@ -585,6 +774,12 @@ if (!scanText) { return; } + // 打印设置弹窗打开时,扫描结果填入打印台输入框并自动匹配打印台 + if (this.showPrintPopup) { + this.printStationInputKeyword = scanText; + this.matchPrintStationByKeyword(scanText); + return; + } this.keyword = scanText; this.handleSearch(); }, @@ -742,16 +937,19 @@ this.printMessage = message; uni.showToast({ title: message, - icon: 'none' + icon: 'none', + duration: 4000 }); return; } try { - await this.loadPrintStations(); + await this.loadPrintStations(false); } catch (error) { this.printStationList = []; + this.printStationId = ''; this.printStationName = '--'; + this.printStationInputKeyword = ''; uni.showToast({ title: '打印台加载失败', icon: 'none' @@ -759,7 +957,14 @@ } this.pendingPrintCount = Number(target.unreviewedCount || 0); this.printMessage = `待打印未复核订单 ${this.pendingPrintCount} 条`; - this.showPrintStationDropdown = false; + // 回显已匹配的打印台;未匹配时清空输入等待扫码/输入 + if (this.printStationId && this.printStationName && this.printStationName !== '--') { + this.printStationInputKeyword = this.printStationName; + } else { + this.printStationId = ''; + this.printStationName = '--'; + this.printStationInputKeyword = ''; + } this.showPrintPopup = true; }, buildPrintSendParams() { @@ -776,10 +981,18 @@ }; }, async handleConfirmPrint() { - if (!this.printStationList.length || !this.printStationId || !this.printStationName || this.printStationName === '--') { - this.printMessage = '请选择打印台'; + if (!Array.isArray(this.printStationList) || !this.printStationList.length) { + this.printMessage = '暂无可用打印台'; uni.showToast({ - title: '请选择打印台', + title: '暂无可用打印台', + icon: 'none' + }); + return; + } + if (!this.printStationId || !this.printStationName || this.printStationName === '--') { + this.printMessage = '请先扫描/输入打印台'; + uni.showToast({ + title: '请先扫描/输入打印台', icon: 'none' }); return; @@ -1118,7 +1331,7 @@ } .print-row--station .print-label { - padding-top: 10rpx; + padding-top: 20rpx; } .print-row--action { @@ -1144,53 +1357,40 @@ color: #303133; } - .print-picker { + .print-station-input-wrap { flex: 1; min-width: 0; + max-width: 100%; display: flex; align-items: center; - justify-content: space-between; - padding: 10rpx 16rpx; - border: 1rpx solid #dcdfe6; - border-radius: 10rpx; - background: #fafafa; + box-sizing: border-box; } - .print-picker-value { + .print-station-input-wrap ::v-deep .u-input { flex: 1; - font-size: 28rpx; - line-height: 40rpx; - color: #303133; - padding-right: 16rpx; - word-break: break-all; + min-width: 0; + width: auto; + max-width: 100%; + box-sizing: border-box; } - .print-station-dropdown { - position: absolute; - right: 0; - top: calc(100% - 4rpx); - width: calc(100% - 154rpx); - max-height: 300rpx; - overflow-y: auto; - background: #ffffff; - border: 1rpx solid #ebeef5; - border-radius: 10rpx; - z-index: 10091; + .print-station-input-wrap ::v-deep .u-input__content { + min-width: 0; + box-sizing: border-box; } - .print-station-option { - padding: 16rpx 20rpx; - font-size: 28rpx; - line-height: 40rpx; - color: #303133; + .print-action-wrap { + flex: 1; + min-width: 0; + max-width: 100%; + display: flex; + align-items: center; + box-sizing: border-box; } - .print-station-option + .print-station-option { - border-top: 1rpx solid #f2f3f5; - } - - .print-station-option--active { - color: #2979ff; + .print-action-wrap ::v-deep .u-button { + width: 100%; + box-sizing: border-box; } .print-message { diff --git a/pages/work/product/query.vue b/pages/work/product/query.vue index b616530..d1e4242 100644 --- a/pages/work/product/query.vue +++ b/pages/work/product/query.vue @@ -1232,7 +1232,24 @@ }; }, buildListWhereParams(stockIdList) { - const normalizedStockIdList = this.extractStockIdList(stockIdList); + // 注意:入参在 handleSearch 中已由 extractStockIdList 归一为纯 id 数组(数字), + // 不能再套一次 extractStockIdList(它只接受对象数组,会把 id 数组全部过滤成空), + // 否则 where 恒为 {},导致 inventory.list 每次全量查询而非按商品过滤。 + const sourceList = Array.isArray(stockIdList) ? stockIdList : []; + const normalizedStockIdList = []; + const seenIds = new Set(); + sourceList.forEach(item => { + let candidate = item; + if (item && typeof item === 'object') { + candidate = item.stock_id ?? item.goods_id ?? item.item_id ?? item.product_id ?? item.id; + } + const normalized = this.normalizePositiveId(candidate); + if (normalized !== null && !seenIds.has(normalized)) { + seenIds.add(normalized); + normalizedStockIdList.push(normalized); + } + }); + if (!normalizedStockIdList.length) { return {}; }