From 2399a2a4a0bb8d2def1f798c5834736e52ba4634 Mon Sep 17 00:00:00 2001 From: zm2000 <18386612143@163.com> Date: Fri, 20 Nov 2026 17:28:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(B2B):=20=E5=A4=87=E8=B4=A7/=E6=8F=90?= =?UTF-8?q?=E8=B4=A7=E6=B5=81=E7=A8=8B=E4=BC=98=E5=8C=96=E5=B9=B6=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E7=89=88=E6=9C=AC=E8=87=B3=201.0.145?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 备货列表(stockPreparation.vue): - 顶部搜索占位与查询改为按运单号精确匹配(waybill_codes eq) - 卡片新增发货单号、提货车牌、备货照片缩略图及点击预览 - 接入扫码广播回调(setCallbacks/start/resume/pause/stop) - 备货详情(stockPreparationDetail.vue): - 商品行名称与编码合并为 formatItemName 显示 - 底部操作栏改用自绘按钮,新增取消/完成备货、分箱校验三个确认弹窗 - 新增分箱校验 validatePacking:同商品箱号去重、合计数量超量/不足拦截 - 取消/完成备货增加语音播报 - onBackPress 拦截返回并提示,新增 navigateBackSafely 兜底重试 - 提货操作(pickupOperation.vue): - 新增车牌拍照识别(OCR)并回填车牌号 - 提货成功/失败增加语音播报 - 接入扫码广播回调 - 发版:package.json version、manifest.json versionName/versionCode 同步升至 1.0.145 / 1000145 --- package.json | 2 +- src/manifest.json | 4 +- src/pages/B2BOperation/pickupOperation.vue | 408 ++++++++++++++--- src/pages/B2BOperation/stockPreparation.vue | 146 +++++- .../B2BOperation/stockPreparationDetail.vue | 422 +++++++++++++++--- 5 files changed, 849 insertions(+), 133 deletions(-) diff --git a/package.json b/package.json index c9f0083..b1237a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wms-pda", - "version": "1.0.144", + "version": "1.0.145", "private": true, "description": "天豹云仓 WMS_PDA(uni-app Vue2 + @vue/cli 4.5)", "scripts": { diff --git a/src/manifest.json b/src/manifest.json index c7031d0..aa12702 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,8 +2,8 @@ "name" : "WMS_PDA", "appid" : "__UNI__0B3DAD3", "description" : "多平台快速开发的UI框架", - "versionName" : "1.0.144", - "versionCode" : 1000144, + "versionName" : "1.0.145", + "versionCode" : 1000145, "transformPx" : false, "app-plus" : { "statusbar" : { diff --git a/src/pages/B2BOperation/pickupOperation.vue b/src/pages/B2BOperation/pickupOperation.vue index 662509f..d3d809e 100644 --- a/src/pages/B2BOperation/pickupOperation.vue +++ b/src/pages/B2BOperation/pickupOperation.vue @@ -6,7 +6,7 @@ - {{ getDeliveryOrderCode(item) }} + {{ getWaybillText(item) }} 加急 含SN @@ -59,54 +59,60 @@ 货主: {{ getStoreOwner(item) }} + + 发货单号: + {{ getDeliveryOrderCode(item) }} + 总箱数: {{ item.total_box_count || 0 }} - 提货车牌号: - {{ item.pickup_plate_number || '--' }} + 备货人: + {{ getPrepOperatorName(item) }} + 备货备注: + {{ item.prep_remark || '--' }} + + + 提货车牌: + {{ item.pickup_plate_number || '--' }} + + + 备货照片: + + + + + + 提货照片: + + + + + 提货时间: {{ formatDateTime(item.picked_up_at) }} - - - - - 创建:{{ getOrderCreateAt(item) }} + + 备货时间: + {{ formatDateTime(item.prep_at) }} + @@ -166,8 +172,8 @@ placeholder-class="plate-placeholder" /> - - + + @@ -225,13 +231,22 @@ currentOrder: null, plateNumber: '', pickupPhotoList: [], - submitting: false + submitting: false, + recognizingPlate: false } }, onLoad() { + this.safeDispatchBroadcast('setCallbacks', { + onResult: this.handleBroadcastResult + }); + this.safeDispatchBroadcast('start'); this.fetchList(); }, onShow() { + this.safeDispatchBroadcast('setCallbacks', { + onResult: this.handleBroadcastResult + }); + this.safeDispatchBroadcast('resume'); // 从详情页返回时刷新(首次进入由 onLoad 拉取,避免重复) if (this._hasShown) { this.currentPage = 1; @@ -239,6 +254,12 @@ } this._hasShown = true; }, + onHide() { + this.safeDispatchBroadcast('pause'); + }, + onUnload() { + this.safeDispatchBroadcast('stop'); + }, computed: { currentOrderDeliveryCode() { return this.getDeliveryOrderCode(this.currentOrder); @@ -257,6 +278,71 @@ } }, methods: { + safeDispatchBroadcast(action, payload) { + try { + const task = this.$store.dispatch(`broadcast/${action}`, payload); + if (task && typeof task.catch === 'function') { + task.catch(error => { + console.warn(`[pickupOperation] broadcast/${action} 调用失败:`, error); + }); + } + } catch (error) { + console.warn(`[pickupOperation] broadcast/${action} 调用异常:`, error); + } + }, + speakMessage(message, options = {}) { + const text = String(message || '').trim(); + if (!text) { + return; + } + const tools = this.$tools; + if (!tools || typeof tools.speakText !== 'function') { + return; + } + try { + const task = tools.speakText(text, options); + if (task && typeof task.catch === 'function') { + task.catch(error => { + console.warn('[pickupOperation] 语音播报失败:', error); + }); + } + } catch (error) { + console.warn('[pickupOperation] 语音播报异常:', error); + } + }, + normalizeUniScanResult(scanResult) { + if (!scanResult) { + return ''; + } + if (typeof scanResult === 'string') { + return scanResult.trim(); + } + if (typeof scanResult.result === 'string') { + return scanResult.result.trim(); + } + if (Array.isArray(scanResult.result)) { + const firstResult = scanResult.result.find(item => item); + if (typeof firstResult === 'string') { + return firstResult.trim(); + } + if (firstResult && typeof firstResult.data === 'string') { + return firstResult.data.trim(); + } + } + if (typeof scanResult.data === 'string') { + return scanResult.data.trim(); + } + return ''; + }, + handleBroadcastResult(result) { + const rawCode = this.normalizeUniScanResult(result); + if (!rawCode) { + return; + } + this.keyword = rawCode; + this.currentPage = 1; + this.fetchList(); + }, async fetchList() { this.loading = true; try { @@ -268,19 +354,20 @@ const where = {}; // 提货作业仅处理已完成备货的订单 where.prep_status = 'fin'; - if (keyword) { - where.waybill_codes = { - operator: 'eq', - type: 'text', - value: keyword - }; - } // 提货状态筛选(简写结构) if (this.pickupStatusTab) { where.is_picked_up = this.pickupStatusTab; } // 已提货走配送订单列表(dispatch/m4),待提货走待处理 B2B 列表 const isPickedUp = this.pickupStatusTab === 'Y'; + if (keyword) { + // 顶部搜索按运单号精确查询(与备货作业/order-review 列表一致) + where.waybill_codes = { + operator: 'eq', + type: 'text', + value: keyword + }; + } const apiName = isPickedUp ? 'order.deliveryOrder2b.list' : 'order.pendingOrder2b.list'; const sort = isPickedUp ? { sortField: 'delivery_time', sortOrder: 'DESC' } @@ -390,6 +477,20 @@ if (!item || typeof item !== 'object') return '--'; return item.store_remark || '--'; }, + getWaybillCodes(item) { + const raw = item?.waybill_codes ?? item?.express_numbers; + if (Array.isArray(raw)) { + return raw.map(String).filter(Boolean); + } + if (typeof raw === 'string' && raw.trim()) { + return raw.split(/[,,]/).map(s => s.trim()).filter(Boolean); + } + return []; + }, + getWaybillText(item) { + const codes = this.getWaybillCodes(item); + return codes.length > 0 ? codes.join(' / ') : '--'; + }, getOrderCreateAt(item) { return this.formatDateTime(item?.created_at ?? item?.create_at); }, @@ -481,18 +582,197 @@ this.plateNumber = ''; this.pickupPhotoList = []; }, - scanPlateNumber() { - uni.scanCode({ - onlyFromCamera: true, - scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'], - success: (res) => { - const code = String(res?.result || '').trim(); - if (!code) return; - this.plateNumber = code; - }, - fail: () => {} + getPlatformInfo() { + const systemInfo = typeof uni.getSystemInfoSync === 'function' ? uni.getSystemInfoSync() : {}; + return { + platform: systemInfo.platform || 'unknown', + uniPlatform: systemInfo.uniPlatform || 'unknown', + system: systemInfo.system || '', + model: systemInfo.model || '', + appVersion: systemInfo.appVersion || '' + }; + }, + arrayBufferToBase64(buffer) { + if (uni.arrayBufferToBase64) { + return uni.arrayBufferToBase64(buffer); + } + + let binary = ''; + const bytes = new Uint8Array(buffer); + const length = bytes.byteLength; + for (let i = 0; i < length; i += 1) { + binary += String.fromCharCode(bytes[i]); + } + + if (typeof btoa === 'function') { + return btoa(binary); + } + + throw new Error('当前环境不支持 ArrayBuffer 转 Base64'); + }, + readFileBase64ByPlus(filePath) { + return new Promise((resolve, reject) => { + if (typeof plus === 'undefined' || !plus.io || !plus.io.resolveLocalFileSystemURL) { + reject(new Error('PLUS 文件系统不可用')); + return; + } + + plus.io.resolveLocalFileSystemURL(filePath, (entry) => { + entry.file((file) => { + const reader = new plus.io.FileReader(); + reader.onloadend = (event) => { + const result = String(event?.target?.result || event?.result || ''); + resolve(result.replace(/^data:.*?;base64,/, '')); + }; + reader.onerror = (error) => reject(error); + reader.readAsDataURL(file); + }, reject); + }, reject); }); }, + readFileBase64ByRequest(filePath) { + return new Promise((resolve, reject) => { + uni.request({ + url: filePath, + method: 'GET', + responseType: 'arraybuffer', + success: (res) => { + try { + resolve(this.arrayBufferToBase64(res.data)); + } catch (error) { + reject(error); + } + }, + fail: (error) => reject(error) + }); + }); + }, + async getImageBase64(filePath) { + const tryByFileSystemManager = () => new Promise((resolve, reject) => { + try { + const fileSystemManager = uni.getFileSystemManager && uni.getFileSystemManager(); + if (!fileSystemManager || typeof fileSystemManager.readFile !== 'function') { + reject(new Error('getFileSystemManager.readFile 不可用')); + return; + } + + fileSystemManager.readFile({ + filePath, + encoding: 'base64', + success: ({ data }) => resolve(String(data || '')), + fail: (error) => reject(error) + }); + } catch (error) { + reject(error); + } + }); + + return new Promise((resolve, reject) => { + if (!filePath) { + reject(new Error('图片路径无效')); + return; + } + + tryByFileSystemManager() + .then(resolve) + .catch((fileSystemError) => { + console.warn('[pickupOperation] getFileSystemManager 分支失败:', fileSystemError); + this.readFileBase64ByPlus(filePath) + .then(resolve) + .catch((plusError) => { + console.warn('[pickupOperation] plus.io.FileReader 分支失败:', plusError); + this.readFileBase64ByRequest(filePath) + .then(resolve) + .catch((requestError) => { + console.error('[pickupOperation] uni.request(arraybuffer) 分支失败:', requestError); + reject(requestError); + }); + }); + }); + }); + }, + extractLicensePlate(response) { + if (!response) { + return ''; + } + + const directFields = [ + response.license_plate, + response.licensePlate, + response.plate_number, + response.plateNo, + response.plate_number_text, + response.number + ]; + const directMatch = directFields.find(value => typeof value === 'string' && value.trim()); + if (directMatch) { + return directMatch.trim(); + } + + const data = response.data; + if (data && typeof data === 'object') { + return this.extractLicensePlate(data); + } + + if (Array.isArray(data) && data.length) { + return this.extractLicensePlate(data[0]); + } + + return ''; + }, + async capturePlateNumber() { + if (this.recognizingPlate) { + return; + } + + try { + const chooseResult = await new Promise((resolve, reject) => { + uni.chooseImage({ + count: 1, + sourceType: ['camera'], + sizeType: ['compressed'], + success: resolve, + fail: reject + }); + }); + + const filePath = chooseResult?.tempFilePaths?.[0] || chooseResult?.tempFiles?.[0]?.path; + if (!filePath) { + throw new Error('未获取到拍照文件'); + } + + this.recognizingPlate = true; + uni.showLoading({ title: '识别车牌中', mask: true }); + + const imageBase64 = await this.getImageBase64(filePath); + if (!imageBase64) { + throw new Error('图片转换失败'); + } + + const result = await this.$http('common.recognizeLicensePlate', { + image_base64: imageBase64 + }, '', false); + console.log('[pickupOperation] 车牌识别接口返回:', result); + const licensePlate = this.extractLicensePlate(result); + if (!licensePlate) { + throw new Error((result && result.message) || '未识别到车牌号'); + } + + this.plateNumber = licensePlate; + uni.showToast({ title: '识别成功', icon: 'success' }); + this.speakMessage(`识别成功,车牌:${licensePlate}`); + } catch (error) { + const errMsg = String(error?.errMsg || error?.message || error || '').toLowerCase(); + if (errMsg.includes('cancel')) { + return; + } + + uni.showToast({ title: (error && error.message) || '车牌识别失败', icon: 'none' }); + } finally { + this.recognizingPlate = false; + uni.hideLoading(); + } + }, handleConfirmPickup() { const orderId = Number(this.currentOrder?.id || 0); if (!orderId) { @@ -542,9 +822,11 @@ if (response?.flag === 'failure') { const msg = String(response?.message || response?.msg || data?.message || '提货失败'); uni.showToast({ title: msg, icon: 'none', duration: 2500 }); + this.speakMessage(msg); return; } uni.showToast({ title: '提货成功', icon: 'success' }); + this.speakMessage('提货成功'); this.closePickupPopup(); this.currentPage = 1; this.fetchList(); @@ -714,7 +996,7 @@ margin-left: 12rpx; padding: 4rpx 16rpx; border-radius: 8rpx; - font-size: 26rpx; + font-size: 36rpx; flex-shrink: 0; } @@ -912,7 +1194,7 @@ .photo-card__title { font-size: 36rpx; - font-weight: 600; + font-weight: bold; color: #303133; } } @@ -967,7 +1249,7 @@ .confirm-title { font-size: 36rpx; - font-weight: 600; + font-weight: bold; color: #303133; } diff --git a/src/pages/B2BOperation/stockPreparation.vue b/src/pages/B2BOperation/stockPreparation.vue index 2ba66bd..e9a9981 100644 --- a/src/pages/B2BOperation/stockPreparation.vue +++ b/src/pages/B2BOperation/stockPreparation.vue @@ -6,7 +6,7 @@ - {{ getDeliveryOrderCode(item) }} + {{ getWaybillText(item) }} 加急 含SN @@ -59,6 +59,10 @@ 货主: {{ getStoreOwner(item) }} + + 发货单号: + {{ getDeliveryOrderCode(item) }} + 总箱数: {{ item.total_box_count || 0 }} @@ -71,6 +75,23 @@ 备注: {{ item.prep_remark || '--' }} + + 提货车牌: + {{ item.pickup_plate_number || '--' }} + + + 备货照片: + + + + @@ -126,9 +147,17 @@ } }, onLoad() { + this.safeDispatchBroadcast('setCallbacks', { + onResult: this.handleBroadcastResult + }); + this.safeDispatchBroadcast('start'); this.fetchList(); }, onShow() { + this.safeDispatchBroadcast('setCallbacks', { + onResult: this.handleBroadcastResult + }); + this.safeDispatchBroadcast('resume'); // 从详情页返回时刷新备货状态(首次进入由 onLoad 拉取,避免重复) if (this._hasShown) { this.currentPage = 1; @@ -136,6 +165,12 @@ } this._hasShown = true; }, + onHide() { + this.safeDispatchBroadcast('pause'); + }, + onUnload() { + this.safeDispatchBroadcast('stop'); + }, computed: { // 当前登录工号:后端 prep_operator_id 取的是当前员工工号(user.employees_id), // 必须与备货人 prep_operator_id 同口径,不能优先取账号 user.id @@ -151,6 +186,51 @@ } }, methods: { + safeDispatchBroadcast(action, payload) { + try { + const task = this.$store.dispatch(`broadcast/${action}`, payload); + if (task && typeof task.catch === 'function') { + task.catch(error => { + console.warn(`[stockPreparation] broadcast/${action} 调用失败:`, error); + }); + } + } catch (error) { + console.warn(`[stockPreparation] broadcast/${action} 调用异常:`, error); + } + }, + normalizeUniScanResult(scanResult) { + if (!scanResult) { + return ''; + } + if (typeof scanResult === 'string') { + return scanResult.trim(); + } + if (typeof scanResult.result === 'string') { + return scanResult.result.trim(); + } + if (Array.isArray(scanResult.result)) { + const firstResult = scanResult.result.find(item => item); + if (typeof firstResult === 'string') { + return firstResult.trim(); + } + if (firstResult && typeof firstResult.data === 'string') { + return firstResult.data.trim(); + } + } + if (typeof scanResult.data === 'string') { + return scanResult.data.trim(); + } + return ''; + }, + handleBroadcastResult(result) { + const rawCode = this.normalizeUniScanResult(result); + if (!rawCode) { + return; + } + this.keyword = rawCode; + this.currentPage = 1; + this.fetchList(); + }, async fetchList() { this.loading = true; try { @@ -161,8 +241,10 @@ const keyword = String(this.keyword || '').trim(); const where = {}; if (keyword) { - where.delivery_order_code = { - operator: 'like', + // 顶部搜索按运单号精确查询(与 order-review 列表一致) + where.waybill_codes = { + operator: 'eq', + type: 'text', value: keyword }; } @@ -290,9 +372,41 @@ if (!item || typeof item !== 'object') return '--'; return item.store_remark || '--'; }, + getWaybillCodes(item) { + const raw = item?.waybill_codes ?? item?.express_numbers; + if (Array.isArray(raw)) { + return raw.map(String).filter(Boolean); + } + if (typeof raw === 'string' && raw.trim()) { + return raw.split(/[,,]/).map(s => s.trim()).filter(Boolean); + } + return []; + }, + getWaybillText(item) { + const codes = this.getWaybillCodes(item); + return codes.length > 0 ? codes.join(' / ') : '--'; + }, getOrderCreateAt(item) { return this.formatDateTime(item?.created_at ?? item?.create_at); }, + getPrepImages(item) { + return this.normalizeImages(item?.images); + }, + normalizeImages(list) { + if (!Array.isArray(list)) return []; + return list + .filter(e => e && (e.url || e.file_id || e.fileId)) + .map(e => ({ url: e.url || e.path || e.image_url || '' })) + .filter(e => e.url); + }, + previewImages(images, index) { + const urls = (Array.isArray(images) ? images : []).map(e => e.url).filter(Boolean); + if (!urls.length) return; + uni.previewImage({ + urls, + current: urls[index] || urls[0] + }); + }, formatDateTime(value) { if (value === null || value === undefined || value === '') return '--'; const date = new Date(String(value).trim()); @@ -512,7 +626,7 @@ margin-left: 12rpx; padding: 4rpx 16rpx; border-radius: 8rpx; - font-size: 26rpx; + font-size: 36rpx; flex-shrink: 0; } @@ -554,6 +668,28 @@ word-break: break-all; } + .photo-row { + display: flex; + align-items: flex-start; + margin-bottom: 12rpx; + + .photo-thumbs { + flex: 1; + min-width: 0; + display: flex; + flex-wrap: wrap; + } + + .photo-thumb { + width: 120rpx; + height: 120rpx; + margin: 0 12rpx 12rpx 0; + border-radius: 8rpx; + background-color: #f5f7fa; + border: 1rpx solid #ebeef5; + } + } + .card-footer { display: flex; align-items: center; diff --git a/src/pages/B2BOperation/stockPreparationDetail.vue b/src/pages/B2BOperation/stockPreparationDetail.vue index f95671a..fc0b06e 100644 --- a/src/pages/B2BOperation/stockPreparationDetail.vue +++ b/src/pages/B2BOperation/stockPreparationDetail.vue @@ -39,7 +39,7 @@ - {{ it.item_name }}、{{ it.item_code }} + {{ formatItemName(it) }} 应拣 @@ -71,8 +71,7 @@ - {{ it.item_name || it.item_code || '--' }} - {{ it.item_code || '' }} + {{ formatItemName(it) }} 应拣: @@ -136,8 +135,60 @@ - 取消备货 - 完成备货 + + 取消备货 + + + {{ submitting ? '提交中...' : '完成备货' }} + + + + + + + + + + 取消备货 + 确认取消备货,取消后可由其他工号重新开始备货? + + 再想想 + 取消备货 + + + + + + + + + + + 完成备货 + 提交即完成备货并同步扣减库存,不可撤回;未齐套的商品行会被后端拦截。确认提交? + + 再想想 + 完成备货 + + + + + + + + + + + 提示 + {{ validateMessage }} + + 知道了 + + @@ -157,7 +208,14 @@ prepRemark: '', photoSyncTimer: null, autoSaveTimer: null, - lastSavedPackingKey: '' + lastSavedPackingKey: '', + allowDirectBack: false, + showCancelPrepConfirm: false, + showFinishPrepConfirm: false, + showValidateConfirm: false, + validateMessage: '', + pendingPrepRemark: '', + pendingPrepTotalBoxCount: 0 } }, computed: { @@ -204,7 +262,43 @@ uni.showToast({ title: '订单ID缺失', icon: 'none' }); } }, + onBackPress() { + // 提交/取消成功后放行,避免返回键再次拦截导致无法返回列表页 + if (this.allowDirectBack) { + return false; + } + // 确认弹窗已显示时,拦截本次返回(不关闭弹窗) + if (this.showCancelPrepConfirm || this.showFinishPrepConfirm || this.showValidateConfirm) { + return true; + } + // 备货中返回时,提示是否取消备货;其他状态直接返回 + if (this.canEdit) { + this.showCancelPrepConfirm = true; + return true; + } + return false; + }, methods: { + speakMessage(message, options = {}) { + const text = String(message || '').trim(); + if (!text) { + return; + } + const tools = this.$tools; + if (!tools || typeof tools.speakText !== 'function') { + return; + } + try { + const task = tools.speakText(text, options); + if (task && typeof task.catch === 'function') { + task.catch(error => { + console.warn('[stockPreparationDetail] 语音播报失败:', error); + }); + } + } catch (error) { + console.warn('[stockPreparationDetail] 语音播报异常:', error); + } + }, async fetchDetail() { this.loading = true; try { @@ -256,6 +350,12 @@ } return []; }, + formatItemName(item) { + const name = String(item?.item_name || '').trim(); + const code = String(item?.item_code || '').trim(); + if (name && code) return `${name}、${code}`; + return name || code || '--'; + }, getPickLocations(item) { const locs = item?.pick_locations; if (!Array.isArray(locs) || locs.length === 0) return ''; @@ -352,6 +452,40 @@ } return packingItems; }, + // 校验分箱:返回错误信息字符串,合法时返回空串 + validatePacking(options = {}) { + const allowInsufficient = !!options.allowInsufficient; + // 同一商品行 + 箱号不能重复 + for (const it of this.editItems) { + const seen = {}; + for (const box of (it.boxes || [])) { + const boxNo = String(box.box_no || '').trim(); + if (!boxNo) continue; + if (seen[boxNo]) { + return `商品「${this.formatItemName(it)}」箱号 ${boxNo} 重复,请修改`; + } + seen[boxNo] = true; + } + } + // 分箱数量合计需等于应拣数量(超量会被拦截) + for (const it of this.editItems) { + const plan = Number(it.plan_qty || 0); + let sum = 0; + for (const box of (it.boxes || [])) { + const quantity = Number(box.quantity); + if (Number.isFinite(quantity) && quantity > 0) { + sum += quantity; + } + } + if (sum > plan) { + return `商品「${this.formatItemName(it)}」分箱数量合计 ${sum} 超过应拣数量 ${plan},请调整`; + } + if (!allowInsufficient && sum < plan) { + return `商品「${this.formatItemName(it)}」分箱数量合计 ${sum} 小于应拣数量 ${plan},请补齐`; + } + } + return ''; + }, savePacking() { const packingItems = this.buildPackingItems(); if (packingItems.length === 0) { @@ -366,6 +500,12 @@ }); return; } + const error = this.validatePacking(); + if (error) { + this.validateMessage = error; + this.showValidateConfirm = true; + return; + } this.doUpdatePacking(packingItems); }, handleBoxInputBlur() { @@ -379,6 +519,9 @@ }, autoSavePacking() { if (this.saving || this.submitting || !this.editing) return; + // 重复箱号或超量时不自动保存(允许不足,便于分箱进行中保存进度) + const error = this.validatePacking({ allowInsufficient: true }); + if (error) return; const packingItems = this.buildPackingItems(); if (packingItems.length === 0) return; const key = JSON.stringify(packingItems); @@ -437,15 +580,27 @@ uni.showToast({ title: '总箱数无效', icon: 'none' }); return; } - uni.showModal({ - title: '提示', - content: '提交即完成备货并同步扣减库存,不可撤回;未齐套的商品行会被后端拦截。确认提交?', - success: (res) => { - if (res.confirm) { - this.doFinishPrep(remark, totalBoxCount); - } - } - }); + const packingError = this.validatePacking(); + if (packingError) { + this.speakMessage(packingError); + this.validateMessage = packingError; + this.showValidateConfirm = true; + return; + } + this.pendingPrepRemark = remark; + this.pendingPrepTotalBoxCount = totalBoxCount; + this.showFinishPrepConfirm = true; + }, + handleFinishPrepConfirmCancel() { + this.showFinishPrepConfirm = false; + }, + handleFinishPrepConfirmOk() { + this.showFinishPrepConfirm = false; + this.doFinishPrep(this.pendingPrepRemark, this.pendingPrepTotalBoxCount); + }, + handleValidateConfirmClose() { + this.showValidateConfirm = false; + this.validateMessage = ''; }, async doFinishPrep(remark, totalBoxCount) { this.submitting = true; @@ -459,11 +614,14 @@ if (response?.flag === 'failure') { const msg = String(response?.message || response?.msg || data?.message || '提交失败'); uni.showToast({ title: msg, icon: 'none', duration: 2500 }); + this.speakMessage(msg); return; } uni.showToast({ title: '备货已完成', icon: 'success' }); + this.speakMessage('备货已完成'); + this.allowDirectBack = true; setTimeout(() => { - uni.navigateBack(); + this.navigateBackSafely(); }, 800); } catch (error) { console.error('[stockPreparationDetail] finishB2bPrep error:', error); @@ -475,29 +633,20 @@ handleBack() { // 备货中返回时,提示是否取消备货;其他状态直接返回 if (this.canEdit) { - uni.showModal({ - title: '提示', - content: '确认取消备货?', - success: (res) => { - if (res.confirm) { - this.doCancelPrep(); - } - } - }); + this.showCancelPrepConfirm = true; return; } uni.navigateBack({ delta: 1 }); }, handleCancelPrep() { - uni.showModal({ - title: '提示', - content: '确认取消备货?', - success: (res) => { - if (res.confirm) { - this.doCancelPrep(); - } - } - }); + this.showCancelPrepConfirm = true; + }, + handleCancelPrepConfirmCancel() { + this.showCancelPrepConfirm = false; + }, + handleCancelPrepConfirmOk() { + this.showCancelPrepConfirm = false; + this.doCancelPrep(); }, async doCancelPrep() { uni.showLoading({ title: '取消备货中...' }); @@ -507,11 +656,14 @@ if (response?.flag === 'failure') { const msg = String(response?.message || response?.msg || data?.message || '取消备货失败'); uni.showToast({ title: msg, icon: 'none', duration: 2500 }); + this.speakMessage(msg); return; } uni.showToast({ title: '已取消备货', icon: 'success' }); + this.speakMessage('已取消备货'); + this.allowDirectBack = true; setTimeout(() => { - uni.navigateBack(); + this.navigateBackSafely(); }, 800); } catch (error) { console.error('[stockPreparationDetail] cancelB2bPrep error:', error); @@ -519,6 +671,35 @@ } finally { uni.hideLoading(); } + }, + navigateBackSafely() { + this.allowDirectBack = true; + let settled = false; + let retried = false; + const doBack = (label) => { + uni.navigateBack({ + delta: 1, + success: () => { + settled = true; + console.log(`[stockPreparationDetail] navigateBack ${label}成功`); + }, + fail: (err) => { + console.warn(`[stockPreparationDetail] navigateBack ${label}失败:`, err); + if (!retried) { + retried = true; + setTimeout(() => doBack('重试'), 300); + } + } + }); + }; + doBack('首次'); + // 兜底:success/fail 都未触发(静默失效)时,400ms 后重试一次 + setTimeout(() => { + if (!settled) { + console.warn('[stockPreparationDetail] navigateBack 静默失效,重试'); + doBack('静默重试'); + } + }, 400); } } } @@ -574,7 +755,7 @@ .photo-card__title { font-size: 30rpx; - font-weight: 600; + font-weight: bold; color: #303133; } @@ -596,7 +777,7 @@ .total-box-value { font-size: 34rpx; - font-weight: 600; + font-weight: bold; color: #303133; } @@ -616,7 +797,7 @@ .remark-card__title { font-size: 30rpx; - font-weight: 600; + font-weight: bold; color: #303133; } @@ -689,7 +870,7 @@ .summary-value { flex: 1; min-width: 0; - font-size: 34rpx; + font-size: 36rpx; color: #303133; word-break: break-all; } @@ -739,18 +920,11 @@ .goods-item__name { flex: 1; min-width: 0; - font-size: 34rpx; - font-weight: 600; + font-size: 36rpx; + font-weight: bold; color: #303133; } - .goods-item__code { - flex-shrink: 0; - margin-left: 12rpx; - font-size: 26rpx; - color: #909399; - } - .goods-item__row { display: flex; align-items: center; @@ -764,7 +938,7 @@ } .goods-item__value { - font-size: 34rpx; + font-size: 36rpx; color: #303133; margin-right: 20rpx; } @@ -794,7 +968,7 @@ margin-right: 12rpx; margin-bottom: 6rpx; padding: 2rpx 12rpx; - font-size: 24rpx; + font-size: 36rpx; color: #2979ff; background-color: #ecf5ff; border-radius: 6rpx; @@ -802,7 +976,7 @@ .goods-item__location { flex: 1; - font-size: 34rpx; + font-size: 36rpx; color: #303133; word-break: break-all; } @@ -818,20 +992,48 @@ padding: 16rpx 24rpx; background-color: #ffffff; border-top: 1rpx solid #ebeef5; + } - ::v-deep .u-button { - flex: 1; - font-size: 36rpx; - } + .bottom-bar-btn { + flex: 1; + height: 88rpx; + border-radius: 16rpx; + display: flex; + align-items: center; + justify-content: center; + } - ::v-deep .u-button + .u-button { - margin-left: 20rpx; - } + .bottom-bar-btn + .bottom-bar-btn { + margin-left: 20rpx; + } - ::v-deep .u-button__text, - ::v-deep .u-button__loading-text { - font-size: 36rpx !important; - } + .bottom-bar-btn--cancel { + background: #fff1f0; + border: 2rpx solid #ffccc7; + } + + .bottom-bar-btn--complete { + background: #2979ff; + border: 2rpx solid #2979ff; + } + + .bottom-bar-btn__text { + font-size: 34rpx; + font-weight: 500; + line-height: 1; + } + + .bottom-bar-btn__text--cancel { + color: #f56c6c; + } + + .bottom-bar-btn__text--complete { + color: #ffffff; + } + + .bottom-bar-btn--disabled { + opacity: 0.6; + pointer-events: none; } .nav-save-btn { @@ -892,4 +1094,100 @@ font-size: 36rpx; color: #2979ff; } + + .confirm-mask { + position: fixed; + left: 0; + top: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.48); + display: flex; + align-items: center; + justify-content: center; + z-index: 10095; + padding: 60rpx; + box-sizing: border-box; + } + + .confirm-dialog { + position: relative; + width: 100%; + max-width: 620rpx; + background: #ffffff; + border-radius: 24rpx; + padding: 40rpx 36rpx 36rpx; + box-sizing: border-box; + box-shadow: 0 24rpx 80rpx rgba(0, 0, 0, 0.18); + display: flex; + flex-direction: column; + align-items: center; + } + + .confirm-title { + font-size: 42rpx; + font-weight: bold; + color: #303133; + text-align: center; + } + + .confirm-close { + position: absolute; + top: 20rpx; + right: 20rpx; + width: 48rpx; + height: 48rpx; + display: flex; + align-items: center; + justify-content: center; + z-index: 1; + } + + .confirm-content { + margin-top: 32rpx; + font-size: 36rpx; + line-height: 1.6; + color: #606266; + text-align: center; + } + + .confirm-actions { + width: 100%; + margin-top: 36rpx; + display: flex; + align-items: center; + } + + .confirm-btn { + flex: 1; + height: 88rpx; + display: flex; + align-items: center; + justify-content: center; + border-radius: 16rpx; + font-size: 36rpx; + font-weight: 500; + } + + .confirm-btn--cancel { + background: #f5f7fa; + color: #606266; + } + + .confirm-btn--ok { + margin-left: 24rpx; + background: #f56c6c; + color: #ffffff; + } + + .confirm-btn--primary { + margin-left: 24rpx; + background: #2979ff; + color: #ffffff; + } + + .confirm-btn--single { + background: #2979ff; + color: #ffffff; + }