diff --git a/core/request/apis.js b/core/request/apis.js index a0e8dac..45ad266 100644 --- a/core/request/apis.js +++ b/core/request/apis.js @@ -164,6 +164,13 @@ export default { auth: false, method: "POST", isSystemApi: true + }, + // 工作台班次打包统计(免登录、免鉴权,以工作台 token 鉴权):统计窗口为本地时间当日 08:00 至次日 08:00 + getWorkbenchCount: { + path: "workbench.getWorkbenchCount", + auth: false, + method: "POST", + isSystemApi: true } }, storage: { diff --git a/pages/packing/packMode.vue b/pages/packing/packMode.vue index 242d432..c707846 100644 --- a/pages/packing/packMode.vue +++ b/pages/packing/packMode.vue @@ -4,9 +4,13 @@ - - - 退出 + + + + + + 今日打包 + 打包模式 @@ -15,7 +19,7 @@ @@ -32,7 +36,7 @@ class="order-query__input" v-model="orderBarcode" :focus="orderInputFocus" - placeholder="扫描/输入运单号查询" + :placeholder="orderScanPlaceholder" placeholder-style="color:#c0c4cc;font-size:34rpx" @confirm="handleOrderQueryConfirm" /> @@ -84,7 +88,16 @@ 包材 {{ packageMaterialName || '--' }} - 商品总数 {{ orderItemsTotal }} + + + + 商品种类 + {{ orderItemsKind }} + + + 商品总数 + {{ orderItemsTotal }} + @@ -171,7 +184,23 @@ - + + + + 在线操作员列表(一个打包台支持多人,仅展示与下线) + {{ workbenchMembers.length }}人 + + + + + {{ m.user_name || '--' }} + + 下线 + + + + + - + - - 移除操作员 - - {{ removeOperatorHint }} - - - {{ op.userName || '--' }} - - - + + 下线操作员 + + 确认将「{{ offlineMember && offlineMember.user_name ? offlineMember.user_name : '--' }}」下线?下线后需重新扫码绑定。 - - 取消 - 确定 + + 取消 + 下线 + + + + + + + + 今日打包 + + + 团购波次 + {{ todayWaveCount }} + + + 团购订单 + {{ todayGroupOrderCount }} + + + 散单 + {{ todaySingleCount }} + + + 团散 + {{ todayRatio !== null ? todayRatio : '—' }} + + + 均件数 + {{ todayAvgPiece !== null ? todayAvgPiece : '—' }} + @@ -349,6 +399,7 @@ export default { userDrawerOpen: false, // 订单查询(workbench.queryOrder) orderBarcode: '', + lastScannedCode: '', // 上一次扫描内容(连续相同跳过,防扫码枪重复触发) orderInputFocus: false, orderQuerying: false, orderQueryState: '', // '' | loading | success | error @@ -359,6 +410,7 @@ export default { finishPacking: false, // finishPack 完成打包请求防重入锁 hasActivePack: false, // 该工作台是否存在未结束打包任务(status<2):退出/解绑前自动上报打包完成 activePackIdentity: '', // 当前「打包中」订单唯一标识:团单为 wave_no,散单为 waybill_code(重复查单去重用) + activePackIsSandan: null, // 当前「打包中」订单类型:true=散单 / false=团单 / null=无进行中任务(重复查单需类型一致) packRestored: false, // 重进后从服务端恢复的「打包中」态(跳过拦截/已打包/预检,直接展示进行中任务) // 团购核实:商品行已扫计数(key=商品行id/序号 → 已扫次数),达 plan_qty 视为已核实 groupVerified: {}, @@ -371,10 +423,16 @@ export default { cancelVerifyPopupOpen: false, // 退出工作台弹窗 exitPopupOpen: false, - // 移除操作员二次确认弹窗 - removeOperatorPopupOpen: false, - // 移除弹窗中已勾选的操作员成员行 id(多选) - removeSelectedIds: [] + // 下线操作员二次确认弹窗 + offlinePopupOpen: false, + offlineMember: null, // 待下线成员 { id, user_name } + // 今日打包统计(workbench.getWorkbenchCount) + todayWaveCount: 0, // 团购波次 + todayGroupOrderCount: 0, // 团购订单 + todaySingleCount: 0, // 散单 + todayRatio: null, // 团散比(仅个人工作台返回) + todayAvgPiece: null, // 均件数(仅个人工作台返回) + todayPackPanelOpen: false // 今日打包统计面板开关 } }, // 团购:全部商品核实完成后自动提交开始打包(每次查询仅自动提交一次) @@ -403,19 +461,18 @@ export default { if (this.workbenchType === 'group') return '团体工作台'; return this.workbenchType ? this.workbenchType : '--'; }, - // 顶部操作员按钮文案:单人显示姓名,多人显示「姓名 等N人」 - boundOperatorText() { + // 是否个人工作台(仅个人工作台显示「团散 / 均件数」) + isPersonalWorkbench() { + return this.workbenchType === 'personal'; + }, + // 顶部操作员按钮文案:单人显示该操作员名称,多人显示「N人」 + topbarOperatorText() { const list = this.boundOperators; if (!list.length) return '未绑定'; - const name = String(list[0] && list[0].userName || '').trim() || '已绑定'; - return list.length > 1 ? `${name} 等${list.length}人` : name; - }, - // 移除操作员二次确认弹窗文案(默认「已选 0 名」,与勾选后文案结构一致,避免页面跳动) - removeOperatorHint() { - const list = this.boundOperators; - if (!list.length) return '当前没有已绑定的操作员'; - const count = this.removeSelectedIds.length; - return `已选 ${count} 名操作员,移除后需重新扫码绑定。`; + if (list.length === 1) { + return String(list[0] && list[0].userName || '').trim() || '已绑定'; + } + return `${list.length}人`; }, // 查询结果是否为散单 orderQueryIsSandan() { @@ -511,6 +568,14 @@ export default { } return 0; }, + // 商品种类数(order.items_count,缺省按 items 数量) + orderItemsKind() { + const r = this.orderQueryResult; + const count = r?.order && (r.order.items_count !== undefined && r.order.items_count !== null) ? r.order.items_count : null; + if (count !== null) return count; + if (Array.isArray(r?.items)) return r.items.length; + return 0; + }, // 团购订单商品明细(查询结果 items) groupItems() { const r = this.orderQueryResult; @@ -551,9 +616,11 @@ export default { const items = this.groupItems; return !!this.orderQueryResult && items.length > 0 && this.groupVerifiedCount < items.length; }, - // 输入框占位:团购核实时提示扫商品条码 - groupScanPlaceholder() { - return (this.groupVerifyingActive && !this.orderBlocked) ? '扫描商品条码核实' : '扫描/输入运单号查询'; + // 输入框占位:按实际流程提示(未绑定操作员 → 扫工牌绑定;团购核实中 → 扫商品条码;否则 → 运单查询) + orderScanPlaceholder() { + if (!this.boundOperators.length) return '扫描/输入工牌绑定操作员'; + if (this.groupVerifyingActive && !this.orderBlocked) return '扫描商品条码核实'; + return '扫描/输入运单号查询'; } }, onLoad(options) { @@ -565,6 +632,8 @@ export default { // 进入打包模式:重新拉取工作台信息(同时校验本地工作台 token 是否仍有效) if (this.bound) { this.fetchWorkbenchInfo(); + // 进入打包页即拉取一次今日打包统计(班次日 08:00~次日 08:00) + this.loadTodayPackStat(); } // 注册广播扫码回调(操作员弹窗内枪扫工牌识别绑定用) this.safeDispatchBroadcast('setCallbacks', { @@ -628,10 +697,39 @@ export default { this.bcastHealTimer = null; } }, - // 主界面扫码统一入口:未绑定操作员 → 识别并自动绑定;团购核实时 → 扫商品条码核实;否则 → 按运单查询 + // 扫码内容去重:扫码枪偶发「内容重复/尾段不完整」输出(如 abcabc → abc、abcab → abc),避免重复查询 + dedupeRepeatedScan(code) { + const s = String(code || '').replace(/\s+/g, ''); + if (!s) return ''; + const len = s.length; + // 偶数长度且前后两半完全相同(abcabc → abc);去重后至少保留 3 位,避免误伤短码 + if (len >= 6 && len % 2 === 0) { + const half = len / 2; + if (s.slice(0, half) === s.slice(half)) { + return s.slice(0, half); + } + } + // 尾段与开头重叠(漏尾多扫了部分前缀,abcab → abc) + for (let overlap = Math.floor(len / 2); overlap >= 2; overlap--) { + if (len - overlap >= 3 && s.slice(0, overlap) === s.slice(len - overlap)) { + return s.slice(0, len - overlap); + } + } + return s; + }, + // 主界面扫码统一入口:工牌码 → 识别并新增绑定;未绑定操作员 → 识别并自动绑定;团购核实时 → 扫商品条码核实;否则 → 按运单查询 handleBarcodeInput(code) { - const c = String(code || '').replace(/\s+/g, ''); + // 扫码内容去重:处理扫码枪「内容重复/尾段不完整」输出(如 abcabc → abc、abcab → abc) + const c = this.dedupeRepeatedScan(code); if (!c) return; + // 工牌码(base64 JSON 含 uuid)→ 识别该用户并新增绑定(未绑定首绑 / 已绑定追加新成员);工牌「再扫=下线」需保留连续扫描 + if (this.parseBadgeCode(c).ok) { + this.handleBadgeScan(c); + return; + } + // 与上一次扫描内容完全一致 → 跳过(防止运单/商品条码重复触发查询/核实) + if (this.lastScannedCode === c) return; + this.lastScannedCode = c; if (!this.boundOperators.length) { // 未绑定操作员:输入/扫描值走绑定操作员流程(识别工牌 → 自动绑定,识别失败由 queryOperatorUser 提示) this.opScanCode = c; @@ -643,8 +741,13 @@ export default { this.orderBarcode = c; this.orderInputFocus = false; if (this.groupVerifyingActive && !this.orderBlocked) { - // 团单尚未开始核实时(groupVerifiedCount === 0):扫描其它团购面单直接查询新订单(不弹窗) + // 团单尚未开始核实时(groupVerifiedCount === 0): + // 若扫描的是当前订单的商品条码 → 直接核实;否则视为扫描其它团购面单 → 重新查单 if (this.groupVerifiedCount === 0) { + if (this.matchesAnyGroupItemCode(c)) { + this.handleGroupVerifyScan(c); + return; + } this.resetOrderQuery(); this.queryOrder(c); return; @@ -686,6 +789,20 @@ export default { groupItemScannable(item) { return this.groupItemCodes(item).length > 0; }, + // 判断条码是否为当前团购订单中某待核实商品的可扫条码(用于首次核实区分商品条码与新面单) + matchesAnyGroupItemCode(code) { + const c = String(code || '').trim(); + if (!c || this.orderQueryIsSandan || !this.orderQueryResult) return false; + const items = this.groupItems; + for (let i = 0; i < items.length; i++) { + const item = items[i]; + if (this.isItemVerified(item, i)) continue; + if (this.groupItemCodes(item).indexOf(c) !== -1) { + return true; + } + } + return false; + }, // 商品是否需要复核:need_recheck 为 'N' 视为免验(无需复核),其余(含缺省)按需要复核(Y) isItemNeedRecheck(item) { const v = String((item && item.need_recheck) || 'Y').trim().toUpperCase(); @@ -830,16 +947,10 @@ export default { this.groupSubmitting = false; } }, - // 顶部操作员姓名按钮:已绑定态直接弹移除二次确认;未绑定态打开操作员弹窗准备枪扫/输入工牌绑定 + // 顶部操作员姓名按钮:打开操作员弹窗(展示在线成员列表,支持扫码追加绑定 / 下线成员) handleUserInfo() { - // 已绑定:简化操作,直接弹移除操作员二次确认弹窗 - if (this.boundOperators.length) { - this.handleRemoveOperator(); - return; - } - // 未绑定:打开操作员弹窗 this.userDrawerOpen = true; - // 确保广播监听(从其它页面返回时可能已 pause),未绑定时扫码即识别绑定 + // 确保广播监听(从其它页面返回时可能已 pause),弹窗内扫码即识别/追加绑定 this.safeDispatchBroadcast('setCallbacks', { onResult: this.handleBroadcastResult }); @@ -860,19 +971,13 @@ export default { this.userDrawerOpen = false; this.opInputFocus = false; }, - // 广播扫码结果:未绑定操作员 → 识别并自动绑定;已绑定 → 查询订单 + // 广播扫码结果:工牌码追加绑定 / 未绑定识别绑定 / 团购核实 / 运单查询(统一走 handleBarcodeInput) handleBroadcastResult(result) { // 打印广播扫描原始数据,便于排查枪扫/广播数据格式 console.log('[packMode] 广播扫描原始数据:', result); const scanText = this.normalizeScanResult(result); console.log('[packMode] handleBroadcastResult 扫描结果:', scanText); if (!scanText) return; - if (this.bound && !this.boundOperators.length) { - this.opScanCode = scanText; - this.opInputFocus = false; - this.queryOperatorUser(scanText); - return; - } if (this.bound) { this.handleBarcodeInput(scanText); } @@ -909,9 +1014,12 @@ export default { const orderNo = result.order && result.order.wave_no ? String(result.order.wave_no) : ''; return String(batchNo || orderNo || '').trim(); }, - // 重复查单判断:本次查询结果与当前「打包中」订单相同(团单比 wave_no,散单比 waybill_code) + // 重复查单判断:本次查询结果与当前「打包中」订单相同(团单比 wave_no,散单比 waybill_code,且订单类型一致) sameOrderQuery(result) { if (!this.hasActivePack || !this.activePackIdentity) return false; + // 订单类型一致(散单/团单),避免散单 waybill_code 与团单 wave_no 同名误判 + const newIsSandan = !!(result && Number(result.isSandan) === 1); + if (this.activePackIsSandan !== newIsSandan) return false; const identity = this.orderIdentity(result); return !!identity && identity === this.activePackIdentity; }, @@ -931,8 +1039,6 @@ export default { return; } if (this.orderQuerying) return; - // 记录上一次查询结果:重复查同一「打包中」订单时据此保持显示、不重复上报 - const prevResult = this.orderQueryResult; this.orderQuerying = true; this.orderQueryState = 'loading'; this.orderQueryResult = null; @@ -957,13 +1063,26 @@ export default { return; } // 重复查单:本次查询与当前「打包中」订单相同(团单比 wave_no,散单比 waybill_code), - // 保持「打包中」状态展示,不重复上报开始打包 + // 刷新为新扫运单数据(运单号/货主/包材/商品明细),保持「打包中」状态,不重复上报、不重新复核 if (this.sameOrderQuery(data)) { - this.orderQueryResult = prevResult; + this.orderQueryResult = data; this.orderQueryState = 'success'; this.orderQueryError = ''; this.orderBarcode = ''; - this.speakText('订单打包中'); + // 打包上下文 key 同步为新查询结果(key 始终对应最近一次查询) + this.packContextKey = String(data?.key || '').trim(); + // 恢复态:跳过拦截/已打包/预检,避免同单重复查单被「已打包」拦截隐藏明细 + this.packRestored = true; + // 团购:全部商品恢复为已核实(标绿),不要求重新复核 + const dupItems = Array.isArray(data?.items) ? data.items : []; + const dupVerified = {}; + dupItems.forEach((it, i) => { + dupVerified[this.groupItemKey(it, i)] = Math.max(1, Number(it?.plan_qty) || 1); + }); + // 先置 groupAutoSubmitted 再写 groupVerified,避免 groupAllVerified 变化触发重复提交打包 + this.groupAutoSubmitted = true; + this.groupVerified = dupVerified; + this.speakText('正在打包'); uni.showToast({ title: '订单打包中,请勿重复上报', icon: 'none' }); return; } @@ -1114,15 +1233,8 @@ export default { uni.showLoading({ title: '打包上报中...', mask: true }); try { const payload = { - token, key: packKey, - status: 1, // 打包中 - // pack_time 必须为 Unix 秒(毫秒会导致 start_time 年份溢出) - pack_time: Math.floor(Date.now() / 1000), - users: operators.map(op => ({ - wms_account_id: (op.userId !== '' && op.userId !== null && op.userId !== undefined) ? Number(op.userId) : null, - real_name: op.userName - })) + token }; // toastAfter=false:失败提示由本方法自行控制 @@ -1142,9 +1254,12 @@ export default { console.log('[packMode] 打包上报成功:', res?.data || res); // 记录存在未结束打包任务:退出工作台/解绑操作员前将自动上报打包完成 this.hasActivePack = true; - // 记录当前「打包中」订单标识,重复扫描同一订单时保持打包中、不重复上报 + // 记录当前「打包中」订单标识与类型,重复扫描同一订单时保持打包中、不重复上报 this.activePackIdentity = this.orderIdentity(this.orderQueryResult); + this.activePackIsSandan = this.orderQueryIsSandan; uni.showToast({ title: '已开始打包', icon: 'success' }); + // 开始打包成功后刷新今日打包统计(以服务端为准) + this.loadTodayPackStat(); return true; } catch (error) { console.error('[packMode] 打包上报失败:', error); @@ -1177,6 +1292,7 @@ export default { if (finished) { this.hasActivePack = false; this.activePackIdentity = ''; + this.activePackIsSandan = null; } return { ok: true, @@ -1340,7 +1456,125 @@ export default { // 识别失败后重新拉起广播监听,确保主页面连续扫码仍能收到广播 this.safeDispatchBroadcast('resume'); }, + // ===== 工牌码(base64 JSON 含 uuid)识别:主搜索框扫描新操作员工牌 → 新增绑定 ===== + decodeBase64Text(value) { + if (!value) return ''; + if (typeof atob !== 'function') return ''; + const normalized = String(value).replace(/-/g, '+').replace(/_/g, '/'); + const binary = atob(normalized); + try { + return decodeURIComponent(Array.prototype.map.call(binary, char => { + const code = char.charCodeAt(0).toString(16).padStart(2, '0'); + return `%${code}`; + }).join('')); + } catch (e) { + return binary; + } + }, + isBase64Text(value) { + if (!value) return false; + const text = String(value).trim().replace(/\s/g, ''); + return /^[A-Za-z0-9+/=_-]+$/.test(text) && text.length % 4 === 0; + }, + // 解析工牌码:仅用于识别「扫描值是工牌码(base64 JSON 含 uuid)还是运单条码」,返回 { ok, uuid } + parseBadgeCode(scanText) { + const raw = String(scanText || '').trim().replace(/\s+/g, ''); + if (!raw) return { ok: false, uuid: '' }; + let obj = null; + try { + const parsed = JSON.parse(raw); + if (parsed && typeof parsed === 'object') obj = parsed; + } catch (e) {} + if (!obj && this.isBase64Text(raw)) { + const decoded = this.decodeBase64Text(raw); + if (decoded) { + try { + const parsed = JSON.parse(decoded); + if (parsed && typeof parsed === 'object') obj = parsed; + } catch (e) {} + } + } + if (!obj || typeof obj !== 'object') return { ok: false, uuid: '' }; + const uuid = String(obj.uuid || '').trim(); + if (!uuid) return { ok: false, uuid: '' }; + return { ok: true, uuid }; + }, + // 主搜索框扫到工牌码(base64 JSON 含 uuid)→ 识别该用户并新增绑定(已在线的同名/同 user_id 仅提示) + async handleBadgeScan(scanText) { + const parsed = this.parseBadgeCode(scanText); + if (!parsed.ok) return false; + // 请求参数按扫描值(原样),不做解码处理:ye4s_user.tmp_code 存的是扫描原文 + const token = String(scanText || '').trim(); + if (!token) return false; + // 识别该用户(queryUserByToken:ye4s 临时码 → real_name / wms_account_id) + let ident = null; + uni.showLoading({ title: '识别中...', mask: true }); + try { + const res = await this.$http('index.queryUserByToken', { token }, '', false); + if (res?.flag === 'success' || Number(res?.code) === 200) { + const data = (res && typeof res === 'object' && res.data && typeof res.data === 'object') ? res.data : res; + const name = String(data?.real_name ?? data?.realName ?? '').trim(); + if (name) { + const rawWmsId = data?.wms_account_id ?? data?.wmsAccountId; + ident = { + name, + wmsAccountId: (rawWmsId === null || rawWmsId === undefined || rawWmsId === '') ? null : Number(rawWmsId) + }; + } + } else { + const code = Number(res?.code); + if (this.handleWorkbenchAuthExpired(code)) return true; + const msg = String(res?.message || res?.msg || ''); + uni.showToast({ title: code === 404 ? '未找到对应用户' : (msg || '识别失败,请重试'), icon: 'none' }); + this.speakText('识别失败'); + return true; + } + } catch (error) { + console.error('[packMode] 识别操作员失败:', error); + uni.showToast({ title: error?.message || '识别失败,请重试', icon: 'none' }); + return true; + } finally { + uni.hideLoading(); + } + if (!ident) { + uni.showToast({ title: '未识别到操作员姓名', icon: 'none' }); + return true; + } + // 已在线的同名/同 user_id 成员:再次扫描同一工牌 = 下线(移除该操作员) + const matchedMembers = (Array.isArray(this.workbenchMembers) ? this.workbenchMembers : []).filter((m) => { + if (!m) return false; + const mn = String(m.user_name || '').trim(); + if (mn && mn === ident.name) return true; + if (ident.wmsAccountId !== null && ident.wmsAccountId !== undefined && m.user_id !== null && m.user_id !== undefined) { + return String(m.user_id) === String(ident.wmsAccountId); + } + return false; + }); + if (matchedMembers.length) { + this.orderBarcode = ''; + const ids = matchedMembers.map((m) => String(m && m.id || '').trim()).filter(Boolean); + if (ids.length) { + // 再次扫描同一操作员工牌:下线(移除该操作员)。 + // doRemoveOperators 内部处理:仍有其他成员在线 → 打包任务不受影响;全员下线 → 先 finishPack 再 clearPackState + await this.doRemoveOperators(ids, { toastText: '操作员已下线' }); + } else { + // 兜底:缓存成员缺少行 id(异常数据),无法下线,仅提示在线 + uni.showToast({ title: `${ident.name} 已在线`, icon: 'none' }); + this.speakText(`${ident.name} 已在线`); + } + return true; + } + // 未绑定过:调用 doBindOperator 追加为新在线成员 + const result = await this.doBindOperator({ name: ident.name, wmsAccountId: ident.wmsAccountId }); + if (result && result.ok) { + this.orderBarcode = ''; + } else if (result && !result.expired && result.error) { + uni.showToast({ title: result.error, icon: 'none' }); + } + return true; + }, // 按 ye4s 登录临时码识别操作员(index.queryUserByToken),成功后进入待绑定态 + // 请求参数按扫描值(原样),不做解码处理:ye4s_user.tmp_code 存的是扫描原文 async queryOperatorUser(token) { const t = String(token || '').trim(); if (!t) return; @@ -1400,28 +1634,50 @@ export default { uni.hideLoading(); } }, - // 绑定操作员到本工作台(workbench.bindMember) + // 绑定操作员到本工作台(workbench.bindMember)—— 弹窗识别流程入口 async handleBindOperator() { const ident = this.opQueryResult; if (!ident) return; + const result = await this.doBindOperator({ + name: ident.name, + wmsAccountId: ident.wmsAccountId + }); + if (result && result.ok) { + // 重置识别待绑定态并关闭弹窗(顶部按钮自动变为“已绑定”) + this.opScanCode = ''; + this.opQueryState = ''; + this.opQueryResult = null; + this.opQueryError = ''; + this.userDrawerOpen = false; + this.opInputFocus = false; + } else if (result && !result.expired) { + // 绑定失败:进入待绑定态,保留识别结果,展示「绑定」按钮供手动重试 + this.opQueryState = 'identified'; + uni.showToast({ title: result.error || '绑定操作员失败,请点击绑定重试', icon: 'none' }); + this.speakText('绑定失败,请点击绑定重试'); + } + }, + // 绑定操作员核心逻辑(弹窗识别 / 主搜索框扫工牌新增绑定共用): + // 调用 workbench.bindMember 成功后把新成员追加进 workbenchMembers(同名/同 id 更新,不同用户叠加绑定) + async doBindOperator({ name, wmsAccountId }) { const token = String(this.workbenchToken || '').trim(); if (!token) { uni.showToast({ title: '工作台 token 缺失', icon: 'none' }); - return; + return { ok: false, error: '工作台 token 缺失' }; } - if (this.opBinding) return; + if (this.opBinding) return { ok: false, busy: true }; this.opBinding = true; uni.showLoading({ title: '绑定中...', mask: true }); try { const res = await this.$http('workbench.bindMember', { - userId: ident.wmsAccountId !== null && ident.wmsAccountId !== undefined ? ident.wmsAccountId : null, - userName: ident.name, + userId: wmsAccountId !== null && wmsAccountId !== undefined ? wmsAccountId : null, + userName: name, token }); const invalid = res?.flag === 'failure' || Number(res?.code) === 400 || Number(res?.code) === 403; if (invalid) { // 401:工作台 token 失效,退出工作台模式并清除 token 回登录页 - if (this.handleWorkbenchAuthExpired(res?.code)) return; + if (this.handleWorkbenchAuthExpired(res?.code)) return { ok: false, expired: true }; throw new Error(res?.message || '绑定操作员失败'); } const data = (res && typeof res === 'object' && res.data && typeof res.data === 'object') ? res.data : res; @@ -1434,10 +1690,11 @@ export default { const member = { id: mid, workbench_id: String(this.workbenchId || ''), - user_id: ident.wmsAccountId !== null && ident.wmsAccountId !== undefined ? String(ident.wmsAccountId) : null, - user_name: String(ident.name) + user_id: wmsAccountId !== null && wmsAccountId !== undefined ? String(wmsAccountId) : null, + user_name: String(name) }; const wmList = Array.isArray(this.workbenchMembers) ? this.workbenchMembers.slice() : []; + // 同名/同 id 更新,不同用户叠加绑定 const wmIdx = wmList.findIndex((m) => String(m && m.id) === mid); if (wmIdx >= 0) { wmList[wmIdx] = member; @@ -1446,63 +1703,39 @@ export default { } this.applyWorkbenchMembers(wmList); uni.removeStorageSync('workbenchOperator'); // 清理旧版单操作员缓存 - // 重置识别待绑定态并关闭弹窗(顶部按钮自动变为“已绑定”) - this.opScanCode = ''; - this.opQueryState = ''; - this.opQueryResult = null; - this.opQueryError = ''; - this.userDrawerOpen = false; - this.opInputFocus = false; uni.showToast({ title: '操作员绑定成功', icon: 'success' }); this.speakText('绑定成功'); // 绑定后静默重拉工作台信息,成员列表以服务端为准 this.fetchWorkbenchInfo({ silent: true }); + return { ok: true, member }; } catch (error) { console.error('[packMode] 绑定操作员失败:', error); - // 绑定失败:进入待绑定态,保留识别结果,展示「绑定」按钮供手动重试 - this.opQueryState = 'identified'; - uni.showToast({ title: error?.message || '绑定操作员失败,请点击绑定重试', icon: 'none' }); - this.speakText('绑定失败,请点击绑定重试'); + return { ok: false, error: error?.message || '绑定操作员失败' }; } finally { uni.hideLoading(); this.opBinding = false; } }, - // 移除操作员(workbench.removeMember):打开多选列表,默认不选中任何操作员 - handleRemoveOperator() { - if (!this.boundOperators.length) return; - this.removeSelectedIds = []; - this.removeOperatorPopupOpen = true; - }, - // 关闭移除操作员二次确认弹窗 - handleCloseRemoveOperatorPopup() { - this.removeOperatorPopupOpen = false; - }, - // 某操作员是否被勾选 - isOperatorSelected(op) { - const id = String(op && op.memberId || ''); - return this.removeSelectedIds.indexOf(id) !== -1; - }, - // 勾选/取消勾选某操作员 - toggleOperatorSelected(op) { - const id = String(op && op.memberId || ''); + // 下线单个在线操作员(workbench.removeMember):打开二次确认弹窗(避免 uni.showModal 被操作员弹窗覆盖) + handleOfflineMember(member) { + const id = String(member && member.id || '').trim(); if (!id) return; - const idx = this.removeSelectedIds.indexOf(id); - if (idx === -1) { - this.removeSelectedIds = this.removeSelectedIds.concat([id]); - } else { - this.removeSelectedIds = this.removeSelectedIds.filter(v => v !== id); - } + this.offlineMember = member; + this.offlinePopupOpen = true; }, - // 确认移除操作员:按勾选的成员行 id 批量移除 - async confirmRemoveOperator() { - const ids = this.removeSelectedIds.map(v => String(v || '').trim()).filter(Boolean); - this.removeOperatorPopupOpen = false; - if (!ids.length) { - uni.showToast({ title: '请先选择要移除的操作员', icon: 'none' }); - return; - } - await this.doRemoveOperators(ids); + // 关闭下线操作员二次确认弹窗 + handleCloseOfflinePopup() { + this.offlinePopupOpen = false; + this.offlineMember = null; + }, + // 确认下线:移除该成员行 + async confirmOfflineMember() { + const member = this.offlineMember; + const id = String(member && member.id || '').trim(); + this.offlinePopupOpen = false; + this.offlineMember = null; + if (!id) return; + await this.doRemoveOperators([id]); }, // 执行移除成员请求(silent=true 时为退出工作台前的静默解绑:不弹 loading/toast/语音) // 支持一次移除多个操作员(ids 传数组);全员下线(移除后无成员)时先 finishPack 再 clearPackState() 清空订单数据 @@ -1561,7 +1794,7 @@ export default { this.clearPackState(); } if (!silent) { - uni.showToast({ title: '操作员已移除', icon: 'success' }); + uni.showToast({ title: opts.toastText || '操作员已移除', icon: 'success' }); this.speakText('移除成功'); // 下线后静默重拉工作台信息,成员列表以服务端为准(退出流程 silent 不重拉) this.fetchWorkbenchInfo({ silent: true }); @@ -1590,6 +1823,7 @@ export default { this.groupAutoSubmitted = false; this.hasActivePack = false; this.activePackIdentity = ''; + this.activePackIsSandan = null; this.packRestored = false; }, // 读取本地已绑定信息(wblc 免登录 / 绑定成功均写入 storage) @@ -1610,14 +1844,18 @@ export default { const src = raw && typeof raw === 'object' ? raw : {}; const wave = src.current_wave ?? src.currentWave; const orders = src.current_orders ?? src.currentOrders ?? src.current_order ?? src.currentOrder; - // 无进行中任务则不恢复 - if (!wave && !orders) return; const hasWave = !!(wave && typeof wave === 'object' && Object.keys(wave).length); + // 汇总进行中任务的订单(orders 可为数组或单个对象;空对象/空数组视为无进行中任务) + const orderList = Array.isArray(orders) + ? orders.filter((od) => od && typeof od === 'object' && Object.keys(od).length) + : (orders && typeof orders === 'object' && Object.keys(orders).length) ? [orders] : []; + + // 无进行中任务则不恢复(服务端无任务时可能返回空对象/空数组,需按“非空”判断) + if (!hasWave && !orderList.length) return; + const isSandan = hasWave ? 0 : 1; - // 汇总进行中任务的订单商品明细 - const orderList = Array.isArray(orders) ? orders : (orders ? [orders] : []); let items = []; orderList.forEach((od) => { if (Array.isArray(od && od.items)) items = items.concat(od.items); @@ -1699,6 +1937,7 @@ export default { this.packContextKey = ''; this.hasActivePack = true; this.activePackIdentity = this.orderIdentity(this.orderQueryResult); + this.activePackIsSandan = this.orderQueryIsSandan; this.packRestored = true; // 跳过拦截/已打包/预检,展示进行中任务 console.log('[packMode] 恢复进行中打包任务:', { isSandan, waveNo, waybill, items: mappedItems.length }); }, @@ -1767,6 +2006,40 @@ export default { } } }, + // 拉取今日打包统计(workbench.getWorkbenchCount):班次日 08:00~次日 08:00;失败静默,不阻断打包流程 + async loadTodayPackStat() { + const token = String(this.workbenchToken || '').trim(); + if (!token) return; + try { + // toastAfter=false:失败提示由本方法自行控制(静默) + const res = await this.$http('workbench.getWorkbenchCount', { token }, '', false); + const invalid = res?.flag === 'failure' || [401, 403].indexOf(Number(res?.code)) !== -1; + if (invalid) { + // 401:工作台 token 失效,退出工作台模式回登录页;其余(403 等)静默忽略 + if (this.handleWorkbenchAuthExpired(res?.code)) return; + console.warn('[packMode] 今日打包统计失败:', res?.message || res?.code); + return; + } + const data = (res && typeof res === 'object' && res.data && typeof res.data === 'object') ? res.data : res; + if (!data || typeof data !== 'object') return; + // 统计值 Number(x) || 0 兜底;ratio/avg 用 ?? null 保留 null(散单为 0 时 ratio 为 null) + this.todayWaveCount = Number(data.group_wave_count) || 0; + this.todayGroupOrderCount = Number(data.group_order_count) || 0; + this.todaySingleCount = Number(data.single_order_count) || 0; + this.todayRatio = data.group_single_ratio ?? null; + this.todayAvgPiece = data.avg_piece_count ?? null; + } catch (error) { + console.warn('[packMode] 今日打包统计拉取失败:', error); + } + }, + // 打开今日打包统计面板 + openTodayPackPanel() { + this.todayPackPanelOpen = true; + }, + // 关闭今日打包统计面板 + closeTodayPackPanel() { + this.todayPackPanelOpen = false; + }, // 退出工作台模式(用户主动):打开退出确认弹窗 handleBack() { this.exitPopupOpen = true; @@ -1865,10 +2138,29 @@ export default { width: 260rpx; } -.header-left__text { - margin-left: 8rpx; - font-size: 34rpx; - color: #606266; +.header-left__exit { + display: flex; + align-items: center; + justify-content: center; + width: 56rpx; + height: 64rpx; + flex-shrink: 0; +} + +.today-pack-btn { + display: flex; + align-items: center; + margin-left: 16rpx; + padding: 8rpx 16rpx; + border-radius: 8rpx; + background: #2979ff; + flex-shrink: 0; +} + +.today-pack-btn__text { + font-size: 30rpx; + color: #ffffff; + font-weight: 500; } .header-title { @@ -1910,7 +2202,7 @@ export default { gap: 6rpx; padding: 8rpx 16rpx; border-radius: 8rpx; - background: #2979ff; + background: #909399; max-width: 248rpx; } @@ -2156,6 +2448,25 @@ export default { color: #2979ff; } +.order-summary__num--green { + color: #07c160; +} + +.order-summary__stat-row { + justify-content: space-between; +} + +.order-summary__stat { + display: flex; + align-items: center; +} + +.order-summary__stat-label { + font-size: 30rpx; + color: #909399; + margin-right: 8rpx; +} + /* 禁止打包:运单/波次行红底 */ .order-summary__row--blocked { background: #e64340; @@ -2436,6 +2747,79 @@ export default { overflow-y: auto; } +.member-section { + margin-bottom: 24rpx; + background: #f5f6f7; + border-radius: 16rpx; + padding: 20rpx; + box-sizing: border-box; +} + +.member-section__header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16rpx; + margin-bottom: 16rpx; +} + +.member-section__title { + flex: 1; + font-size: 24rpx; + color: #909399; + line-height: 1.4; + word-break: break-all; +} + +.member-section__count { + flex-shrink: 0; + font-size: 26rpx; + font-weight: 600; + color: #2979ff; +} + +.member-list { + display: flex; + flex-direction: column; + max-height: 300rpx; + overflow-y: auto; +} + +.member-item { + display: flex; + align-items: center; + justify-content: space-between; + padding: 18rpx 20rpx; + background: #ffffff; + border-radius: 12rpx; + border: 2rpx solid #e4e7ed; +} + +.member-item:not(:last-child) { + margin-bottom: 12rpx; +} + +.member-item__info { + flex: 1; + min-width: 0; +} + +.member-item__name { + font-size: 34rpx; + color: #303133; + word-break: break-all; +} + +.member-item__offline { + flex-shrink: 0; + margin-left: 16rpx; + padding: 8rpx 24rpx; + border-radius: 8rpx; + background: #fef0f0; + color: #f56c6c; + font-size: 28rpx; +} + .scan-section { background: #f5f6f7; border-radius: 16rpx; @@ -2726,7 +3110,8 @@ export default { color: #ffffff; } -.remove-operator-popup { +/* ===== 下线操作员二次确认弹窗 ===== */ +.offline-popup { width: 640rpx; padding: 40rpx 32rpx 32rpx; background: #ffffff; @@ -2734,7 +3119,7 @@ export default { box-sizing: border-box; } -.remove-operator-popup__title { +.offline-popup__title { font-size: 42rpx; font-weight: 600; color: #303133; @@ -2742,57 +3127,25 @@ export default { margin-bottom: 32rpx; } -.remove-operator-popup__body { +.offline-popup__body { margin-bottom: 36rpx; padding: 24rpx; background: #f8f9fa; border-radius: 12rpx; } -.remove-operator-popup__text { +.offline-popup__text { font-size: 36rpx; color: #303133; line-height: 1.6; } -.remove-operator-list { - margin-top: 24rpx; - display: flex; - flex-direction: column; - gap: 16rpx; - max-height: 360rpx; - overflow-y: auto; -} - -.remove-operator-item { - display: flex; - align-items: center; - justify-content: space-between; - gap: 16rpx; - padding: 20rpx 24rpx; - border: 2rpx solid #e4e7ed; - border-radius: 12rpx; - background: #f8f9fb; -} - -.remove-operator-item--checked { - border-color: #2979ff; - background: #f0f7ff; -} - -.remove-operator-item__name { - flex: 1; - font-size: 34rpx; - color: #303133; - word-break: break-all; -} - -.remove-operator-popup__actions { +.offline-popup__actions { display: flex; align-items: center; } -.remove-operator-popup__btn { +.offline-popup__btn { flex: 1; height: 88rpx; border-radius: 12rpx; @@ -2803,18 +3156,72 @@ export default { font-weight: 500; } -.remove-operator-popup__btn:not(:last-child) { +.offline-popup__btn:not(:last-child) { margin-right: 20rpx; } -.remove-operator-popup__btn--cancel { +.offline-popup__btn--cancel { background: #f5f7fa; color: #606266; border: 1rpx solid #dcdfe6; } -.remove-operator-popup__btn--confirm { +.offline-popup__btn--confirm { background: #f56c6c; color: #ffffff; } + +/* ===== 今日打包统计面板 ===== */ +.today-pack-panel { + width: 640rpx; + padding: 40rpx 32rpx 32rpx; + background: #ffffff; + border-radius: 20rpx; + box-sizing: border-box; +} + +.today-pack-panel__title { + font-size: 48rpx; + font-weight: 600; + color: #303133; + text-align: center; + margin-bottom: 32rpx; +} + +.today-pack-panel__body { + display: flex; + flex-direction: column; +} + +.today-pack-stat { + display: flex; + align-items: center; + justify-content: space-between; + padding: 20rpx 24rpx; + border-radius: 12rpx; +} + +.today-pack-stat:not(:last-child) { + margin-bottom: 16rpx; +} + +/* 斑马纹:白底 + 浅蓝底交替(参考商品查询库存斑马纹) */ +.today-pack-stat:nth-child(even) { + background: #dde9fb; +} + +.today-pack-stat:nth-child(odd) { + background: #ffffff; +} + +.today-pack-stat__label { + font-size: 36rpx; + color: #000000; +} + +.today-pack-stat__value { + font-size: 40rpx; + font-weight: 600; + color: #2979ff; +}