From 42fee4319db09a24c1468b5254fe137631c6347e Mon Sep 17 00:00:00 2001 From: zm2000 <18386612143@163.com> Date: Sat, 25 Apr 2026 17:15:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(receiving):=20=E5=AE=8C=E5=96=84=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=E6=B5=81=E7=A8=8B=E8=AF=AD=E9=9F=B3=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../receiving/components/detail-container.vue | 23 ++ .../receiving/components/info-container.vue | 32 ++- pages/work/storage/receiving/receiving.vue | 62 ++++- .../storage/receiving/receivingCreate.vue | 156 ++++++++++--- .../storage/receiving/receivingDetail.vue | 213 ++++++++++++++++-- 5 files changed, 429 insertions(+), 57 deletions(-) diff --git a/pages/work/storage/receiving/components/detail-container.vue b/pages/work/storage/receiving/components/detail-container.vue index 56d41f9..d5b2278 100644 --- a/pages/work/storage/receiving/components/detail-container.vue +++ b/pages/work/storage/receiving/components/detail-container.vue @@ -167,6 +167,28 @@ this.$store.dispatch('broadcast/stop'); }, 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('[ReceivingDetail-DetailContainer] 语音播报失败:', error); + }); + } + } catch (error) { + console.warn('[ReceivingDetail-DetailContainer] 语音播报异常:', error); + } + }, // === 事件处理方法 === truncateText(text, length = 20) { if (!text) return ''; @@ -326,6 +348,7 @@ if(this.isSpaceInput){ this.$emit('searchSpace', data.data); }else{ + this.speakMessage('商品条码扫描成功'); this.$emit('tryGetStock', data.data); } }, diff --git a/pages/work/storage/receiving/components/info-container.vue b/pages/work/storage/receiving/components/info-container.vue index 1188d99..f7c3edd 100644 --- a/pages/work/storage/receiving/components/info-container.vue +++ b/pages/work/storage/receiving/components/info-container.vue @@ -13,7 +13,7 @@ {{ pendingStoreName || '请选择货主绑定' }} @@ -204,6 +204,32 @@ } }, 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('[ReceivingDetail-InfoContainer] 语音播报失败:', error); + }); + } + } catch (error) { + console.warn('[ReceivingDetail-InfoContainer] 语音播报异常:', error); + } + }, + openStorePicker() { + this.speakMessage('选择货主'); + this.showStorePicker = true; + }, async loadStoreList() { try { const res = await this.$http('common.store', {}); @@ -221,11 +247,14 @@ return; } + this.speakMessage('请确认货主绑定'); + uni.showModal({ title: '货主绑定', content: `是否将当前收货单绑定到货主【${option.label}】?绑定后不可更改。`, success: async ({ confirm }) => { if (!confirm) { + this.speakMessage('已取消'); return; } @@ -253,6 +282,7 @@ if (res && res.code === 200) { this.pendingStoreId = option.value; this.pendingStoreName = option.label; + this.speakMessage('绑定成功'); uni.showToast({ title: '绑定成功', icon: 'success' diff --git a/pages/work/storage/receiving/receiving.vue b/pages/work/storage/receiving/receiving.vue index 9857508..67910ad 100644 --- a/pages/work/storage/receiving/receiving.vue +++ b/pages/work/storage/receiving/receiving.vue @@ -123,7 +123,7 @@ - + {{where.startDate}} - {{where.endDate}} @@ -205,6 +205,8 @@ loading: false, storeId:null, refreshing: false, + pageChangeSilentVoice: true, + nextListVoiceDelay: 0, pageSize: 20, currentPage: 1, totalItems: 0, @@ -281,8 +283,13 @@ watch: { currentPage(newval) { console.log('页码变化:', newval); + const silentVoice = this.pageChangeSilentVoice; + const voiceDelay = Number(this.nextListVoiceDelay || 0); + this.pageChangeSilentVoice = true; + this.nextListVoiceDelay = 0; this.loadReceivingList({ - silentVoice: false + silentVoice, + voiceDelay }); } }, @@ -421,6 +428,15 @@ // 设置日期范围 setDateRange(type) { + const quickDateVoiceMap = { + today: '今日', + yesterday: '昨日', + beforeYesterday: '前日', + last3days: '3天内', + week: '本周', + month: '本月' + }; + this.speakReceivingMessage(quickDateVoiceMap[type] || '筛选日期'); this.dateModel = type; const dateRange = this.getDateRange(type); this.where.startDate = dateRange.startDate; @@ -531,6 +547,7 @@ // 加载收货列表 async loadReceivingList(options = {}) { const silentVoice = !!(options && options.silentVoice); + const voiceDelay = Number((options && options.voiceDelay) || 0); if (this.loading) return; this.loading = true; @@ -598,7 +615,14 @@ } if (!silentVoice) { - this.speakReceivingMessage(this.getReceivingListVoiceText()); + const resultVoiceText = this.getReceivingListVoiceText(); + if (voiceDelay > 0) { + setTimeout(() => { + this.speakReceivingMessage(resultVoiceText); + }, voiceDelay); + } else { + this.speakReceivingMessage(resultVoiceText); + } } } } catch (error) { @@ -608,7 +632,13 @@ icon: 'error' }); if (!silentVoice) { - this.speakReceivingMessage('加载收货列表失败,请重试'); + if (voiceDelay > 0) { + setTimeout(() => { + this.speakReceivingMessage('加载收货列表失败,请重试'); + }, voiceDelay); + } else { + this.speakReceivingMessage('加载收货列表失败,请重试'); + } } } finally { this.loading = false; @@ -645,12 +675,14 @@ return typeMap[status] || 'info'; }, handleShowStore(){ + this.speakReceivingMessage('选择货主'); this.showStore = true; console.log("显示选择货主") }, // 搜索处理 handleSearch() { if (this.currentPage !== 1) { + this.pageChangeSilentVoice = false; this.currentPage = 1; return; } @@ -663,6 +695,7 @@ changeStatus(status) { this.activeStatus = status; if (this.currentPage !== 1) { + this.pageChangeSilentVoice = false; this.currentPage = 1; return; } @@ -675,6 +708,7 @@ onRefresh() { this.refreshing = true; if (this.currentPage !== 1) { + this.pageChangeSilentVoice = false; this.currentPage = 1; return; } @@ -685,11 +719,17 @@ // 显示筛选弹窗 showFilterPopup() { + this.speakReceivingMessage('筛选'); this.filterVisible = true; }, + openDateFilter() { + this.speakReceivingMessage('筛选日期'); + this.showSelectDate = true; + }, // 重置筛选 resetFilter() { + this.speakReceivingMessage('重置'); this.where = { store: 0, startDate: this.formatDate(new Date()), @@ -703,18 +743,23 @@ // 应用筛选 applyFilter() { + this.speakReceivingMessage('确定'); this.filterVisible = false; + this.nextListVoiceDelay = 700; if (this.currentPage !== 1) { + this.pageChangeSilentVoice = false; this.currentPage = 1; return; } this.loadReceivingList({ - silentVoice: false + silentVoice: false, + voiceDelay: 700 }); }, // 新建收货 createReceiving() { + this.speakReceivingMessage('新建收货'); this.$store.dispatch('broadcast/stop'); uni.navigateTo({ url: './receivingCreate', @@ -765,6 +810,13 @@ }, handlePageChange(page) { + const previousPage = Number(this.currentPage || 1); + if (page < previousPage) { + this.speakReceivingMessage('上一页'); + } else if (page > previousPage) { + this.speakReceivingMessage('下一页'); + } + this.pageChangeSilentVoice = true; this.currentPage = page; } } diff --git a/pages/work/storage/receiving/receivingCreate.vue b/pages/work/storage/receiving/receivingCreate.vue index e12a9ba..73ecb37 100644 --- a/pages/work/storage/receiving/receivingCreate.vue +++ b/pages/work/storage/receiving/receivingCreate.vue @@ -9,7 +9,7 @@ 基础信息 - + {{ storeName || '请选择货主' }} @@ -194,6 +194,111 @@ }, methods: { + normalizeSpeechText(message) { + const rawText = String(message || '').trim(); + if (!rawText) { + return ''; + } + + const digitMap = { + '0': '零', + '1': '一', + '2': '二', + '3': '三', + '4': '四', + '5': '五', + '6': '六', + '7': '七', + '8': '八', + '9': '九' + }; + + const normalizeCodeSegment = (segment) => { + return segment + .split('-') + .map(part => String(part || '') + .split('') + .map(char => (digitMap[char] || char)) + .join('')) + .join('的'); + }; + + return rawText.replace(/([A-Za-z0-9]+(?:-[A-Za-z0-9]+)+)/g, normalizeCodeSegment); + }, + speakMessage(message, options = {}) { + const text = this.normalizeSpeechText(message); + 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('[ReceivingCreate] 语音播报失败:', error); + }); + } + } catch (error) { + console.warn('[ReceivingCreate] 语音播报异常:', error); + } + }, + stopSpeak() { + const tools = this.$tools; + if (!tools || typeof tools.stopSpeak !== 'function') { + return; + } + + try { + tools.stopSpeak(); + } catch (error) { + console.warn('[ReceivingCreate] 停止语音播报异常:', error); + } + }, + showToastMessage(title, icon = 'none', options = {}) { + const message = String(title || '').trim(); + if (!message) { + return; + } + + uni.showToast({ + title: message, + icon + }); + + if (options.speak !== false) { + this.speakMessage(options.speakText || message, options.voiceOptions || {}); + } + }, + extractErrorMessage(error, fallback = '操作失败') { + if (!error) { + return fallback; + } + + if (typeof error === 'string') { + return error; + } + + if (typeof error.message === 'string' && error.message.trim()) { + return error.message.trim(); + } + + if (Array.isArray(error) && error.length) { + const firstError = error[0]; + if (typeof firstError === 'string') { + return firstError; + } + if (firstError && typeof firstError.message === 'string') { + return firstError.message; + } + } + + return fallback; + }, getPlatformInfo() { const systemInfo = typeof uni.getSystemInfoSync === 'function' ? uni.getSystemInfoSync() : {}; return { @@ -385,9 +490,8 @@ } this.formData.license_plate = licensePlate; - uni.showToast({ - title: '识别成功', - icon: 'success' + this.showToastMessage('识别成功', 'success', { + speakText: `识别成功,车牌:${licensePlate}` }); } catch (error) { const errMsg = String(error?.errMsg || error?.message || error || '').toLowerCase(); @@ -395,10 +499,7 @@ return; } - uni.showToast({ - title: (error && error.message) || '车牌识别失败', - icon: 'none' - }); + this.showToastMessage((error && error.message) || '车牌识别失败'); } finally { this.recognizingPlate = false; uni.hideLoading(); @@ -440,14 +541,12 @@ success: (res) => { const rawCode = this.normalizeUniScanResult(res); if (!rawCode) { - uni.showToast({ - title: '未识别到有效内容', - icon: 'none' - }); + this.showToastMessage('未识别到有效内容'); return; } this.formData.tracking_number = rawCode; + this.speakMessage('扫描成功'); }, fail: (error) => { const errMsg = String(error?.errMsg || '').toLowerCase(); @@ -455,10 +554,7 @@ return; } - uni.showToast({ - title: '扫码失败,请重试', - icon: 'none' - }); + this.showToastMessage('扫码失败,请重试'); } }); }, @@ -499,11 +595,7 @@ this.formData.video_device_id = deviceCode; // 可选:给用户一个提示 - uni.showToast({ - title: `已扫描录像设备: ${deviceCode}`, - icon: 'success', - duration: 2000 - }); + this.showToastMessage(`已扫描录像设备: ${deviceCode}`, 'success'); } // 如果没有提取到设备编号,也直接忽略,不提示用户 return; @@ -511,6 +603,7 @@ if (this.formData.delivery_method === 'express') { this.formData.tracking_number = scanText; + this.speakMessage('扫描成功'); } } }, @@ -526,10 +619,7 @@ const result = await this.$http("storage.receiving.create",submitData); if(result.code==200){ - uni.showToast({ - title: '创建成功', - icon: 'success' - }); + this.showToastMessage('创建成功', 'success'); }else{ throw new Error("创建失败"+result.message); @@ -541,16 +631,14 @@ }, 1500); } catch (error) { - uni.showToast({ - title: '创建失败'+error, - icon: 'error' - }); + this.showToastMessage(this.extractErrorMessage(error, '创建失败')); } finally { this.submitting = false; } }, handleReset() { + this.speakMessage('请确认重置表单'); uni.showModal({ title: '确认重置', content: '确定要重置所有表单数据吗?', @@ -559,11 +647,19 @@ this.$refs.formRef.resetFields(); this.storeName = "不设置"; this.formData.store_id = null; + this.showToastMessage('已重置表单'); + } else { + this.speakMessage('已取消'); } } }); }, + openStorePicker() { + this.speakMessage('选择货主'); + this.showStorePicker = true; + }, + handleStoreChange(option) { if (!option) { this.storeName = "不设置"; @@ -588,9 +684,11 @@ }, onHide() { this.$store.dispatch('broadcast/pause'); + this.stopSpeak(); }, onUnload() { this.$store.dispatch('broadcast/stop'); + this.stopSpeak(); } }; diff --git a/pages/work/storage/receiving/receivingDetail.vue b/pages/work/storage/receiving/receivingDetail.vue index 144af8f..8bb12ae 100644 --- a/pages/work/storage/receiving/receivingDetail.vue +++ b/pages/work/storage/receiving/receivingDetail.vue @@ -151,6 +151,87 @@ }, methods: { + normalizeSpeechText(message) { + const rawText = String(message || '').trim(); + if (!rawText) { + return ''; + } + + const digitMap = { + '0': '零', + '1': '一', + '2': '二', + '3': '三', + '4': '四', + '5': '五', + '6': '六', + '7': '七', + '8': '八', + '9': '九' + }; + + const normalizeCodeSegment = (segment) => { + return segment + .split('-') + .map(part => String(part || '') + .split('') + .map(char => (digitMap[char] || char)) + .join('')) + .join('的'); + }; + + return rawText.replace(/([A-Za-z0-9]+(?:-[A-Za-z0-9]+)+)/g, normalizeCodeSegment); + }, + speakMessage(message, options = {}) { + const text = this.normalizeSpeechText(message); + 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('[ReceivingDetail] 语音播报失败:', error); + }); + } + } catch (error) { + console.warn('[ReceivingDetail] 语音播报异常:', error); + } + }, + stopSpeak() { + const tools = this.$tools; + if (!tools || typeof tools.stopSpeak !== 'function') { + return; + } + + try { + tools.stopSpeak(); + } catch (error) { + console.warn('[ReceivingDetail] 停止语音播报异常:', error); + } + }, + showToastMessage(title, icon = 'none', options = {}) { + const message = String(title || '').trim(); + if (!message) { + return; + } + + uni.showToast({ + title: message, + icon, + duration: options.duration || 1500 + }); + + if (options.speak !== false) { + this.speakMessage(options.speakText || message, options.voiceOptions || {}); + } + }, getTodayStartTimestamp() { const today = new Date(); today.setHours(0, 0, 0, 0); @@ -222,6 +303,41 @@ return invalidDetail || null; }, + validateReceivingBaseFields() { + const detailList = this.details || []; + + // 1) 先校验商品名称 + const invalidNameDetail = detailList.find(detail => !String(detail?.product_name || '').trim()); + if (invalidNameDetail) { + return { + detail: invalidNameDetail, + message: `${invalidNameDetail.product_name || '当前商品'}缺少商品名称` + }; + } + + // 2) 再校验实际数量是否为空 + const invalidEmptyQtyDetail = detailList.find(detail => !String(detail?.actual_quantity ?? '').trim()); + if (invalidEmptyQtyDetail) { + return { + detail: invalidEmptyQtyDetail, + message: `${invalidEmptyQtyDetail.product_name || '当前商品'}缺少实际数量` + }; + } + + // 3) 最后校验实际数量是否大于0 + const invalidQtyValueDetail = detailList.find(detail => { + const quantityValue = Number(String(detail?.actual_quantity ?? '').trim()); + return !Number.isFinite(quantityValue) || quantityValue <= 0; + }); + if (invalidQtyValueDetail) { + return { + detail: invalidQtyValueDetail, + message: `${invalidQtyValueDetail.product_name || '当前商品'}实际数量需大于0` + }; + } + + return null; + }, // 初始化数据 async initData() { await this.loadReceivingInfo(); @@ -274,14 +390,15 @@ try { // 货主确认逻辑 if (this.receivingInfo.store_id == null && data.system_product_id) { + this.speakMessage('请确认货主'); const confirm = await this.confirmStoreOwner(); if (!confirm) { - uni.showToast({ - title: '已取消', - icon: 'none' + this.showToastMessage('已取消', 'none', { + speakText: '已取消' }); return; } + this.speakMessage('已确认'); } // 调用API更新 @@ -362,6 +479,8 @@ return; } + this.speakMessage('请确认删除'); + uni.showModal({ title: '确认删除', content: `确定要删除商品"${detailToDelete.product_name}"吗?`, @@ -374,9 +493,8 @@ }); if (result.code === 200) { - uni.showToast({ - title: '删除成功', - icon: 'success' + this.showToastMessage('删除成功', 'success', { + speakText: '删除成功' }); // 删除后统一以服务端最新数据重建列表与选中态,避免残留旧引用 @@ -411,6 +529,10 @@ icon: 'error' }); } + } else { + this.showToastMessage('已取消', 'none', { + speakText: '已取消' + }); } } }); @@ -423,9 +545,8 @@ }); if (result.code === 200) { - uni.showToast({ - title: '添加成功', - icon: 'success' + this.showToastMessage('添加成功', 'success', { + speakText: '添加成功' }); if (result.data.selectId) { @@ -516,6 +637,20 @@ }, async completeReceiving() { this.showComplete = false; + const baseValidation = this.validateReceivingBaseFields(); + if (baseValidation) { + this.currentTab = 1; + this.selectedDetail = baseValidation.detail; + const message = baseValidation.message || '商品信息不完整'; + this.speakMessage(message); + uni.showModal({ + title: '商品信息不完整', + content: message, + showCancel: false + }); + return; + } + const shelfLifeValidation = this.validateShelfLifeRequiredFields(); if (shelfLifeValidation) { this.currentTab = 1; @@ -539,6 +674,34 @@ return; } try { + const tools = this.$tools; + if (tools && typeof tools.speakText === 'function') { + try { + const speakTask = tools.speakText('请确认完成收货', { + force: true, + minInterval: 0 + }); + if (speakTask && typeof speakTask.catch === 'function') { + speakTask.catch(error => { + console.warn('[ReceivingDetail] 完成收货前语音播报失败:', error); + }); + } + } catch (error) { + console.warn('[ReceivingDetail] 完成收货前语音播报失败:', error); + } + } else { + this.speakMessage('请确认完成收货', { + force: true, + minInterval: 0 + }); + } + + uni.showToast({ + title: '请确认完成收货', + icon: 'none', + duration: 800 + }); + await new Promise(resolve => setTimeout(resolve, 900)); // 1. 显示确认弹窗 const confirmResult = await uni.showModal({ title: '完成收货', @@ -553,6 +716,9 @@ // 修正:直接使用confirmResult.confirm if (!confirmResult[1].confirm) { + this.showToastMessage('已取消', 'none', { + speakText: '已取消' + }); return; } @@ -576,11 +742,7 @@ // 根据你的后端响应结构调整 if (res.code === 200 || res.success) { // 成功提示 - uni.showToast({ - title: '收货完成成功', - icon: 'success', - duration: 1500 - }); + this.showToastMessage('收货完成成功', 'success'); // 延迟跳转 setTimeout(() => { @@ -628,15 +790,14 @@ uni.hideLoading(); console.error('完成收货失败:', error); this.currentTab = 1; - uni.showToast({ - title: error.message || '操作失败,请稍后重试', - icon: 'none', - duration: 3000 + this.showToastMessage(error.message || '操作失败,请稍后重试', 'none', { + duration: 3000 }); } }, async cancel() { try { + this.speakMessage('请确认作废'); // 1. 显示确认弹窗 const confirmResult = await uni.showModal({ title: '整单作废', @@ -648,6 +809,9 @@ }); console.log(confirmResult); if (!confirmResult[1].confirm) { + this.showToastMessage('已取消', 'none', { + speakText: '已取消' + }); return; } @@ -670,10 +834,8 @@ throw new Error("取消失败"+res.message) } // 5. 显示成功提示 - uni.showToast({ - title: '取消成功', - icon: 'success', - duration: 1500 + this.showToastMessage('取消成功', 'success', { + speakText: '取消成功' }); // 6. 延迟跳转,让用户看到成功提示 @@ -816,6 +978,7 @@ }; console.log("更新仓位",updateData); await this.handleSelectDetailChange(updateData); + this.speakMessage('库位条码扫描成功'); } else if (spaceInfo.total > 1) { console.log("多个仓位",spaceInfo.data); this.showSpaceList = true; @@ -841,6 +1004,12 @@ this.$nextTick(() => { this.updateReceivingListHeaderTop(); }); + }, + onHide() { + this.stopSpeak(); + }, + onUnload() { + this.stopSpeak(); } };