WMS_PDA/pages/packing/packMode.vue
2026-09-21 18:20:27 +08:00

2821 lines
91 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="pack-mode-page">
<!-- 顶部栏 -->
<view class="top-bar">
<view class="status-bar"></view>
<view class="header">
<view class="header-left" @click="handleBack">
<u-icon name="arrow-left" size="36rpx" color="#303133"></u-icon>
<text class="header-left__text">退出</text>
</view>
<view class="header-center">
<text class="header-title">打包模式</text>
<text v-if="bound && workbenchName" class="header-subtitle">{{ workbenchName }}</text>
</view>
<view class="header-right">
<view class="user-info-btn" :class="{ 'user-info-btn--bound': boundOperators.length }" @click="handleUserInfo">
<u-icon name="account-fill" size="34rpx" color="#ffffff"></u-icon>
<text class="user-info-btn__text">{{ boundOperatorText }}</text>
</view>
</view>
</view>
</view>
<view class="content">
<!-- ============ 已绑定态 ============ -->
<template v-if="bound">
<!-- 订单查询 -->
<view class="order-query-card">
<view class="order-query__scan-line">
<view class="order-query__scan-row">
<input
class="order-query__input"
v-model="orderBarcode"
:focus="orderInputFocus"
placeholder="扫描/输入运单号查询"
placeholder-style="color:#c0c4cc;font-size:34rpx"
@confirm="handleOrderQueryConfirm"
/>
<view class="camera-btn" @click="handleOrderCameraScan">
<u-icon name="scan" size="36rpx" color="#2979ff"></u-icon>
</view>
</view>
<template v-if="orderQueryState === 'success' && orderQueryResult && !orderQueryIsSandan">
<u-button
v-if="groupVerifyingActive && groupItems.length > 0 && !orderBlocked"
text="取消核实"
type="error"
@click="handleCancelGroupVerify"
></u-button>
</template>
</view>
<!-- 查询中 -->
<view v-if="orderQueryState === 'loading'" class="order-query__loading">
<u-loading-icon text="查询中..." color="#2979ff"></u-loading-icon>
</view>
<!-- 查询失败 -->
<view v-else-if="orderQueryState === 'error'" class="order-query__error">
<text class="order-query__error-text">{{ orderQueryError || '查询失败,请重试' }}</text>
</view>
<!-- 查询成功 -->
<template v-else-if="orderQueryState === 'success' && orderQueryResult">
<!-- 头部:运单号 + 类型(仅团购显示;散单运单号在概要行展示) -->
<view v-if="!orderQueryIsSandan" class="order-query__head">
<text class="order-result-waybill">{{ orderQueryResult.waybill_code || orderQueryResult.barcode || '--' }}</text>
<text class="order-result-tag order-result-tag--tuangou">团购</text>
<text class="order-verify-progress">已扫{{ groupVerifiedCount }}/{{ groupItems.length }}种</text>
</view>
<!-- 精简概要:波次(散单显示运单) 共x单 / 包材名称 商品总数量 -->
<view class="order-summary">
<view class="order-summary__row" :class="{ 'order-summary__row--blocked': orderBlocked }">
<text class="order-summary__label">{{ orderQueryIsSandan ? '运单' : '波次' }}</text>
<text class="order-summary__value order-summary__value--strong">{{ orderQueryIsSandan ? orderWaybillNo : orderWaveNo }}</text>
<text v-if="orderQueryIsSandan" class="order-result-tag order-result-tag--sandan order-summary__tag">散单</text>
<text v-if="!orderQueryIsSandan" class="order-summary__extra">共 <text class="order-summary__num">{{ orderWaveTotal }}</text> 单</text>
</view>
<view v-if="orderQueryResult.store_remark" class="order-summary__row">
<text class="order-summary__label">货主</text>
<text class="order-summary__value">{{ orderQueryResult.store_remark }}</text>
</view>
<view class="order-summary__row">
<text class="order-summary__label">包材</text>
<text class="order-summary__value">{{ packageMaterialName || '--' }}</text>
<text class="order-summary__extra">商品总数 <text class="order-summary__num">{{ orderItemsTotal }}</text></text>
</view>
</view>
<!-- 商品明细:数量 + 图片 + 名称 + 条码(拦截/未复核/已打包时显示禁止打包提示) -->
<view v-if="orderBlocked" class="order-block order-block--blocked">
<view class="order-block__hint">{{ orderBlockedHint }}</view>
</view>
<view v-else class="order-block">
<template v-if="orderQueryResult.items && orderQueryResult.items.length">
<view
v-for="(item, idx) in orderQueryResult.items"
:key="item.id || idx"
class="order-item"
:class="{ 'order-item--verified': !orderQueryIsSandan && isItemVerified(item, idx) }"
@longpress="handleGroupItemLongPress(item, idx)"
>
<view class="order-item__top">
<view class="order-item__qty-group">
<view class="order-item__qty-item">
<text class="order-item__label">数量</text>
<text class="order-item__value">{{ item.plan_qty }}</text>
</view>
</view>
<view class="order-item__image-wrap" @click="previewItemImage(item)">
<image
v-if="orderItemImg(item)"
class="order-item__image"
:src="orderItemImg(item)"
mode="aspectFill"
></image>
<view v-else class="order-item__image order-item__image--placeholder">
<u-icon name="photo" size="24" color="#c0c4cc"></u-icon>
</view>
<view v-if="orderItemImages(item).length > 1" class="order-item__image-count">+{{ orderItemImages(item).length - 1 }}</view>
</view>
</view>
<view class="order-item__bottom">
<text class="order-item__name">{{ item.item_name || '--' }}</text>
<text class="order-item__space">、</text>
<text class="order-item__barcode">{{ orderItemBarcode(item) || item.item_code || '--' }}</text>
</view>
</view>
</template>
<view v-else class="order-empty">无商品明细</view>
</view>
</template>
</view>
</template>
<!-- ============ 未绑定态:提示返回登录页 ============ -->
<template v-else>
<view class="state-card">
<view class="state-badge">
<u-icon name="info-circle" size="36rpx" color="#909399"></u-icon>
<text class="state-badge__text">未绑定工作台</text>
</view>
<view class="info-block">
<view class="info-row">
<text class="info-label">提示</text>
<text class="info-value">当前未绑定工作台,请返回登录页使用工作台登录码(wblc 开头)登录后进入打包模式。</text>
</view>
</view>
</view>
<view class="action-area action-area--col">
<u-button text="返回登录页" plain @click="handleBack"></u-button>
</view>
</template>
</view>
<!-- 操作员弹窗 -->
<u-popup
:show="userDrawerOpen"
mode="center"
round="16"
bgColor="#ffffff"
:closeable="true"
:z-index="10090"
@close="handleCloseUserDrawer"
>
<view class="user-drawer">
<view class="user-drawer__header">
<text class="user-drawer__title">操作员</text>
</view>
<view class="user-drawer__body">
<!-- 未绑定:扫码识别工牌 → 绑定 -->
<view class="scan-section">
<view class="scan-row">
<input
class="scan-input"
v-model="opScanCode"
:focus="opInputFocus"
placeholder="输入/扫描工牌绑定工作台"
placeholder-style="color:#c0c4cc;font-size:34rpx"
@confirm="handleOpInputConfirm"
/>
<view class="camera-btn" @click="handleOpCameraScan">
<u-icon name="scan" size="36rpx" color="#2979ff"></u-icon>
</view>
</view>
</view>
<view v-if="opQueryState === 'loading'" class="query-state query-state--loading">
<u-loading-icon text="识别中..." color="#2979ff"></u-loading-icon>
</view>
<view v-else-if="opQueryState === 'identified' && opQueryResult" class="operator-ident-card">
<u-button
text="绑定"
type="primary"
:loading="opBinding"
@click="handleBindOperator"
></u-button>
</view>
<view v-else-if="opQueryState === 'error'" class="query-state query-state--error">
<text class="query-state__error-text">{{ opQueryError || '识别失败,请重试' }}</text>
</view>
</view>
</view>
</u-popup>
<!-- 无条码复核弹窗(团单) -->
<u-popup
:show="noBarcodePopupOpen"
mode="center"
:closeable="true"
:closeOnClickOverlay="false"
border-radius="20"
:z-index="10095"
@close="handleCloseNoBarcodePopup"
>
<view class="no-barcode-popup">
<view class="no-barcode-popup__title">无条码复核</view>
<view class="no-barcode-popup__body">
<text class="no-barcode-popup__text">
将商品「{{ noBarcodeItem ? noBarcodeItem.name : '--' }}」标记为已核实({{ noBarcodeItem ? noBarcodeItem.current : 0 }}/{{ noBarcodeItem ? noBarcodeItem.qty : 0 }} → {{ noBarcodeItem ? noBarcodeItem.qty : 0 }}/{{ noBarcodeItem ? noBarcodeItem.qty : 0 }})?
</text>
</view>
<view class="no-barcode-popup__actions">
<view class="no-barcode-popup__btn no-barcode-popup__btn--cancel" @click="handleCloseNoBarcodePopup">取消</view>
<view class="no-barcode-popup__btn no-barcode-popup__btn--confirm" @click="confirmNoBarcodeReview">确定</view>
</view>
</view>
</u-popup>
<!-- 取消核实弹窗(团单) -->
<u-popup
:show="cancelVerifyPopupOpen"
mode="center"
:closeable="true"
:closeOnClickOverlay="false"
border-radius="20"
:z-index="10095"
@close="handleCloseCancelVerifyPopup"
>
<view class="cancel-verify-popup">
<view class="cancel-verify-popup__title">取消核实</view>
<view class="cancel-verify-popup__body">
<text class="cancel-verify-popup__text">确认取消本次核实?将放弃当前订单的商品核实,且不会开始打包。</text>
</view>
<view class="cancel-verify-popup__actions">
<view class="cancel-verify-popup__btn cancel-verify-popup__btn--cancel" @click="handleCloseCancelVerifyPopup">关闭</view>
<view class="cancel-verify-popup__btn cancel-verify-popup__btn--confirm" @click="confirmCancelVerify">确定</view>
</view>
</view>
</u-popup>
<!-- 退出工作台弹窗 -->
<u-popup
:show="exitPopupOpen"
mode="center"
:closeable="true"
:closeOnClickOverlay="false"
border-radius="20"
:z-index="10095"
@close="handleCloseExitPopup"
>
<view class="exit-popup">
<view class="exit-popup__title">退出工作台模式</view>
<view class="exit-popup__body">
<text class="exit-popup__text">退出后将清除本地工作台登录记录,需要重新扫码(wblc 开头登录码)才能进入打包模式。</text>
</view>
<view class="exit-popup__actions">
<view class="exit-popup__btn exit-popup__btn--cancel" @click="handleCloseExitPopup">取消</view>
<view class="exit-popup__btn exit-popup__btn--confirm" @click="confirmExit">退出</view>
</view>
</view>
</u-popup>
<!-- 移除操作员二次确认弹窗 -->
<u-popup
:show="removeOperatorPopupOpen"
mode="center"
:closeable="true"
:closeOnClickOverlay="false"
border-radius="20"
:z-index="10095"
@close="handleCloseRemoveOperatorPopup"
>
<view class="remove-operator-popup">
<view class="remove-operator-popup__title">移除操作员</view>
<view class="remove-operator-popup__body">
<text class="remove-operator-popup__text">{{ removeOperatorHint }}</text>
<view class="remove-operator-list">
<view
v-for="op in boundOperators"
:key="op.memberId"
class="remove-operator-item"
:class="{ 'remove-operator-item--checked': isOperatorSelected(op) }"
@click="toggleOperatorSelected(op)"
>
<text class="remove-operator-item__name">{{ op.userName || '--' }}</text>
<u-icon
:name="isOperatorSelected(op) ? 'checkmark-circle-fill' : 'checkmark-circle'"
:color="isOperatorSelected(op) ? '#2979ff' : '#c0c4cc'"
size="22"
></u-icon>
</view>
</view>
</view>
<view class="remove-operator-popup__actions">
<view class="remove-operator-popup__btn remove-operator-popup__btn--cancel" @click="handleCloseRemoveOperatorPopup">取消</view>
<view class="remove-operator-popup__btn remove-operator-popup__btn--confirm" @click="confirmRemoveOperator">确定</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
// 工作台在线成员列表本地缓存 key(服务端 getWorkbenchInfo 返回 members[] 时同步并缓存,重进时据此恢复)
const MEMBER_STORAGE_KEY = 'workbenchMembers'
export default {
data() {
return {
// 当前绑定
bound: false,
workbenchId: '',
workbenchName: '',
workbenchToken: '',
warehouseId: '',
workbenchStatus: '',
workbenchType: '',
infoRefreshing: false, // 进入后刷新工作台信息请求防重入锁
bcastHealTimer: null, // 广播监听自愈定时器(onShow 延迟重新注册用)
// 当前操作员列表(工作台成员,本地保存 bindMember 返回的成员行 id,支持多人)
boundOperators: [],
// 工作台在线成员列表(以服务端 getWorkbenchInfo 返回的 members[] 为权威,绑定/下线后静默重拉同步)
workbenchMembers: [],
infoRefreshingSilent: false, // 静默刷新工作台信息防重入锁
opScanCode: '', // 操作员扫码输入框内容(ye4s 登录临时码)
opInputFocus: false,
opQueryState: '', // '' | loading | identified | error(识别待绑定状态)
opQueryResult: null, // 识别出的待绑定操作员 { scanToken, name, wmsAccountId }
opQueryError: '',
opBinding: false, // bindMember 请求中
opRemoving: false, // removeMember 请求中
// 操作员弹窗
userDrawerOpen: false,
// 订单查询(workbench.queryOrder)
orderBarcode: '',
orderInputFocus: false,
orderQuerying: false,
orderQueryState: '', // '' | loading | success | error
orderQueryResult: null,
orderQueryError: '',
packContextKey: '', // 查单返回的打包上下文 key(20 分钟有效,packOrder 凭此打包)
packReporting: false, // packOrder 上报请求防重入锁
finishPacking: false, // finishPack 完成打包请求防重入锁
hasActivePack: false, // 该工作台是否存在未结束打包任务(status<2):退出/解绑前自动上报打包完成
activePackIdentity: '', // 当前「打包中」订单唯一标识:团单为 wave_no,散单为 waybill_code(重复查单去重用)
packRestored: false, // 重进后从服务端恢复的「打包中」态(跳过拦截/已打包/预检,直接展示进行中任务)
// 团购核实:商品行已扫计数(key=商品行id/序号 → 已扫次数),达 plan_qty 视为已核实
groupVerified: {},
groupSubmitting: false, // 团购提交开始打包防重入
groupAutoSubmitted: false, // 团购全部核实后是否已自动提交开始打包
// 无条码复核弹窗(团单)
noBarcodePopupOpen: false,
noBarcodeItem: null, // { name, current, qty, item, idx }
// 取消核实弹窗(团单)
cancelVerifyPopupOpen: false,
// 退出工作台弹窗
exitPopupOpen: false,
// 移除操作员二次确认弹窗
removeOperatorPopupOpen: false,
// 移除弹窗中已勾选的操作员成员行 id(多选)
removeSelectedIds: []
}
},
// 团购:全部商品核实完成后自动提交开始打包(每次查询仅自动提交一次)
watch: {
groupAllVerified(verified) {
if (verified && !this.orderQueryIsSandan && this.orderQueryResult && !this.groupAutoSubmitted) {
this.groupAutoSubmitted = true;
this.handleSubmitGroupPack();
}
}
},
computed: {
maskedToken() {
const token = String(this.workbenchToken || '');
if (!token) return '';
if (token.length <= 12) return token;
return `${token.substring(0, 6)}...${token.substring(token.length - 4)}`;
},
statusText() {
if (this.workbenchStatus === 0 || this.workbenchStatus === '0') return '禁用';
if (this.workbenchStatus === 1 || this.workbenchStatus === '1') return '启用';
return this.workbenchStatus === '' || this.workbenchStatus === null || typeof this.workbenchStatus === 'undefined' ? '--' : String(this.workbenchStatus);
},
typeText() {
if (this.workbenchType === 'personal') return '个人工作台';
if (this.workbenchType === 'group') return '团体工作台';
return this.workbenchType ? this.workbenchType : '--';
},
// 顶部操作员按钮文案:单人显示姓名,多人显示「姓名 等N人」
boundOperatorText() {
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} 名操作员,移除后需重新扫码绑定。`;
},
// 查询结果是否为散单
orderQueryIsSandan() {
const r = this.orderQueryResult;
return !!(r && Number(r.isSandan) === 1);
},
// 订单是否被禁止打包(拦截/未复核/已打包),命中时不显示商品明细
orderBlocked() {
// 重进恢复的进行中任务:跳过拦截/未复核/已打包判断,直接展示打包中状态
if (this.packRestored) return false;
const r = this.orderQueryResult;
const order = r && r.order;
if (!order) return false;
// 1. 拦截:仅散单判断
if (this.orderQueryIsSandan && Number(order.intercept_flag) === 1) {
return true;
}
// 2. 未复核(团散都判)
const recheck = String(order.recheck_status ?? '').trim().toLowerCase();
const recheckDone = recheck === 'fin' || recheck === 'finished' || recheck === '1';
if (!recheckDone) {
return true;
}
// 3. 已打包:散单看 pack_flag;团购看 pack_status
let packed = false;
if (this.orderQueryIsSandan) {
packed = Number(order.pack_flag) === 1 || order.pack_flag === true;
} else {
const ps = String(order.pack_status ?? '').trim().toLowerCase();
packed = ps !== '' && ps !== 'none';
}
return packed;
},
// 禁止打包提示文案:与 orderBlocked 判定顺序一致(拦截 → 未复核 → 已打包)
orderBlockedHint() {
if (!this.orderBlocked) return '';
const r = this.orderQueryResult;
const order = r && r.order;
if (this.orderQueryIsSandan && order && Number(order.intercept_flag) === 1) {
return '订单已拦截,禁止打包';
}
if (order) {
const recheck = String(order.recheck_status ?? '').trim().toLowerCase();
const recheckDone = recheck === 'fin' || recheck === 'finished' || recheck === '1';
if (!recheckDone) {
return '订单未复核,禁止打包';
}
let packed = false;
if (this.orderQueryIsSandan) {
packed = Number(order.pack_flag) === 1 || order.pack_flag === true;
} else {
const ps = String(order.pack_status ?? '').trim().toLowerCase();
packed = ps !== '' && ps !== 'none';
}
if (packed) return '订单已打包,禁止打包';
}
return '订单禁止打包';
},
// 精简概要:包材名称(express/order 的 package_material_name)
packageMaterialName() {
const r = this.orderQueryResult;
const raw = (r?.order && (r.order.package_material_name ?? r.order.packageMaterialName)) ?? (r?.express && (r.express.package_material_name ?? r.express.packageMaterialName));
return String(raw || '').trim();
},
// 运单号(waybill_code 优先,兜底 barcode)——散单概要行显示用
orderWaybillNo() {
const r = this.orderQueryResult;
const waybill = r?.waybill_code ? String(r.waybill_code) : '';
const barcode = r?.barcode ? String(r.barcode) : '';
return waybill || barcode || '--';
},
// 波次号(batch.wave_no 优先,兜底 order.wave_no)
orderWaveNo() {
const r = this.orderQueryResult;
const batchNo = r?.batch && r.batch.wave_no ? String(r.batch.wave_no) : '';
const orderNo = r?.order && r.order.wave_no ? String(r.order.wave_no) : '';
return batchNo || orderNo || '--';
},
// 波次总单数(团购 batch.total_orders;兜底 items_count)
orderWaveTotal() {
const r = this.orderQueryResult;
const batchTotal = r?.batch && (r.batch.total_orders !== undefined && r.batch.total_orders !== null) ? r.batch.total_orders : null;
const itemCount = r?.order && (r.order.items_count !== undefined && r.order.items_count !== null) ? r.order.items_count : 0;
return batchTotal !== null ? batchTotal : itemCount;
},
// 商品总数量(order.items_total,缺省按 items 求和)
orderItemsTotal() {
const r = this.orderQueryResult;
const total = r?.order && (r.order.items_total !== undefined && r.order.items_total !== null) ? r.order.items_total : null;
if (total !== null) return total;
if (Array.isArray(r?.items)) {
return r.items.reduce((sum, it) => sum + (Number(it.plan_qty) || 0), 0);
}
return 0;
},
// 团购订单商品明细(查询结果 items)
groupItems() {
const r = this.orderQueryResult;
return (r && Array.isArray(r.items)) ? r.items : [];
},
// 团购已核实商品数
groupVerifiedCount() {
const items = this.groupItems;
let count = 0;
for (let i = 0; i < items.length; i++) {
if (this.isItemVerified(items[i], i)) count++;
}
return count;
},
// 团购总已扫件数(所有商品已扫次数之和,单件不超过 plan_qty)
groupScannedTotal() {
const items = this.groupItems;
let sum = 0;
for (let i = 0; i < items.length; i++) {
const qty = Math.max(1, Number(items[i] && items[i].plan_qty) || 1);
const current = this.groupVerified[this.groupItemKey(items[i], i)] || 0;
sum += Math.min(current, qty);
}
return sum;
},
// 团购商品是否全部核实(无明细视为无需核实)
groupAllVerified() {
if (this.orderQueryIsSandan) return false;
const items = this.groupItems;
if (!items.length) return true;
return this.groupVerifiedCount >= items.length;
},
// 团购核实扫描激活中:存在未核实的可扫商品(此时扫码=核实商品条码)
groupVerifyingActive() {
if (this.orderQueryIsSandan) return false;
// 被禁止打包(拦截/未复核/已打包)时不激活核实,扫描走运单查询
if (this.orderBlocked) return false;
const items = this.groupItems;
return !!this.orderQueryResult && items.length > 0 && this.groupVerifiedCount < items.length;
},
// 输入框占位:团购核实时提示扫商品条码
groupScanPlaceholder() {
return (this.groupVerifyingActive && !this.orderBlocked) ? '扫描商品条码核实' : '扫描/输入运单号查询';
}
},
onLoad(options) {
this.loadBound(options);
// 读取本地保存的已绑定操作员列表(bindMember 返回的成员行 id,按 workbenchId 匹配)
this.loadBoundOperators();
// 恢复本地缓存的工作台成员列表(离线优先,随后 fetchWorkbenchInfo 以服务端 members 覆盖)
this.restoreWorkbenchMembers();
// 进入打包模式:重新拉取工作台信息(同时校验本地工作台 token 是否仍有效)
if (this.bound) {
this.fetchWorkbenchInfo();
}
// 注册广播扫码回调(操作员弹窗内枪扫工牌识别绑定用)
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
// 诊断:确认接收器是否在监听
this.$store.dispatch('broadcast/getStatus').then((status) => {
console.log('[packMode][bcast] onShow 广播状态:', JSON.stringify(status));
});
// 自愈:reLaunch 进入本页时,登录页 onUnload 的 broadcast/stop 可能晚于本页 start,
// 把刚注册的接收器注销导致主页面扫码收不到广播(打开绑定弹窗时 resume 又恢复正常)。
// 延迟后强制重新注册一次,确保主页面连续扫码可用。
this.clearBcastHealTimer();
this.bcastHealTimer = setTimeout(() => {
this.$store.dispatch('broadcast/getStatus').then((status) => {
const listening = !!(status && status.isListening);
if (!listening) {
console.warn('[packMode][bcast] 广播未在监听,延迟重启接收器');
this.safeDispatchBroadcast('start');
} else {
// 状态显示在监听,但 reLaunch 竞态可能已把接收器注销而标志仍为真,强制重新注册一次
console.log('[packMode][bcast] 延迟自愈:重新注册广播接收器');
this.safeDispatchBroadcast('resume');
}
});
}, 1200);
},
onHide() {
this.clearBcastHealTimer();
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.clearBcastHealTimer();
this.safeDispatchBroadcast('stop');
},
methods: {
// 语音播报($tools.speakText 封装,自动 catch)
speakText(text = '') {
try {
const tools = this.$tools;
if (!tools || typeof tools.speakText !== 'function') return;
const task = tools.speakText(String(text).trim(), {});
if (task && typeof task.catch === 'function') {
task.catch(error => console.warn('[packMode] 语音播报失败:', error));
}
} catch (error) {
console.warn('[packMode] 语音播报异常:', error);
}
},
// 清理广播自愈定时器(页面隐藏/卸载时避免残留定时器误注册广播)
clearBcastHealTimer() {
if (this.bcastHealTimer) {
clearTimeout(this.bcastHealTimer);
this.bcastHealTimer = null;
}
},
// 主界面扫码统一入口:未绑定操作员 → 识别并自动绑定;团购核实时 → 扫商品条码核实;否则 → 按运单查询
handleBarcodeInput(code) {
const c = String(code || '').replace(/\s+/g, '');
if (!c) return;
if (!this.boundOperators.length) {
// 未绑定操作员:输入/扫描值走绑定操作员流程(识别工牌 → 自动绑定,识别失败由 queryOperatorUser 提示)
this.opScanCode = c;
this.opInputFocus = false;
this.orderBarcode = ''; // 清空订单输入框,避免残留工牌码,便于连续操作
this.queryOperatorUser(c);
return;
}
this.orderBarcode = c;
this.orderInputFocus = false;
if (this.groupVerifyingActive && !this.orderBlocked) {
// 团单尚未开始核实时(groupVerifiedCount === 0):扫描其它团购面单直接查询新订单(不弹窗)
if (this.groupVerifiedCount === 0) {
this.resetOrderQuery();
this.queryOrder(c);
return;
}
// 团单核实中:扫描内容按商品条码核实(匹配商品明细条码)
this.handleGroupVerifyScan(c);
return;
}
this.queryOrder(c);
},
// ===== 团购商品核实 =====
groupItemKey(item, idx) {
return (item && item.id !== undefined && item.id !== null) ? ('id_' + item.id) : ('idx_' + idx);
},
// 商品可扫条码列表(barcodes[].barcode / barcode / item_code)
groupItemCodes(item) {
if (!item) return [];
const out = [];
const codes = item.barcodes ?? item.barcode;
if (Array.isArray(codes)) {
codes.forEach((c) => {
if (!c) return;
if (typeof c === 'object') {
if (c.barcode) out.push(String(c.barcode));
else if (c.code) out.push(String(c.code));
} else {
out.push(String(c));
}
});
} else if (codes && typeof codes === 'object') {
if (codes.barcode) out.push(String(codes.barcode));
else if (codes.code) out.push(String(codes.code));
} else if (codes) {
out.push(String(codes));
}
if (item.item_code) out.push(String(item.item_code));
return out.map(s => String(s).trim()).filter(Boolean);
},
groupItemScannable(item) {
return this.groupItemCodes(item).length > 0;
},
// 商品是否需要复核:need_recheck 为 'N' 视为免验(无需复核),其余(含缺省)按需要复核(Y)
isItemNeedRecheck(item) {
const v = String((item && item.need_recheck) || 'Y').trim().toUpperCase();
return v !== 'N';
},
isItemVerified(item, idx) {
// 免验商品(need_recheck=N)无需扫码复核,直接视为已核实
if (!this.isItemNeedRecheck(item)) return true;
const qty = Math.max(1, Number(item && item.plan_qty) || 1);
const key = this.groupItemKey(item, idx);
return (this.groupVerified[key] || 0) >= qty;
},
// 长按复核:整件标记已核实(视为数量全部扫满)
markItemVerified(item, idx) {
const key = this.groupItemKey(item, idx);
if (this.isItemVerified(item, idx)) return;
const qty = Math.max(1, Number(item && item.plan_qty) || 1);
this.groupVerified = Object.assign({}, this.groupVerified, { [key]: qty });
},
// 扫描计数 +1:扫中商品条码一次记一次,返回是否刚好扫满(该商品已核实)
incrementVerified(item, idx) {
const key = this.groupItemKey(item, idx);
const qty = Math.max(1, Number(item && item.plan_qty) || 1);
const current = this.groupVerified[key] || 0;
if (current >= qty) return false;
const next = current + 1;
this.groupVerified = Object.assign({}, this.groupVerified, { [key]: next });
return next >= qty;
},
// 商品行核实状态文案:已核实 / 已扫x/y
itemVerifyText(item, idx) {
if (this.orderQueryIsSandan) return '';
// 已核实:绿底即完成状态,不再显示文字标签;未核实显示已扫 x/y
if (this.isItemVerified(item, idx)) return '';
const current = this.groupVerified[this.groupItemKey(item, idx)] || 0;
const qty = Math.max(1, Number(item && item.plan_qty) || 1);
return `${current}/${qty}`;
},
// 商品行已扫数:已核实返回 plan_qty,否则返回当前已扫次数
groupItemScanned(item, idx) {
const qty = Math.max(1, Number(item && item.plan_qty) || 1);
const current = this.groupVerified[this.groupItemKey(item, idx)] || 0;
return Math.min(current, qty);
},
// 扫描条码与订单信息条码比对:命中一次即标记该商品已完成(数量一次扫满)
// 返回 true=命中商品条码已核实;false=未命中(供调用方判断是否切换面单)
handleGroupVerifyScan(barcode) {
const code = String(barcode || '').trim();
if (!code) return false;
if (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(code) !== -1) {
const name = String(item.item_name || '商品').trim();
// 团单:条码比对命中一次即标记该商品已完成(数量一次扫满)
this.markItemVerified(item, i);
this.speakText('数据一致');
uni.showToast({ title: `${name} 已核实`, icon: 'none' });
return true;
}
}
this.speakText('无记录');
uni.showToast({ title: '条码与待核实商品不匹配', icon: 'none' });
return false;
},
// 清空当前订单查询与团购核实状态(不打包,回到可查询新面单状态)
resetOrderQuery() {
this.groupVerified = {};
this.groupAutoSubmitted = false;
this.packRestored = false;
this.orderQueryState = '';
this.orderQueryResult = null;
this.orderQueryError = '';
this.orderBarcode = '';
this.packContextKey = '';
},
// 长按复核:团单任意未核实商品可通过“无条码复核”人工标记已核实
handleGroupItemLongPress(item, idx) {
if (this.orderQueryIsSandan) return;
if (this.isItemVerified(item, idx)) return;
const name = String(item.item_name || '该商品').trim();
const qty = Math.max(1, Number(item.plan_qty) || 1);
const current = this.groupVerified[this.groupItemKey(item, idx)] || 0;
this.noBarcodeItem = { name, current, qty, item, idx };
this.noBarcodePopupOpen = true;
},
// 无条码复核:确认标记已核实
confirmNoBarcodeReview() {
const info = this.noBarcodeItem;
if (!info) return;
this.markItemVerified(info.item, info.idx);
this.speakText('数据一致');
this.noBarcodePopupOpen = false;
// 延迟清空,避免关闭动画期间文案闪变
setTimeout(() => {
this.noBarcodeItem = null;
}, 300);
},
// 关闭无条码复核弹窗
handleCloseNoBarcodePopup() {
this.noBarcodePopupOpen = false;
// 延迟清空,避免关闭动画期间文案闪变为占位符
setTimeout(() => {
this.noBarcodeItem = null;
}, 300);
},
// 取消团购核实:打开取消核实弹窗
handleCancelGroupVerify() {
this.cancelVerifyPopupOpen = true;
},
// 确认取消核实
confirmCancelVerify() {
this.cancelVerifyPopupOpen = false;
// 清除核实与当前订单结果,回到可扫描其它运单状态
this.groupVerified = {};
this.groupAutoSubmitted = false;
this.packRestored = false;
this.orderQueryState = '';
this.orderQueryResult = null;
this.orderQueryError = '';
this.orderBarcode = '';
this.packContextKey = '';
uni.showToast({ title: '已取消核实', icon: 'none' });
this.speakText('已取消核实');
},
// 关闭取消核实弹窗(继续核实)
handleCloseCancelVerifyPopup() {
this.cancelVerifyPopupOpen = false;
},
// 团购全部商品核实后:提交开始打包(packOrder status=1)并语音
async handleSubmitGroupPack() {
if (this.groupSubmitting || !this.groupAllVerified) return;
this.groupSubmitting = true;
try {
const ok = await this.reportPackOrder();
if (ok) {
this.speakText('开始打包');
}
} finally {
this.groupSubmitting = false;
}
},
// 顶部操作员姓名按钮:已绑定态直接弹移除二次确认;未绑定态打开操作员弹窗准备枪扫/输入工牌绑定
handleUserInfo() {
// 已绑定:简化操作,直接弹移除操作员二次确认弹窗
if (this.boundOperators.length) {
this.handleRemoveOperator();
return;
}
// 未绑定:打开操作员弹窗
this.userDrawerOpen = true;
// 确保广播监听(从其它页面返回时可能已 pause),未绑定时扫码即识别绑定
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
// 重置识别待绑定态并聚焦输入框,便于扫码枪/键盘输入
this.opScanCode = '';
this.opQueryState = '';
this.opQueryResult = null;
this.opQueryError = '';
this.$nextTick(() => {
setTimeout(() => {
this.opInputFocus = true;
}, 300);
});
},
// 关闭操作员弹窗
handleCloseUserDrawer() {
this.userDrawerOpen = false;
this.opInputFocus = false;
},
// 广播扫码结果:未绑定操作员 → 识别并自动绑定;已绑定 → 查询订单
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);
}
},
// 订单查询输入框回车确认
handleOrderQueryConfirm() {
const code = String(this.orderBarcode || '').trim();
if (!code) {
uni.showToast({ title: '请输入/扫描运单号', icon: 'none' });
return;
}
this.handleBarcodeInput(code);
},
// 订单查询相机扫码
handleOrderCameraScan() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
success: (res) => {
const code = String(res?.result || '').trim();
if (!code) return;
this.handleBarcodeInput(code);
},
fail: () => {}
});
},
// 订单唯一标识:散单比 waybill_code(barcode 兜底),团单比 wave_no(batch.wave_no 优先,order.wave_no 兜底)
orderIdentity(result) {
if (!result || typeof result !== 'object') return '';
if (Number(result.isSandan) === 1) {
return String(result.waybill_code || result.barcode || '').trim();
}
const batchNo = result.batch && result.batch.wave_no ? String(result.batch.wave_no) : '';
const orderNo = result.order && result.order.wave_no ? String(result.order.wave_no) : '';
return String(batchNo || orderNo || '').trim();
},
// 重复查单判断:本次查询结果与当前「打包中」订单相同(团单比 wave_no,散单比 waybill_code)
sameOrderQuery(result) {
if (!this.hasActivePack || !this.activePackIdentity) return false;
const identity = this.orderIdentity(result);
return !!identity && identity === this.activePackIdentity;
},
// 按运单号条码查询订单(workbench.queryOrder)
async queryOrder(barcode) {
const code = String(barcode || '').trim();
if (!code) return;
// 无成员(未绑定操作员)时不允许查询订单
if (!this.boundOperators.length) {
this.speakText('未绑定操作员');
uni.showToast({ title: '请先绑定操作员再查询订单', icon: 'none', duration: 4000 });
return;
}
const token = String(this.workbenchToken || '').trim();
if (!token) {
uni.showToast({ title: '工作台 token 缺失', icon: 'none' });
return;
}
if (this.orderQuerying) return;
// 记录上一次查询结果:重复查同一「打包中」订单时据此保持显示、不重复上报
const prevResult = this.orderQueryResult;
this.orderQuerying = true;
this.orderQueryState = 'loading';
this.orderQueryResult = null;
this.orderQueryError = '';
uni.showLoading({ title: '查询中...', mask: true });
try {
// toastAfter=false:失败提示由本方法自行控制,避免拦截器重复弹 toast
const res = await this.$http('workbench.queryOrder', { token, barcode: code }, '', false);
const invalid = res?.flag === 'failure' || [0, 401, 403].indexOf(Number(res?.code)) !== -1;
if (invalid) {
// 401:工作台 token 失效,退出工作台模式并清除 token 回登录页
if (this.handleWorkbenchAuthExpired(res?.code)) return;
this.orderQueryState = 'error';
this.orderQueryError = res?.message || '查询失败,请重试';
this.speakText('无记录');
return;
}
const data = (res && typeof res === 'object' && res.data && typeof res.data === 'object') ? res.data : res;
if (!data || typeof data !== 'object') {
this.orderQueryState = 'error';
this.orderQueryError = '查询结果无效';
return;
}
// 重复查单:本次查询与当前「打包中」订单相同(团单比 wave_no,散单比 waybill_code),
// 保持「打包中」状态展示,不重复上报开始打包
if (this.sameOrderQuery(data)) {
this.orderQueryResult = prevResult;
this.orderQueryState = 'success';
this.orderQueryError = '';
this.orderBarcode = '';
this.speakText('订单打包中');
uni.showToast({ title: '订单打包中,请勿重复上报', icon: 'none' });
return;
}
this.orderQueryResult = data;
this.orderQueryState = 'success';
// 新查询正常进入,清除恢复态
this.packRestored = false;
// 打包上下文 key:packOrder 凭 key 由服务端解析订单信息,前端不回传订单数据
this.packContextKey = String(data?.key || '').trim();
// 查询成功:清空输入框,方便连续扫描下一单
this.orderBarcode = '';
// 团购:初始化商品核实状态(不自动上报,全部核实后将自动提交开始打包)
this.groupVerified = {};
this.groupAutoSubmitted = false;
// 团购:查询后立即预检(未复核/已打包时提示并语音,商品明细已隐藏),命中则不进入核实流程
let precheckBlocked = false;
if (!this.orderQueryIsSandan) {
precheckBlocked = !this.packPrecheck();
}
// 兜底:无商品明细且未禁止打包的团购单视为无需核实,直接自动提交开始打包
if (!precheckBlocked && !this.orderQueryIsSandan && this.groupAllVerified && !this.groupAutoSubmitted) {
this.groupAutoSubmitted = true;
this.handleSubmitGroupPack();
}
if (this.orderQueryIsSandan) {
// 散单:扫描面单立即上报开始打包(等查询 loading 关闭后再发起)
setTimeout(() => {
this.reportPackOrder().then((ok) => {
if (ok) this.speakText('开始打包');
});
}, 0);
}
} catch (error) {
console.error('[packMode] 查询订单失败:', error);
this.orderQueryState = 'error';
this.orderQueryError = error?.message || '查询失败,请重试';
} finally {
uni.hideLoading();
this.orderQuerying = false;
}
},
// 商品明细首张图片(image_url 为数组或字符串时取首个非空)
orderItemImg(item) {
if (!item) return '';
const url = item.image_url ?? item.imageUrl;
if (Array.isArray(url)) {
const first = url.find(u => u);
return String(first || '');
}
return String(url || '');
},
// 商品明细图片列表(多图:image_url 数组 / images 数组;单图兜底 imageUrl)
orderItemImages(item) {
if (!item) return [];
let list = [];
const url = item.image_url ?? item.imageUrl;
if (Array.isArray(url)) {
list = url;
} else if (url) {
list = [url];
}
if (Array.isArray(item.images)) {
const imgs = item.images.map(u => String(u || '').trim()).filter(Boolean);
if (imgs.length) list = imgs;
}
return list.map(u => String(u || '').trim()).filter(Boolean);
},
// 点击商品图放大预览(支持多图切换)
previewItemImage(item) {
const images = this.orderItemImages(item);
if (!images.length) return;
const current = this.orderItemImg(item) || images[0];
uni.previewImage({
current,
urls: images
});
},
// 商品明细条码(barcodes 数组取首项 barcode,或字符串直接返回)
orderItemBarcode(item) {
if (!item) return '';
const codes = item.barcodes ?? item.barcode;
if (Array.isArray(codes)) {
const first = codes.find(c => c);
if (first && typeof first === 'object') return String(first.barcode || first.code || '');
return String(first || '');
}
if (codes && typeof codes === 'object') return String(codes.barcode || codes.code || '');
return String(codes || '');
},
// 打包预检(上报 packOrder 前):散单拦截 → 未复核 → 已打包;命中则文字+语音提示并禁止打包
packPrecheck() {
const r = this.orderQueryResult;
const order = r && r.order;
if (!order) return true;
// 1. 拦截:仅散单判断(团购不做拦截)
if (this.orderQueryIsSandan && Number(order.intercept_flag) === 1) {
this.speakText('订单已拦截,禁止打包');
uni.showToast({ title: '订单已拦截,禁止打包', icon: 'none', duration: 3000 });
return false;
}
// 2. 未复核(recheck_status 非完成视为未复核,团散都判)
const recheck = String(order.recheck_status ?? '').trim().toLowerCase();
const recheckDone = recheck === 'fin' || recheck === 'finished' || recheck === '1';
if (!recheckDone) {
this.speakText('订单未复核,禁止打包');
uni.showToast({ title: '订单未复核,禁止打包', icon: 'none', duration: 3000 });
return false;
}
// 3. 已打包:散单看 pack_flag=1;团购无 pack_flag 用 pack_status 非空/非 none
let packed = false;
if (this.orderQueryIsSandan) {
packed = Number(order.pack_flag) === 1 || order.pack_flag === true;
} else {
const ps = String(order.pack_status ?? '').trim().toLowerCase();
packed = ps !== '' && ps !== 'none';
}
if (packed) {
this.speakText('已打包');
uni.showToast({ title: '已打包', icon: 'none', duration: 3000 });
return false;
}
return true;
},
// 工作台打包上报(workbench.packOrder):基于最近一次查询结果,状态=1 打包中;成功返回 true
async reportPackOrder() {
const r = this.orderQueryResult;
if (!r) return false;
// 打包预检:订单未复核/拦截/已打包时提示并禁止开始打包
if (!this.packPrecheck()) return false;
const token = String(this.workbenchToken || '').trim();
if (!token) return false;
if (this.packReporting) return false;
// 打包上下文 key:来自 workbench.queryOrder 响应(20 分钟有效),订单信息由服务端从 key 解析,前端不回传订单信息
const packKey = String(this.packContextKey || '').trim();
if (!packKey) {
uni.showToast({ title: '缺少打包上下文,请重新扫码查询', icon: 'none' });
return false;
}
// 打包人员:当前已绑定操作员(可多人)
const operators = this.boundOperators;
if (!operators || !operators.length || !operators.some(op => String(op && op.userName || '').trim())) {
uni.showToast({ title: '请先绑定操作员再上报打包', icon: 'none' });
return false;
}
this.packReporting = true;
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
}))
};
// toastAfter=false:失败提示由本方法自行控制
const res = await this.$http('workbench.packOrder', payload, '', false);
const invalid = res?.flag === 'failure' || [0, 400, 401, 403].indexOf(Number(res?.code)) !== -1;
if (invalid) {
// 401:工作台 token 失效,退出工作台模式并清除 token 回登录页
if (this.handleWorkbenchAuthExpired(res?.code)) return false;
// 400:打包上下文 key 缺失或过期(跨仓库/跨工作台消费他人 key 为 403),提示重新扫码
if (Number(res?.code) === 400) {
uni.showToast({ title: res?.message || '打包上下文已失效,请重新扫码查询', icon: 'none' });
return false;
}
uni.showToast({ title: res?.message || '打包上报失败', icon: 'none' });
return false;
}
console.log('[packMode] 打包上报成功:', res?.data || res);
// 记录存在未结束打包任务:退出工作台/解绑操作员前将自动上报打包完成
this.hasActivePack = true;
// 记录当前「打包中」订单标识,重复扫描同一订单时保持打包中、不重复上报
this.activePackIdentity = this.orderIdentity(this.orderQueryResult);
uni.showToast({ title: '已开始打包', icon: 'success' });
return true;
} catch (error) {
console.error('[packMode] 打包上报失败:', error);
uni.showToast({ title: error?.message || '打包上报失败', icon: 'none' });
return false;
} finally {
uni.hideLoading();
this.packReporting = false;
}
},
// 工作台打包完成请求(workbench.finishPack):结束该工作台最后一个未结束打包任务
async requestFinishPack() {
const token = String(this.workbenchToken || '').trim();
if (!token) return { ok: false, error: '工作台 token 缺失' };
if (this.finishPacking) return { ok: false, busy: true };
this.finishPacking = true;
try {
// toastAfter=false:失败提示由调用方自行控制
const res = await this.$http('workbench.finishPack', { token }, '', false);
const invalid = res?.flag === 'failure' || [401, 403].indexOf(Number(res?.code)) !== -1;
if (invalid) {
// 401:工作台 token 失效,退出工作台模式并清除 token 回登录页
if (this.handleWorkbenchAuthExpired(res?.code)) {
return { ok: false, expired: true, error: '工作台登录已失效' };
}
return { ok: false, error: res?.message || '完成打包失败' };
}
const data = (res && typeof res === 'object' && res.data && typeof res.data === 'object') ? res.data : res;
const finished = !!(data && (data.finished === true || data.finished === 'true' || data.finished === 1));
if (finished) {
this.hasActivePack = false;
this.activePackIdentity = '';
}
return {
ok: true,
finished,
error: finished ? '' : (data?.message || '当前无进行中的打包任务')
};
} catch (error) {
console.error('[packMode] 完成打包失败:', error);
return { ok: false, error: error?.message || '完成打包失败' };
} finally {
this.finishPacking = false;
}
},
// 广播调用兜底(广播 store 未初始化/禁用时静默失败)
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[packMode] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[packMode] broadcast/${action} 调用异常:`, error);
}
},
// 归一化广播扫描结果文本(去除所有空白字符,仅保留有效字符)
normalizeScanResult(scanResult) {
const clean = (v) => String(v || '').replace(/\s+/g, '');
if (!scanResult) return '';
if (typeof scanResult === 'string') return clean(scanResult);
if (typeof scanResult.result === 'string') return clean(scanResult.result);
if (Array.isArray(scanResult.result)) {
const firstResult = scanResult.result.find(item => item);
if (typeof firstResult === 'string') return clean(firstResult);
if (firstResult && typeof firstResult.data === 'string') return clean(firstResult.data);
}
if (typeof scanResult.data === 'string') return clean(scanResult.data);
return '';
},
// 读取本地保存的已绑定操作员列表(bindMember 返回的成员行 id,按 workbenchId 匹配;兼容旧版单操作员缓存)
loadBoundOperators() {
let list = null
try {
list = uni.getStorageSync('workbenchOperators')
} catch (e) {}
if (!Array.isArray(list)) {
// 兼容旧版单操作员缓存(workbenchOperator 对象)
let saved = null
try {
saved = uni.getStorageSync('workbenchOperator')
} catch (e) {}
if (saved && typeof saved === 'object' && String(saved?.memberId || '')) {
list = [saved]
} else {
list = []
}
}
const wbId = String(this.workbenchId || '')
this.boundOperators = list
.filter(op => op && String(op?.memberId || ''))
.filter(op => !op.workbenchId || String(op.workbenchId) === wbId)
.map(op => ({
memberId: String(op.memberId),
workbenchId: String(op.workbenchId || wbId),
userId: (op.userId === null || op.userId === undefined || op.userId === '') ? '' : String(op.userId),
userName: String(op.userName || '')
}))
},
// 归一化服务端 members[] 为统一结构 { id, workbench_id, user_id, user_name }
normalizeWorkbenchMembers(members, workbenchId) {
const wbId = workbenchId === null || workbenchId === undefined ? '' : workbenchId;
return (Array.isArray(members) ? members : [])
.filter((m) => m && (m.id || m.member_id || m.memberId || m.user_name || m.userName || m.real_name || m.name))
.map((m) => ({
id: (m.id || m.member_id || m.memberId || ''),
workbench_id: (m.workbench_id ?? m.workbenchId ?? wbId ?? ''),
user_id: (m.user_id ?? m.userId ?? m.wms_account_id ?? m.wmsAccountId ?? null),
user_name: String(m.user_name ?? m.userName ?? m.real_name ?? m.realName ?? m.name ?? '')
}))
.filter((m) => m.id || m.user_name);
},
// 应用成员列表:写入 workbenchMembers + 本地缓存,并同步 boundOperators(现有业务依赖)
// 同一 user_id 只保留一个(服务端重复绑定会产生多行成员,显示/上报需去重)
applyWorkbenchMembers(members) {
const seen = new Set();
const list = (Array.isArray(members) ? members : []).filter((m) => {
if (!m || (!m.id && !m.user_name)) return false;
const uid = m.user_id;
const key = (uid !== null && uid !== undefined && uid !== '') ? ('uid_' + uid) : ('id_' + m.id);
if (seen.has(key)) return false;
seen.add(key);
return true;
});
this.workbenchMembers = list;
try {
uni.setStorageSync(MEMBER_STORAGE_KEY, list);
} catch (e) {}
const wbId = String(this.workbenchId || '');
this.boundOperators = list
.map((m) => ({
memberId: m.id === null || m.id === undefined ? '' : String(m.id),
workbenchId: String(m.workbench_id || wbId),
userId: (m.user_id === null || m.user_id === undefined || m.user_id === '') ? '' : String(m.user_id),
userName: String(m.user_name || '')
}))
.filter((op) => op.memberId);
try {
uni.setStorageSync('workbenchOperators', this.boundOperators);
} catch (e) {}
},
// 恢复本地缓存的工作台成员列表(服务端 members 缓存;缺失时用 boundOperators 兜底保持一致)
restoreWorkbenchMembers() {
let cached = null;
try {
cached = uni.getStorageSync(MEMBER_STORAGE_KEY);
} catch (e) {}
if (Array.isArray(cached) && cached.length) {
this.applyWorkbenchMembers(cached.filter((m) => m && (m.id || m.user_name)));
return;
}
// 无新缓存:用 boundOperators 兜底映射,保持 workbenchMembers 与 boundOperators 一致
const list = (Array.isArray(this.boundOperators) ? this.boundOperators : [])
.filter((op) => op && op.memberId);
this.workbenchMembers = list.map((op) => ({
id: String(op.memberId),
workbench_id: String(op.workbenchId || this.workbenchId || ''),
user_id: (op.userId === null || op.userId === undefined || op.userId === '') ? null : op.userId,
user_name: String(op.userName || '')
}));
},
// 操作员扫码输入框回车确认
handleOpInputConfirm() {
const code = String(this.opScanCode || '').trim();
if (!code) return;
// 识别成功后输入框回显的是姓名(非工牌码),避免把姓名当码再次查询
if (this.opQueryState === 'identified' && this.opQueryResult && code === this.opQueryResult.name) {
return;
}
this.queryOperatorUser(code);
},
// 操作员相机扫码
handleOpCameraScan() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
success: (res) => {
const code = String(res?.result || '').trim();
if (!code) return;
this.opScanCode = code;
this.opInputFocus = false;
this.queryOperatorUser(code);
},
fail: () => {}
});
},
// 操作员识别失败统一提示(扫描值非有效工牌码时,提示先绑定操作员)
notifyOperatorIdentifyFailed() {
this.speakText('未绑定操作员');
uni.showToast({ title: '请先绑定操作员再查询订单', icon: 'none', duration: 4000 });
// 识别失败后重新拉起广播监听,确保主页面连续扫码仍能收到广播
this.safeDispatchBroadcast('resume');
},
// 按 ye4s 登录临时码识别操作员(index.queryUserByToken),成功后进入待绑定态
async queryOperatorUser(token) {
const t = String(token || '').trim();
if (!t) return;
if (this.opQueryState === 'loading' || this.opBinding) return;
this.opQueryState = 'loading';
this.opQueryResult = null;
this.opQueryError = '';
uni.showLoading({ title: '识别中...', mask: true });
try {
// toastAfter=false:失败提示由本方法自行控制,避免拦截器重复弹 toast
const res = await this.$http('index.queryUserByToken', { token: t }, '', 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) {
this.opQueryState = 'error';
this.opQueryError = '未识别到操作员姓名';
this.notifyOperatorIdentifyFailed();
return;
}
const rawWmsId = data?.wms_account_id ?? data?.wmsAccountId;
this.opQueryResult = {
scanToken: t,
name,
wmsAccountId: (rawWmsId === null || rawWmsId === undefined || rawWmsId === '') ? null : Number(rawWmsId)
};
// 识别成功直接进入绑定流程(binding 态不展示绑定按钮,避免按钮一闪而过)
this.opQueryState = 'binding';
// 扫描/输入成功且识别到姓名:输入框直接回显姓名
this.opScanCode = name;
this.opInputFocus = false;
// 有效扫描值直接完成绑定(延迟到识别 loading 关闭后,避免与绑定 loading 冲突)
setTimeout(() => {
this.handleBindOperator();
}, 0);
} else {
const code = Number(res?.code);
// 401:工作台 token 失效,退出工作台模式并清除 token 回登录页
if (this.handleWorkbenchAuthExpired(code)) return;
const msg = String(res?.message || res?.msg || '');
if (code === 404) {
this.opQueryError = '未找到对应用户';
} else if (code === 400) {
this.opQueryError = 'token 不能为空';
} else {
this.opQueryError = msg || '识别失败,请重试';
}
this.opQueryState = 'error';
this.notifyOperatorIdentifyFailed();
}
} catch (error) {
console.error('[packMode] 识别操作员失败:', error);
this.opQueryState = 'error';
this.opQueryError = error?.message || '识别失败,请重试';
this.notifyOperatorIdentifyFailed();
} finally {
uni.hideLoading();
}
},
// 绑定操作员到本工作台(workbench.bindMember)
async handleBindOperator() {
const ident = this.opQueryResult;
if (!ident) return;
const token = String(this.workbenchToken || '').trim();
if (!token) {
uni.showToast({ title: '工作台 token 缺失', icon: 'none' });
return;
}
if (this.opBinding) return;
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,
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;
throw new Error(res?.message || '绑定操作员失败');
}
const data = (res && typeof res === 'object' && res.data && typeof res.data === 'object') ? res.data : res;
const memberId = data?.id ?? data?.member_id ?? data?.memberId;
if (memberId === null || memberId === undefined || memberId === '') {
throw new Error('绑定成功但未返回成员ID');
}
// bindMember 返回后本地保存成员行 id(供 removeMember 使用),追加到当前操作员列表
const mid = String(memberId);
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)
};
const wmList = Array.isArray(this.workbenchMembers) ? this.workbenchMembers.slice() : [];
const wmIdx = wmList.findIndex((m) => String(m && m.id) === mid);
if (wmIdx >= 0) {
wmList[wmIdx] = member;
} else {
wmList.push(member);
}
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 });
} catch (error) {
console.error('[packMode] 绑定操作员失败:', error);
// 绑定失败:进入待绑定态,保留识别结果,展示「绑定」按钮供手动重试
this.opQueryState = 'identified';
uni.showToast({ title: error?.message || '绑定操作员失败,请点击绑定重试', icon: 'none' });
this.speakText('绑定失败,请点击绑定重试');
} 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 || '');
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);
}
},
// 确认移除操作员:按勾选的成员行 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);
},
// 执行移除成员请求(silent=true 时为退出工作台前的静默解绑:不弹 loading/toast/语音)
// 支持一次移除多个操作员(ids 传数组);全员下线(移除后无成员)时先 finishPack 再 clearPackState() 清空订单数据
async doRemoveOperators(ids, opts = {}) {
const silent = !!opts.silent;
const idList = (Array.isArray(ids) ? ids : [ids])
.map(v => String(v == null ? '' : v).trim())
.filter(Boolean);
if (!idList.length) {
if (!silent) uni.showToast({ title: '成员行ID不能为空', icon: 'none' });
return { ok: false, error: '成员行ID不能为空' };
}
if (this.opRemoving) return { ok: false, busy: true };
const token = String(this.workbenchToken || '').trim();
if (!token) {
if (!silent) uni.showToast({ title: '工作台 token 缺失', icon: 'none' });
return { ok: false, error: '工作台 token 缺失' };
}
this.opRemoving = true;
if (!silent) uni.showLoading({ title: '移除中...', mask: true });
try {
const res = await this.$http('workbench.removeMember', {
ids: idList.map(Number),
token
});
const bizCode = Number(res?.code);
// 404:成员行已不存在(已被其它设备移除/下线),视为已移除,继续走本地清理流程
const missing = bizCode === 404;
const invalid = !missing && (res?.flag === 'failure' || [400, 403].indexOf(bizCode) !== -1);
if (invalid) {
// 401:工作台 token 失效,退出工作台模式并清除 token 回登录页
if (this.handleWorkbenchAuthExpired(bizCode)) return { ok: false, expired: true };
throw new Error(res?.message || '移除操作员失败');
}
// 从本地列表移除已移除的成员行(同步 workbenchMembers 与 boundOperators)
const removedSet = new Set(idList);
const wmList = (Array.isArray(this.workbenchMembers) ? this.workbenchMembers : [])
.filter(m => !removedSet.has(String(m && m.id || '')));
if (wmList.length) {
this.applyWorkbenchMembers(wmList);
} else {
// 全员下线:清空成员列表与本地缓存
this.workbenchMembers = [];
uni.removeStorageSync(MEMBER_STORAGE_KEY);
this.boundOperators = [];
uni.removeStorageSync('workbenchOperators');
}
this.opScanCode = '';
this.opQueryState = '';
this.opQueryResult = null;
this.opQueryError = '';
// 全员下线(移除后工作台已无任何成员):先 finishPack 再 clearPackState() 清空订单数据
if (!this.boundOperators.length) {
const fr = await this.requestFinishPack();
if (fr && fr.expired) return { ok: false, expired: true };
this.clearPackState();
}
if (!silent) {
uni.showToast({ title: '操作员已移除', icon: 'success' });
this.speakText('移除成功');
// 下线后静默重拉工作台信息,成员列表以服务端为准(退出流程 silent 不重拉)
this.fetchWorkbenchInfo({ silent: true });
}
return { ok: true };
} catch (error) {
console.error('[packMode] 移除操作员失败:', error);
if (!silent) {
uni.showToast({ title: error?.message || '移除操作员失败', icon: 'none' });
this.speakText('移除失败');
}
return { ok: false, error: error?.message };
} finally {
if (!silent) uni.hideLoading();
this.opRemoving = false;
}
},
// 清空订单打包状态与查询/核实数据(全员下线、退出工作台时调用)
clearPackState() {
this.orderBarcode = '';
this.orderQueryState = '';
this.orderQueryResult = null;
this.orderQueryError = '';
this.packContextKey = '';
this.groupVerified = {};
this.groupAutoSubmitted = false;
this.hasActivePack = false;
this.activePackIdentity = '';
this.packRestored = false;
},
// 读取本地已绑定信息(wblc 免登录 / 绑定成功均写入 storage)
loadBound(options) {
const cached = uni.getStorageSync('workbenchInfo') || {};
// 优先使用 storage 中的原始信息(UTF-8),避免真机上 URL 中文参数乱码
this.workbenchId = String(cached?.id || options?.workbenchId || '');
this.workbenchName = String(cached?.name || options?.workbenchName || '');
this.workbenchToken = String(cached?.token || uni.getStorageSync('workbenchToken') || '');
this.warehouseId = String(cached?.warehouse_id ?? cached?.warehouseId ?? '');
this.workbenchStatus = cached?.status ?? '';
this.workbenchType = String(cached?.type || '');
this.bound = !!this.workbenchToken;
},
// 从 getWorkbenchInfo 响应恢复「进行中的打包任务」:服务端是唯一事实来源,
// 把服务端记录的未结束任务画回界面(商品明细全部视为已核实、显示打包中、跳过拦截/已打包/预检)
restoreCurrentPackTask(raw) {
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);
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);
});
const waveNo = String(
(wave && (wave.wave_no ?? wave.waveNo)) ||
(orderList[0] && (orderList[0].wave_no ?? orderList[0].waveNo)) || ''
).trim();
// 散单恢复运单号:waybill_code(运单号)优先,express.waybill_code 次之,delivery_order_code(发货单号)最后兜底;
// 用 || 跳过空字符串;团购为波次,无单一运单号,置空
const firstOrder = orderList[0] || {};
const express = firstOrder.express || {};
const waybill = hasWave
? ''
: String(
firstOrder.waybill_code ||
express.waybill_code ||
firstOrder.delivery_order_code ||
firstOrder.waybillCode ||
firstOrder.barcode ||
''
).trim();
// 波次总单数:current_wave.order_count 优先,兜底 current_orders 数量
const rawTotal = wave && (wave.order_count ?? wave.total_orders ?? wave.totalOrders);
const totalOrders = (rawTotal !== undefined && rawTotal !== null) ? rawTotal : orderList.length;
const mappedItems = items.map((it, i) => {
const o = it || {};
// 实际字段:item_id(wms_item id)为主;item.id 可能为 0(无效),不能用于核实 key
const rawId = o.item_id ?? o.itemId ?? o.sku_id ?? o.id;
const hasValidId = rawId !== undefined && rawId !== null && rawId !== 0 && rawId !== '';
return {
id: hasValidId ? rawId : i,
plan_qty: Number((o.plan_qty ?? o.qty ?? o.num) || 1) || 1,
item_name: String((o.item_name ?? o.itemName ?? o.name ?? o.sku_name) || '').trim(),
item_code: String((o.item_code ?? o.itemCode ?? o.sku_code) || '').trim(),
barcodes: o.barcodes ?? o.barcode,
image_url: o.image_url ?? o.imageUrl ?? o.image,
need_recheck: o.need_recheck
};
});
this.orderQueryResult = {
isSandan,
waybill_code: waybill,
barcode: waybill,
key: '', // 恢复态无需再发起 packOrder,不携带打包上下文 key
store_remark: String((orderList[0] && (orderList[0].store_remark ?? orderList[0].storeRemark)) || ''),
// 散单恢复运单信息(包材名称/物流公司/称重重量);团购 express 为 null,置 undefined
express: hasWave ? undefined : {
waybill_code: express.waybill_code,
logistics_name: express.logistics_name,
weighing_weight: express.weighing_weight,
package_material_name: express.package_material_name
},
batch: hasWave ? { wave_no: waveNo, total_orders: totalOrders } : undefined,
order: {
wave_no: waveNo,
recheck_status: 'fin', // 恢复态跳过未复核判断
pack_status: 'packing', // 恢复态跳过已打包判断(packRestored 兜底)
items_count: mappedItems.length,
items_total: mappedItems.reduce((s, it) => s + (Number(it.plan_qty) || 0), 0)
},
items: mappedItems
};
// 恢复「打包中」状态:全部商品视为已核实
const verified = {};
mappedItems.forEach((it, i) => {
verified[this.groupItemKey(it, i)] = Math.max(1, Number(it.plan_qty) || 1);
});
// 先置 groupAutoSubmitted 再写 groupVerified,避免 groupAllVerified 变化触发重复提交打包
this.groupAutoSubmitted = true;
this.groupVerified = verified;
this.orderQueryState = 'success';
this.orderQueryError = '';
this.orderBarcode = '';
this.packContextKey = '';
this.hasActivePack = true;
this.activePackIdentity = this.orderIdentity(this.orderQueryResult);
this.packRestored = true; // 跳过拦截/已打包/预检,展示进行中任务
console.log('[packMode] 恢复进行中打包任务:', { isSandan, waveNo, waybill, items: mappedItems.length });
},
// 重新拉取工作台信息:进入打包模式时校验本地工作台 token 并刷新工作台信息
// silent=true:静默刷新(绑定/下线成功后重拉同步成员),失败不弹 toast
async fetchWorkbenchInfo(options = {}) {
const silent = !!options.silent;
const token = String(this.workbenchToken || '').trim();
if (!token) return;
if (silent) {
if (this.infoRefreshingSilent) return;
this.infoRefreshingSilent = true;
} else {
if (this.infoRefreshing) return;
this.infoRefreshing = true;
}
try {
const res = await this.$http('workbench.getWorkbenchInfo', { token });
const invalid = res?.flag === 'failure' || Number(res?.code) === 400 || Number(res?.code) === 403;
if (invalid) {
console.warn('[packMode] 工作台 token 已失效,退出工作台模式:', res?.message || res?.code);
await this.exitWorkbench(true);
return;
}
const data = (res && typeof res === 'object' && res.data && typeof res.data === 'object')
? res.data
: res;
if (!data || typeof data !== 'object') {
await this.exitWorkbench(true);
return;
}
const detail = {
id: data?.workbench_id ?? data?.workbenchId ?? data?.id ?? this.workbenchId,
name: String(data?.name || this.workbenchName),
warehouse_id: data?.warehouse_id ?? data?.warehouseId ?? '',
status: data?.status ?? '',
type: String(data?.type || ''),
remark: String(data?.remark || ''),
token
};
// 刷新页面展示与本地缓存
this.workbenchId = String(detail.id);
this.workbenchName = detail.name;
this.warehouseId = String(detail.warehouse_id ?? '');
this.workbenchStatus = detail.status ?? '';
this.workbenchType = detail.type;
uni.setStorageSync('workbenchInfo', detail);
// 同步工作台在线成员列表(服务端 members 为权威,含绑定/下线后的最新状态)
if (Array.isArray(data?.members)) {
this.applyWorkbenchMembers(this.normalizeWorkbenchMembers(data.members, detail.id));
}
// 恢复进行中的打包任务(服务端是唯一事实来源:current_wave / current_orders)
this.restoreCurrentPackTask(data);
console.log('[packMode] 工作台信息刷新成功:', detail);
} catch (error) {
// 网络/其它异常:保留本地缓存信息继续使用,仅提示,不清除会话
console.warn('[packMode] 工作台信息刷新失败,沿用本地缓存:', error);
if (!silent) {
uni.showToast({ title: '工作台信息刷新失败', icon: 'none' });
}
} finally {
if (silent) {
this.infoRefreshingSilent = false;
} else {
this.infoRefreshing = false;
}
}
},
// 退出工作台模式(用户主动):打开退出确认弹窗
handleBack() {
this.exitPopupOpen = true;
},
// 确认退出工作台
async confirmExit() {
this.exitPopupOpen = false;
// 退出工作台 = 同时解绑操作员:操作员已绑定时先静默批量解绑(不弹提示,随后统一退出)
const ids = this.boundOperators.map(op => String(op && op.memberId || '').trim()).filter(Boolean);
if (ids.length && String(this.workbenchToken || '').trim()) {
const unbind = await this.doRemoveOperators(ids, { silent: true });
// 401 已由 handleWorkbenchAuthExpired 处理退出并回登录页,无需重复退出
if (unbind && unbind.expired) return;
}
await this.exitWorkbench(false);
},
// 关闭退出弹窗
handleCloseExitPopup() {
this.exitPopupOpen = false;
},
// 清除工作台 token 并返回登录页:工作台会话(主 token 即工作台 token)时一并清除主登录态
async exitWorkbench(withToast = false) {
const wbToken = String(uni.getStorageSync('workbenchToken') || '').trim();
const mainToken = String(uni.getStorageSync('token') || '').trim();
uni.removeStorageSync('workbenchToken');
uni.removeStorageSync('workbenchInfo');
// 退出工作台同时清除本地操作员绑定记录,避免下次进入误恢复旧操作员
uni.removeStorageSync('workbenchOperator');
uni.removeStorageSync('workbenchOperators');
uni.removeStorageSync(MEMBER_STORAGE_KEY);
this.workbenchMembers = [];
this.boundOperators = [];
if (withToast) {
uni.showToast({ title: '工作台登录已失效,请重新登录', icon: 'none' });
}
if (wbToken && mainToken === wbToken) {
try {
// logout 内部 clearSession(store) 会清除主 token / isLogin / userInfo 等并跳回登录页
await this.$store.dispatch('logout');
return;
} catch (error) {
console.warn('[packMode] 退出工作台模式失败,兜底跳转登录页:', error);
}
}
uni.reLaunch({ url: '/pages/login/index' });
},
// 业务请求返回 401(工作台 token 失效):退出工作台模式、清除 token 并回登录页;返回 true 表示已处理退出
handleWorkbenchAuthExpired(code) {
if (Number(code) === 401) {
this.exitWorkbench(true);
return true;
}
return false;
}
}
}
</script>
<style lang="scss" scoped>
.pack-mode-page {
width: 100vw;
height: 100vh;
background: #f5f6f7;
box-sizing: border-box;
overflow: hidden;
}
.top-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
z-index: 999;
background: #ffffff;
}
.status-bar {
height: var(--status-bar-height, 0px);
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 144rpx;
padding: 16rpx 24rpx;
box-sizing: border-box;
background: #ffffff;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
}
.header-left {
display: flex;
align-items: center;
width: 260rpx;
}
.header-left__text {
margin-left: 8rpx;
font-size: 34rpx;
color: #606266;
}
.header-title {
font-size: 34rpx;
font-weight: 600;
color: #303133;
line-height: 1.15;
}
.header-center {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex: 1;
min-width: 0;
}
.header-subtitle {
margin-top: 4rpx;
font-size: 34rpx;
color: #303133;
line-height: 1.25;
text-align: center;
word-break: break-all;
max-width: 100%;
}
.header-right {
width: 260rpx;
display: flex;
align-items: center;
justify-content: flex-end;
}
.user-info-btn {
display: flex;
align-items: center;
gap: 6rpx;
padding: 8rpx 16rpx;
border-radius: 8rpx;
background: #2979ff;
max-width: 248rpx;
}
.user-info-btn--bound {
background: #18b566;
}
.user-info-btn__text {
font-size: 34rpx;
color: #ffffff;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.content {
padding: 0 12rpx 24rpx;
box-sizing: border-box;
height: calc(100vh - var(--status-bar-height, 0px) - 144rpx);
margin-top: calc(var(--status-bar-height, 0px) + 144rpx);
display: flex;
flex-direction: column;
overflow: hidden;
}
/* 已绑定态顶部工作台卡并入 header,以下旧样式不再使用 */
.state-card {
background: #ffffff;
border-radius: 20rpx;
padding: 32rpx 28rpx;
box-sizing: border-box;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
}
.state-badge {
display: flex;
align-items: center;
gap: 12rpx;
margin-bottom: 24rpx;
}
.state-badge__text {
font-size: 36rpx;
font-weight: 600;
color: #303133;
}
.info-block {
display: flex;
flex-direction: column;
gap: 20rpx;
border-top: 1rpx solid #f0f0f0;
padding-top: 24rpx;
}
.info-row {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 20rpx;
}
.info-label {
font-size: 26rpx;
color: #909399;
flex-shrink: 0;
}
.info-value {
font-size: 26rpx;
color: #303133;
text-align: right;
word-break: break-all;
}
.info-value--mono {
font-family: monospace;
font-size: 24rpx;
}
/* ===== 查询订单 ===== */
.order-query-card {
margin-top: 16rpx;
background: #ffffff;
border-radius: 20rpx;
padding: 16rpx 12rpx;
box-sizing: border-box;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
overflow: hidden;
}
.order-query__scan-line {
display: flex;
align-items: center;
gap: 12rpx;
flex-shrink: 0;
}
.order-query__scan-row {
display: flex;
align-items: center;
gap: 8rpx;
background: #f5f6f7;
border: 2rpx solid #e4e7ed;
border-radius: 12rpx;
padding: 0 8rpx 0 20rpx;
box-sizing: border-box;
height: 64rpx;
flex: 1;
min-width: 0;
}
.order-query__scan-row .camera-btn {
width: 52rpx;
height: 52rpx;
flex-shrink: 0;
}
.order-query__input {
flex: 1;
height: 60rpx;
font-size: 34rpx;
color: #303133;
}
.order-query__loading {
margin-top: 16rpx;
padding: 16rpx 0;
display: flex;
justify-content: center;
align-items: center;
}
.order-query__error {
margin-top: 16rpx;
background: #fef0f0;
border-radius: 16rpx;
padding: 16rpx 20rpx;
box-sizing: border-box;
}
.order-query__error-text {
font-size: 34rpx;
color: #f56c6c;
text-align: center;
line-height: 1.5;
}
.order-query__head {
margin-top: 8rpx;
display: flex;
align-items: center;
gap: 16rpx;
border-bottom: 1rpx solid #f0f0f0;
padding-bottom: 8rpx;
flex-shrink: 0;
}
.order-result-waybill {
flex: 1;
font-size: 34rpx;
font-weight: bold;
color: #303133;
word-break: break-all;
}
.order-result-tag {
flex-shrink: 0;
padding: 6rpx 18rpx;
border-radius: 999rpx;
font-size: 28rpx;
}
.order-result-tag--sandan {
background: transparent;
color: #303133;
font-size: 30rpx;
font-weight: 600;
}
.order-result-tag--tuangou {
background: transparent;
color: #303133;
font-size: 30rpx;
font-weight: 600;
}
.order-summary {
margin-top: 12rpx;
background: #f8f9fb;
border-radius: 16rpx;
padding: 12rpx 16rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 6rpx;
flex-shrink: 0;
}
.order-summary__row {
display: flex;
align-items: center;
}
.order-summary__label {
font-size: 30rpx;
color: #909399;
flex-shrink: 0;
margin-right: 20rpx;
}
.order-summary__value {
flex: 1;
font-size: 34rpx;
font-weight: bold;
color: #303133;
word-break: break-all;
min-width: 0;
}
.order-summary__value--strong {
font-size: 38rpx;
}
.order-summary__extra {
flex-shrink: 0;
font-size: 30rpx;
color: #2979ff;
margin-left: 20rpx;
}
.order-summary__tag {
margin-left: 16rpx;
}
.order-summary__num {
font-size: 36rpx;
font-weight: bold;
color: #2979ff;
}
/* 禁止打包:运单/波次行红底 */
.order-summary__row--blocked {
background: #e64340;
border-radius: 8rpx;
padding: 8rpx 12rpx;
}
.order-summary__row--blocked .order-summary__label,
.order-summary__row--blocked .order-summary__value,
.order-summary__row--blocked .order-summary__extra,
.order-summary__row--blocked .order-summary__num,
.order-summary__row--blocked .order-result-tag {
color: #ffffff;
}
.order-block {
margin-top: 12rpx;
background: #f8f9fb;
border-radius: 16rpx;
padding: 16rpx;
box-sizing: border-box;
flex: 1;
min-height: 0;
overflow-y: auto;
}
.order-block__title {
font-size: 26rpx;
font-weight: normal;
color: #303133;
margin-bottom: 8rpx;
}
.order-block--blocked {
display: flex;
align-items: center;
justify-content: center;
}
.order-block__hint {
font-size: 36rpx;
font-weight: 600;
color: #e64340;
text-align: center;
line-height: 1.6;
}
.order-item {
background: #ffffff;
border: 1rpx solid #000000;
border-radius: 10rpx;
margin-top: 12rpx;
overflow: hidden;
}
.order-item__top {
display: flex;
align-items: flex-start;
justify-content: space-between;
}
.order-item__qty-group {
display: flex;
flex-direction: row;
flex: 1;
min-width: 0;
border-bottom: 1rpx solid #000000;
}
.order-item__qty-item {
display: flex;
align-items: center;
flex: 1;
min-width: 0;
padding: 16rpx 0 8rpx 16rpx;
}
.order-item__qty-item:not(:last-child) {
border-right: 1rpx solid #000000;
}
.order-item__label {
font-size: 30rpx;
color: #000000;
flex-shrink: 0;
width: 80rpx;
text-align: left;
line-height: 1.6;
}
.order-item__value {
font-size: 46rpx;
color: #000000;
font-weight: 500;
flex: 1;
text-align: center;
padding: 0 10rpx;
}
.order-item__value--done {
color: #07c160;
font-weight: 600;
}
.order-item__image-wrap {
flex-shrink: 0;
margin-left: 16rpx;
padding: 4rpx 16rpx 0 0;
position: relative;
}
.order-item__image-count {
position: absolute;
right: 20rpx;
bottom: 4rpx;
background: rgba(0, 0, 0, 0.55);
color: #ffffff;
font-size: 22rpx;
line-height: 1.4;
padding: 2rpx 10rpx;
border-radius: 999rpx;
}
.order-item__image {
width: 120rpx;
height: 120rpx;
border-radius: 10rpx;
background: #f2f3f5;
}
.order-item__image--placeholder {
display: flex;
align-items: center;
justify-content: center;
}
.order-item__bottom {
padding: 4rpx 16rpx 16rpx;
line-height: 1.5;
}
.order-item__name {
font-size: 40rpx;
color: #000000;
font-weight: 500;
line-height: 1.5;
word-break: break-all;
}
.order-item__space {
font-size: 40rpx;
color: #000000;
line-height: 1.5;
}
.order-item__barcode {
font-size: 40rpx;
color: #000000;
line-height: 1.5;
word-break: break-all;
}
.order-empty {
padding: 24rpx 0;
font-size: 30rpx;
color: #909399;
text-align: center;
}
/* 团购商品核实区 */
.group-verify {
margin-top: 12rpx;
background: #fffbea;
border-radius: 16rpx;
padding: 12rpx 16rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 8rpx;
}
.group-verify__head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.order-query__scan-line ::v-deep .u-button {
width: 120rpx !important;
height: 48rpx !important;
padding: 0 !important;
margin: 0 !important;
border-radius: 10rpx;
flex-shrink: 0;
}
.order-query__scan-line ::v-deep .u-button__text {
font-size: 24rpx !important;
}
.order-verify-progress {
flex-shrink: 0;
font-size: 30rpx;
font-weight: 600;
color: #303133;
}
.group-verify__progress {
font-size: 30rpx;
font-weight: 600;
color: #2979ff;
}
/* 团购已核实:绿色高亮(参考订单复核 matched) */
.order-item--verified {
background: #07c160;
}
.order-item--verified .order-item__label,
.order-item--verified .order-item__value,
.order-item--verified .order-item__name,
.order-item--verified .order-item__space,
.order-item--verified .order-item__barcode {
color: #ffffff;
}
.action-area {
margin-top: 48rpx;
display: flex;
flex-direction: column;
gap: 20rpx;
}
.operator-ident-card {
margin-top: 24rpx;
background: #f0f7ff;
border-radius: 16rpx;
padding: 20rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: stretch;
gap: 20rpx;
}
/* ===== 操作员弹窗 ===== */
.user-drawer {
width: 560rpx;
box-sizing: border-box;
background: #ffffff;
border-radius: 16rpx;
display: flex;
flex-direction: column;
max-height: 75vh;
overflow: hidden;
}
.user-drawer__header {
padding: 48rpx 28rpx 16rpx;
flex-shrink: 0;
text-align: center;
}
.user-drawer__title {
display: block;
font-size: 42rpx;
font-weight: 600;
color: #303133;
text-align: center;
}
.user-drawer__body {
flex: 1;
min-height: 0;
padding: 20rpx 28rpx 40rpx;
box-sizing: border-box;
overflow-y: auto;
}
.scan-section {
background: #f5f6f7;
border-radius: 16rpx;
padding: 20rpx;
box-sizing: border-box;
}
.scan-row {
display: flex;
align-items: center;
gap: 8rpx;
background: #ffffff;
border: 2rpx solid #e4e7ed;
border-radius: 12rpx;
padding: 0 8rpx 0 20rpx;
box-sizing: border-box;
}
.scan-input {
flex: 1;
height: 88rpx;
font-size: 36rpx;
color: #303133;
}
.camera-btn {
width: 76rpx;
height: 76rpx;
display: flex;
align-items: center;
justify-content: center;
}
.scan-tip {
display: flex;
align-items: center;
gap: 8rpx;
margin-top: 16rpx;
}
.scan-tip__text {
font-size: 24rpx;
color: #909399;
}
.query-state {
margin-top: 32rpx;
padding: 48rpx 24rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
gap: 16rpx;
}
.query-state--loading {
min-height: 200rpx;
justify-content: center;
}
.query-state--error {
background: #fef0f0;
border-radius: 16rpx;
}
.query-state__error-text {
font-size: 36rpx;
color: #f56c6c;
text-align: center;
line-height: 1.5;
}
.result-card {
margin-top: 32rpx;
background: #f0f7ff;
border-radius: 16rpx;
padding: 12rpx 24rpx;
box-sizing: border-box;
}
.result-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 22rpx 0;
gap: 20rpx;
}
.result-label {
font-size: 28rpx;
color: #909399;
flex-shrink: 0;
}
.result-value {
font-size: 28rpx;
font-weight: 600;
color: #303133;
word-break: break-all;
text-align: right;
}
.result-divider {
height: 1rpx;
background: #e4e7ed;
}
/* 无条码复核弹窗 */
.no-barcode-popup {
width: 640rpx;
padding: 40rpx 32rpx 32rpx;
background: #ffffff;
border-radius: 20rpx;
box-sizing: border-box;
}
.no-barcode-popup__title {
font-size: 42rpx;
font-weight: 600;
color: #303133;
text-align: center;
margin-bottom: 32rpx;
}
.no-barcode-popup__body {
margin-bottom: 36rpx;
padding: 24rpx;
background: #f8f9fa;
border-radius: 12rpx;
}
.no-barcode-popup__text {
font-size: 36rpx;
color: #303133;
line-height: 1.6;
}
.no-barcode-popup__actions {
display: flex;
align-items: center;
}
.no-barcode-popup__btn {
flex: 1;
height: 88rpx;
border-radius: 12rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 36rpx;
font-weight: 500;
}
.no-barcode-popup__btn:not(:last-child) {
margin-right: 20rpx;
}
.no-barcode-popup__btn--cancel {
background: #f5f7fa;
color: #606266;
border: 1rpx solid #dcdfe6;
}
.no-barcode-popup__btn--confirm {
background: #2979ff;
color: #ffffff;
}
/* 取消核实弹窗(参考无条码复核弹窗) */
.cancel-verify-popup {
width: 640rpx;
padding: 40rpx 32rpx 32rpx;
background: #ffffff;
border-radius: 20rpx;
box-sizing: border-box;
}
.cancel-verify-popup__title {
font-size: 42rpx;
font-weight: 600;
color: #303133;
text-align: center;
margin-bottom: 32rpx;
}
.cancel-verify-popup__body {
margin-bottom: 36rpx;
padding: 24rpx;
background: #f8f9fa;
border-radius: 12rpx;
}
.cancel-verify-popup__text {
font-size: 36rpx;
color: #303133;
line-height: 1.6;
}
.cancel-verify-popup__actions {
display: flex;
align-items: center;
}
.cancel-verify-popup__btn {
flex: 1;
height: 88rpx;
border-radius: 12rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 36rpx;
font-weight: 500;
}
.cancel-verify-popup__btn:not(:last-child) {
margin-right: 20rpx;
}
.cancel-verify-popup__btn--cancel {
background: #f5f7fa;
color: #606266;
border: 1rpx solid #dcdfe6;
}
.cancel-verify-popup__btn--confirm {
background: #f56c6c;
color: #ffffff;
}
/* 退出工作台弹窗(参考取消核实弹窗) */
.exit-popup {
width: 640rpx;
padding: 40rpx 32rpx 32rpx;
background: #ffffff;
border-radius: 20rpx;
box-sizing: border-box;
}
.exit-popup__title {
font-size: 42rpx;
font-weight: 600;
color: #303133;
text-align: center;
margin-bottom: 32rpx;
}
.exit-popup__body {
margin-bottom: 36rpx;
padding: 24rpx;
background: #f8f9fa;
border-radius: 12rpx;
}
.exit-popup__text {
font-size: 36rpx;
color: #303133;
line-height: 1.6;
}
.exit-popup__actions {
display: flex;
align-items: center;
}
.exit-popup__btn {
flex: 1;
height: 88rpx;
border-radius: 12rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 36rpx;
font-weight: 500;
}
.exit-popup__btn:not(:last-child) {
margin-right: 20rpx;
}
.exit-popup__btn--cancel {
background: #f5f7fa;
color: #606266;
border: 1rpx solid #dcdfe6;
}
.exit-popup__btn--confirm {
background: #f56c6c;
color: #ffffff;
}
.remove-operator-popup {
width: 640rpx;
padding: 40rpx 32rpx 32rpx;
background: #ffffff;
border-radius: 20rpx;
box-sizing: border-box;
}
.remove-operator-popup__title {
font-size: 42rpx;
font-weight: 600;
color: #303133;
text-align: center;
margin-bottom: 32rpx;
}
.remove-operator-popup__body {
margin-bottom: 36rpx;
padding: 24rpx;
background: #f8f9fa;
border-radius: 12rpx;
}
.remove-operator-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 {
display: flex;
align-items: center;
}
.remove-operator-popup__btn {
flex: 1;
height: 88rpx;
border-radius: 12rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 36rpx;
font-weight: 500;
}
.remove-operator-popup__btn:not(:last-child) {
margin-right: 20rpx;
}
.remove-operator-popup__btn--cancel {
background: #f5f7fa;
color: #606266;
border: 1rpx solid #dcdfe6;
}
.remove-operator-popup__btn--confirm {
background: #f56c6c;
color: #ffffff;
}
</style>