修改订单复核、退件记录页面

This commit is contained in:
zm2000 2026-08-15 18:04:55 +08:00
parent 3174c068db
commit b2d6172f16
5 changed files with 590 additions and 107 deletions

4
env.js
View File

@ -1,4 +1,4 @@
export const BASE_URL = 'http://qimen.wms.gztbyc.com' //生产环境接口地址
// export const BASE_URL = 'http://192.168.11.56:6060' //开发环境接口地址
// export const BASE_URL = 'http://qimen.wms.gztbyc.com' //生产环境接口地址
export const BASE_URL = 'http://192.168.11.56:6060' //开发环境接口地址
export const API_URL = `${BASE_URL}/system` //后台接口域名
export const IMG_URL = 'https://ye4s.file.gzxunren.com' //全局网络图片地址变量,css背景图片地址变量在uni.scss

View File

@ -58,7 +58,7 @@
<view class="record-main record-main--row">
<text
class="record-value"
:class="getReviewStatusText(item) === '已复核' ? 'record-value--reviewed' : 'record-value--unreviewed'"
:class="getReviewStatusText(item) === '已复核' ? 'record-value--reviewed' : (isIntercepted(item) ? 'record-value--intercepted-unreviewed' : 'record-value--unreviewed')"
>{{ getReviewStatusText(item) }}</text>
<text
v-if="item.waveIndex && Number(pickMode) !== 3 && Number(pickMode) !== 2"
@ -147,6 +147,8 @@
},
methods: {
isIntercepted(item) {
// 团购模式:波次 intercepted 中存在被拦截订单即视为已拦截(参考散单模式拦截处理)
if (Array.isArray(item?.interceptList) && item.interceptList.length > 0) return true;
const status = String(item?.interceptStatus || '').trim();
return INTERCEPT_STATUSES.includes(status);
},
@ -159,7 +161,11 @@
},
isPrintDisabled(item) {
if (!item) return true;
// 不打印模式:列表不支持手动打印
if (this.printMode === 'noPrint') return true;
if (this.printMode === 'reviewFirst') return true;
// 拦截订单:禁止打印面单
if (this.isIntercepted(item)) return true;
if (this.listType === 'single') return false;
return (item.orderCount || 0) === 0 && (item.unprintedCount || 0) === 0;
},
@ -406,6 +412,10 @@
color: #fa8c16;
}
.record-value--intercepted-unreviewed {
color: #909399;
}
.record-value--printed {
color: #f56c6c;
}

View File

@ -28,9 +28,6 @@
<text class="store-info-divider"></text>
</template>
<text class="store-info-text">货主:{{ detailInfo.storeName }}</text>
<view v-if="isIntercepted" class="intercept-info-btn intercept-info-btn--row" @click="showInterceptInfoPopup = true">
<text class="intercept-info-btn__text">拦截信息</text>
</view>
</view>
<view v-if="detailInfo.listType === 'group'" class="wave-info-row">
<text class="wave-info-text">订单数:{{ detailInfo.totalOrders || '--' }}</text>
@ -38,9 +35,6 @@
<text class="wave-info-text">篮号:{{ detailInfo.waveIndex || detailInfo.boxNo || '--' }}</text>
<text class="wave-info-divider"></text>
<text class="wave-info-text">货主:{{ detailInfo.storeName || '--' }}</text>
<view v-if="isIntercepted" class="intercept-info-btn intercept-info-btn--row" @click="showInterceptInfoPopup = true">
<text class="intercept-info-btn__text">拦截信息</text>
</view>
</view>
<!-- 推荐包材提示 -->
<view v-if="detailInfo.listType === 'group' && detailInfo.suggestedPkg" class="package-info-hint">
@ -211,19 +205,26 @@
</u-popup>
<!-- 拦截信息弹窗 -->
<u-popup v-if="showInterceptInfoPopup" :show="showInterceptInfoPopup" mode="center" :closeable="true" border-radius="20" @close="showInterceptInfoPopup = false">
<u-popup v-if="showInterceptInfoPopup" :show="showInterceptInfoPopup" mode="bottom" :closeable="false" :closeOnClickOverlay="false" border-radius="20" @close="showInterceptInfoPopup = false">
<view class="intercept-info-popup">
<view class="intercept-info-popup__title">拦截信息</view>
<view class="intercept-info-popup__header">
<text class="intercept-info-popup__title">拦截信息</text>
</view>
<view class="intercept-info-popup__body">
<view class="intercept-info-popup__row">
<text class="intercept-info-popup__label">运单号</text>
<text class="intercept-info-popup__value">{{ detailInfo.waybillNo || '--' }}</text>
</view>
<view class="intercept-info-popup__row">
<text class="intercept-info-popup__label">拦截状态</text>
<text class="intercept-info-popup__value intercept-info-popup__value--warn">{{ interceptStatusText() }}</text>
</view>
<view class="intercept-info-popup__tip">该订单已被拦截,请勿复核发货</view>
<template v-if="isWaveInterceptList">
<view class="intercept-info-popup__tip intercept-info-popup__tip--first">该波次以下订单已被拦截,请勿复核发货</view>
<view v-for="(o, idx) in detailInfo.interceptList" :key="idx" class="intercept-info-popup__row">
<text class="intercept-info-popup__label">运单号</text>
<text class="intercept-info-popup__value">{{ interceptWaybill(o) }}</text>
</view>
</template>
<template v-else>
<view class="intercept-info-popup__row">
<text class="intercept-info-popup__label">运单号</text>
<text class="intercept-info-popup__value">{{ detailInfo.waybillNo || '--' }}</text>
</view>
<view class="intercept-info-popup__tip">该订单已被拦截,请勿复核发货</view>
</template>
</view>
<view class="intercept-info-popup__footer">
<view class="intercept-info-popup__btn" @click="showInterceptInfoPopup = false">关闭</view>
@ -275,6 +276,7 @@ import voice from '@/core/utils/voice';
waveIndex: '',
orderIds: [],
interceptStatus: '',
interceptList: [],
printStationId: '',
printStationName: '',
boxNo: ''
@ -365,6 +367,13 @@ import voice from '@/core/utils/voice';
if (!!this.detailInfo?.waveHasIntercept) return true;
const status = String(this.detailInfo?.interceptStatus || '').trim();
return !!status && status !== 'none';
},
isWaveInterceptList() {
const listType = String(this.detailInfo?.listType || '').trim();
// 散单/团单模式:波次内存在被拦截订单时,弹窗以列表形式展示波次内所有被拦截订单
return (listType === 'single' || listType === 'group') &&
Array.isArray(this.detailInfo?.interceptList) &&
this.detailInfo.interceptList.length > 0;
}
},
watch: {
@ -387,22 +396,14 @@ import voice from '@/core/utils/voice';
}
},
methods: {
interceptStatusText(status) {
// 统一的拦截状态映射(与 interceptionLog.vue 保持一致)
const map = {
'': '未拦截',
'none': '未拦截',
'requested': '拦截中',
'pending': '拦截中',
'intercepting': '拦截中',
'intercepted': '仓库已拦截',
'intercepted_at_warehouse': '仓库已拦截',
'intercept_success': '拦截成功',
'intercept_failed': '拦截失败',
'cancelled': '已取消'
};
const key = String(status ?? this.detailInfo?.interceptStatus ?? '').trim();
return map[key] || key || '未拦截';
openInterceptInfo() {
// 由订单复核页面导航栏标题左侧的拦截信息按钮触发打开
this.showInterceptInfoPopup = true;
},
interceptWaybill(o) {
// 安全获取拦截订单的运单号(模板中不支持可选链写法)
const text = String((o && (o.firstWaybillNo || o.waybillNo)) || '').trim();
return text || '--';
},
isGoodsMatched(item) {
const id = String(item?.id || '');
@ -1174,17 +1175,29 @@ import voice from '@/core/utils/voice';
}
.intercept-info-popup {
width: 560rpx;
padding: 32rpx;
box-sizing: border-box;
background: #ffffff;
border-top-left-radius: 20rpx;
border-top-right-radius: 20rpx;
padding-bottom: env(safe-area-inset-bottom);
}
.intercept-info-popup__header {
display: flex;
align-items: center;
justify-content: center;
padding: 24rpx 32rpx;
border-bottom: 1rpx solid #f2f3f5;
}
.intercept-info-popup__title {
font-size: 34rpx;
font-size: 38rpx;
font-weight: 600;
color: #303133;
text-align: center;
margin-bottom: 28rpx;
}
.intercept-info-popup__body {
padding: 24rpx 32rpx;
}
.intercept-info-popup__row {
@ -1196,21 +1209,16 @@ import voice from '@/core/utils/voice';
.intercept-info-popup__label {
width: 160rpx;
font-size: 30rpx;
color: #909399;
color: #000000;
}
.intercept-info-popup__value {
flex: 1;
font-size: 30rpx;
font-size: 36rpx;
color: #303133;
word-break: break-all;
}
.intercept-info-popup__value--warn {
color: #fa3534;
font-weight: 500;
}
.intercept-info-popup__tip {
margin-top: 20rpx;
padding: 16rpx;
@ -1221,17 +1229,22 @@ import voice from '@/core/utils/voice';
text-align: center;
}
.intercept-info-popup__tip--first {
margin-top: 0;
margin-bottom: 12rpx;
}
.intercept-info-popup__footer {
display: flex;
justify-content: center;
margin-top: 28rpx;
padding: 16rpx 32rpx 32rpx;
}
.intercept-info-popup__btn {
padding: 12rpx 48rpx;
height: 88rpx;
line-height: 88rpx;
text-align: center;
background: #2979ff;
border-radius: 8rpx;
font-size: 30rpx;
border-radius: 12rpx;
font-size: 32rpx;
color: #ffffff;
}

View File

@ -2,6 +2,11 @@
<view class="scatter-picking-detail-page">
<view class="normar_container">
<page-nav :title="showDetailView ? '订单复核详情' : title">
<template #left>
<view v-if="showDetailView && isIntercepted" class="nav-intercept-btn" @click="handleShowInterceptInfo">
<text class="nav-intercept-btn__text">拦截信息</text>
</view>
</template>
<template #right>
<view class="nav-settings-btn" @click="showSettingsPopup = true">
<text class="nav-settings-btn__text">设置</text>
@ -126,6 +131,25 @@
</view>
</u-popup>
<!-- 拦截订单弹窗(散单模式扫码命中被拦截订单时,仅显示当前一个订单) -->
<u-popup :show="showOrderInterceptPopup" mode="bottom" :closeable="false" :closeOnClickOverlay="false" border-radius="20" :z-index="10080" @close="showOrderInterceptPopup = false">
<view class="order-intercept-popup">
<view class="order-intercept-popup__header">
<text class="order-intercept-popup__title">拦截信息</text>
</view>
<view class="order-intercept-popup__body">
<view class="order-intercept-popup__row">
<text class="order-intercept-popup__label">运单号</text>
<text class="order-intercept-popup__value">{{ orderInterceptWaybill }}</text>
</view>
<view class="order-intercept-popup__tip">该订单已被拦截,请勿复核发货</view>
</view>
<view class="order-intercept-popup__footer">
<view class="order-intercept-popup__btn" @click="handleCloseOrderInterceptPopup">关闭</view>
</view>
</view>
</u-popup>
<!-- 称重弹窗 -->
<u-popup :show="showWeighPopup" mode="bottom" :closeable="true" :closeOnClickOverlay="false" border-radius="20" :z-index="10080" @close="handleWeighCancel">
<view class="weigh-popup" :style="{ paddingBottom: keyboardHeight ? keyboardHeight + 'px' : '' }">
@ -430,6 +454,10 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
showPrintModeDropdown: false,
showSettingsPopup: false,
showWeighPopup: false,
showOrderInterceptPopup: false,
orderInterceptInfo: {},
_interceptContinueNext: false,
_interceptNotifiedIds: [],
keyboardHeight: 0,
weighWeight: 0,
weighAfterReview: false,
@ -534,6 +562,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
const reviewedIds = this.reviewedOrderIds;
if (this.listType === 'single') {
return list.filter(item => {
// 拦截订单无法复核,不计入未复核统计
if (this.isOrderIntercepted(item)) return false;
const itemId = Number(item.id || item.orderId || 0);
if (itemId > 0 && reviewedIds.includes(itemId)) return false;
return !item.isReviewed;
@ -558,6 +588,18 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
console.log('[refWeightG] itemsWeight:', this.detailInfo?.itemsWeight, 'kg:', kg, 'g:', g);
return g;
},
isIntercepted() {
// 散单模式:波次内任一订单被拦截即显示拦截信息按钮(waveHasIntercept)
// 其它模式:直接看当前订单/波次的拦截状态
if (!!this.detailInfo?.waveHasIntercept) return true;
const status = String(this.detailInfo?.interceptStatus || '').trim();
return !!status && status !== 'none';
},
// 拦截订单弹窗当前订单的运单号(仅显示当前一个订单)
orderInterceptWaybill() {
const info = this.orderInterceptInfo || {};
return String(info.waybillNo || info.waybillCode || info.firstWaybillNo || '--');
},
effectivePrintMode() {
// 散单模式只走先复核后打印或不打印
if (this.listType === 'single' && this.printMode !== 'noPrint') {
@ -1724,6 +1766,16 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
const waveTotalOrders = Number(wave?.order_count ?? wave?.orderCount ?? subList.length);
const waveUnreviewed = Number(wave?.unreviewed_count ?? wave?.unreviewedCount ?? 0);
const waveStocks = Array.isArray(wave?.stocks) ? wave.stocks : [];
// 团购模式:解析波次内被拦截订单(intercepted),参考散单模式拦截处理
const waveInterceptList = (Array.isArray(wave?.intercepted) ? wave.intercepted : [])
.filter(inter => inter && typeof inter === 'object')
.map(inter => ({
orderId: Number(inter?.order_id ?? inter?.orderId ?? 0),
deliveryOrderCode: String(inter?.delivery_order_code || inter?.deliveryOrderCode || '').trim(),
waybillNo: String(inter?.waybill_no || inter?.waybillNo || '').trim(),
interceptStatus: String(inter?.intercept_status || inter?.interceptStatus || '').trim(),
waveIndex: String(inter?.wave_index ?? inter?.waveIndex ?? '').trim()
}));
return {
waveNo: String(wave?.wave_no || wave?.waveNo || '').trim(),
waveIndex: String(wave?.wave_index || wave?.waveIndex || '').trim(),
@ -1742,6 +1794,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
firstWaybillNo: String(wave?.first_waybill_no || wave?.firstWaybillNo || '').trim(),
storeName: String(wave?.store_remark || '').trim(),
suggestedPkg: wave?.suggested_package_material || wave?.suggestedPkg || null,
interceptList: waveInterceptList,
hasIntercept: waveInterceptList.length > 0,
list: subList
};
});
@ -1895,6 +1949,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
}));
this.paginationTotal = result?.total ?? flatList.length;
this.goodsInfoList = [];
// 刷新订单列表后重置已提示的拦截订单记录
this._interceptNotifiedIds = [];
this.totalOrders = result?.totalOrders ?? 0;
if (!silent) {
uni.showToast({
@ -1959,6 +2015,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
firstWaybillNo: String(wave?.firstWaybillNo || '').trim(),
storeName: String(wave?.storeName || '').trim(),
suggestedPkg: wave?.suggestedPkg || null,
interceptList: Array.isArray(wave?.interceptList) ? wave.interceptList : [],
hasIntercept: Array.isArray(wave?.interceptList) && wave.interceptList.length > 0,
status: wave?.status || 'pending',
children: subList
};
@ -2362,9 +2420,32 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
uni.hideLoading();
}
},
goPickGoodsDetail(item) {
goPickGoodsDetail(item, continueAfterIntercept = false) {
if (!item) return;
// 散单模式:被拦截订单不允许进入详情/复核扫描/打印/发货流程
// 语音提示"此单已拦截",并弹出当前订单的拦截信息(仅显示当前一个订单)
if (this.listType === 'single' && this.isOrderIntercepted(item)) {
// 记录当前拦截订单在列表中的位置,关闭弹窗后从其后继续查找下一个未复核订单
const interceptedIndex = this.orderList.findIndex(o =>
String(o.id || o.orderId || '') === String(item.id || item.orderId || '')
);
if (interceptedIndex >= 0) {
this.currentOrderIndex = interceptedIndex;
}
this._interceptContinueNext = !!continueAfterIntercept;
// 自动跳转流程:记录本次已提示过的拦截订单,避免后续查找时重复弹窗造成死循环
if (continueAfterIntercept) {
const interceptedId = String(item.id || item.orderId || '');
if (interceptedId && !this._interceptNotifiedIds.includes(interceptedId)) {
this._interceptNotifiedIds = [...this._interceptNotifiedIds, interceptedId];
}
}
this.speakVoice('此单已拦截');
this.openOrderInterceptPopup(item);
return;
}
// 切换订单时重置包材/称重取消标志,新订单继续正常弹窗
this.packageBindingCancelled = false;
this.weighCancelled = false;
@ -2455,6 +2536,7 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
orderIds: Array.isArray(item?.orderIds) ? item.orderIds : [],
interceptStatus: String(item?.interceptStatus || '').trim(),
waveHasIntercept: this.resolveWaveHasIntercept(item),
interceptList: this.resolveWaveInterceptList(item),
printStationId: String(this.printStationId || ''),
printStationName: String(this.printStationName || ''),
boxNo: String(item.boxNo || ''),
@ -2518,6 +2600,31 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
this.requestScanOrder(this.keyword, true);
}
},
// 详情页导航栏标题左侧的拦截信息按钮:通过 ReviewDetail 组件打开拦截信息弹窗
handleShowInterceptInfo() {
if (this.$refs.reviewDetail) {
this.$refs.reviewDetail.openInterceptInfo();
}
},
// 判断单个订单是否被拦截(散单模式拦截订单拦截入口使用)
isOrderIntercepted(item) {
const status = String(item?.interceptStatus || item?.intercept_status || '').trim();
return !!status && status !== 'none';
},
// 散单模式扫码命中被拦截订单时:弹出仅显示当前订单的拦截信息弹窗
openOrderInterceptPopup(item) {
this.orderInterceptInfo = item || {};
this.showOrderInterceptPopup = true;
},
// 关闭拦截订单弹窗:若为自动跳转流程(复核完自动找下一个)触发,则继续查找下一个未复核订单
handleCloseOrderInterceptPopup() {
this.showOrderInterceptPopup = false;
const shouldContinue = this._interceptContinueNext;
this._interceptContinueNext = false;
if (shouldContinue) {
this.goToNextOrder();
}
},
handleDrawerOrderClick(item) {
this.showListDrawer = false;
this.goPickGoodsDetail(item);
@ -2527,6 +2634,9 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
// 其它模式:直接看当前订单/波次的拦截状态
resolveWaveHasIntercept(item) {
if (this.listType !== 'single') {
// 团单模式:波次 intercepted 中存在被拦截订单即视为波次含拦截(参考散单模式拦截处理)
const interceptList = Array.isArray(item?.interceptList) ? item.interceptList : [];
if (interceptList.length > 0) return true;
const status = String(item?.interceptStatus || '').trim();
return !!status && status !== 'none';
}
@ -2542,6 +2652,29 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
return !!s && s !== 'none';
});
},
// 获取当前订单所属波次的被拦截订单列表
// 散单模式(single):返回波次内所有被拦截订单;其它模式:返回当前订单自身(若被拦截)
resolveWaveInterceptList(item) {
if (this.listType !== 'single') {
// 团单模式:直接返回波次内被拦截订单列表(intercepted),参考散单模式波次内拦截订单展示
const interceptList = Array.isArray(item?.interceptList) ? item.interceptList : [];
if (interceptList.length > 0) return interceptList;
const status = String(item?.interceptStatus || '').trim();
if (!status || status === 'none') return [];
return [item];
}
const waveNo = String(item?.waveNo || '').trim();
const hasOrderList = Array.isArray(this.orderList) && this.orderList.length > 0;
if (!waveNo || !hasOrderList) {
const status = String(item?.interceptStatus || '').trim();
return (!status || status === 'none') ? [] : [item];
}
return this.orderList.filter(o => {
if (String(o?.waveNo || '').trim() !== waveNo) return false;
const s = String(o?.interceptStatus || '').trim();
return !!s && s !== 'none';
});
},
buildRecheckParams() {
const listType = String(this.detailInfo?.listType || '').trim();
if (listType === 'group') {
@ -3121,6 +3254,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
const item = this.orderList[i];
const itemId = Number(item.id || item.orderId || 0);
if (itemId > 0 && this.reviewedOrderIds.includes(itemId)) continue;
// 散单模式:跳过已提示过的拦截订单,避免重复弹窗死循环
if (this.listType === 'single' && this._interceptNotifiedIds.includes(String(itemId))) continue;
if (this.listType === 'single') {
if (!item.isReviewed) { nextOrder = item; break; }
} else {
@ -3133,6 +3268,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
const item = this.orderList[i];
const itemId = Number(item.id || item.orderId || 0);
if (itemId > 0 && this.reviewedOrderIds.includes(itemId)) continue;
// 散单模式:跳过已提示过的拦截订单,避免重复弹窗死循环
if (this.listType === 'single' && this._interceptNotifiedIds.includes(String(itemId))) continue;
if (this.listType === 'single') {
if (!item.isReviewed) { nextOrder = item; break; }
} else {
@ -3141,7 +3278,8 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
}
}
if (nextOrder) {
this.goPickGoodsDetail(nextOrder);
// 自动跳转流程:若下一个订单被拦截,关闭拦截弹窗后继续查找下一个未复核订单
this.goPickGoodsDetail(nextOrder, true);
} else {
uni.showToast({ title: '所有订单已复核完成', icon: 'success' });
this.speakVoice('所有订单已复核完成');
@ -3368,6 +3506,18 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
return;
}
// 不打印模式:禁止触发打印
if (this.effectivePrintMode === 'noPrint') {
uni.showToast({ title: '当前为不打印模式,无法打印', icon: 'none' });
return;
}
// 散单模式:被拦截订单禁止打印面单
if (this.listType === 'single' && this.isOrderIntercepted(item)) {
uni.showToast({ title: '该订单已拦截,禁止打印', icon: 'none' });
this.speakVoice('此单已拦截');
return;
}
uni.showLoading({ title: '处理打印中...' });
try {
@ -3634,6 +3784,99 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
line-height: 1.4;
}
.nav-intercept-btn {
padding: 4rpx 16rpx;
display: flex;
align-items: center;
justify-content: center;
border: 1rpx solid #fa3534;
border-radius: 6rpx;
background: #fef0f0;
}
.nav-intercept-btn:active {
opacity: 0.7;
}
.nav-intercept-btn__text {
font-size: 26rpx;
color: #fa3534;
line-height: 1.6;
}
.order-intercept-popup {
background: #ffffff;
border-top-left-radius: 20rpx;
border-top-right-radius: 20rpx;
padding-bottom: env(safe-area-inset-bottom);
}
.order-intercept-popup__header {
display: flex;
align-items: center;
justify-content: center;
padding: 24rpx 32rpx;
border-bottom: 1rpx solid #f2f3f5;
}
.order-intercept-popup__title {
font-size: 38rpx;
font-weight: 600;
color: #303133;
text-align: center;
}
.order-intercept-popup__body {
padding: 24rpx 32rpx;
}
.order-intercept-popup__row {
display: flex;
align-items: center;
padding: 12rpx 0;
}
.order-intercept-popup__label {
width: 160rpx;
font-size: 30rpx;
color: #000000;
}
.order-intercept-popup__value {
flex: 1;
font-size: 36rpx;
color: #303133;
word-break: break-all;
}
.order-intercept-popup__tip {
margin-top: 20rpx;
padding: 16rpx;
background: #fef0f0;
border-radius: 8rpx;
font-size: 28rpx;
color: #fa3534;
text-align: center;
}
.order-intercept-popup__footer {
padding: 16rpx 32rpx 32rpx;
}
.order-intercept-popup__btn {
height: 88rpx;
line-height: 88rpx;
text-align: center;
background: #2979ff;
border-radius: 12rpx;
color: #ffffff;
font-size: 32rpx;
}
.order-intercept-popup__btn:active {
opacity: 0.7;
}
.nav-right-action {
font-size: 32rpx;
line-height: 36rpx;

View File

@ -12,8 +12,8 @@
</view>
</template>
<template #right>
<view class="nav-reset" @click="handleReset">
<text class="nav-reset-text">重置</text>
<view class="nav-scan-count">
<text class="nav-scan-count-text">扫描计数:{{ scanCount }}</text>
</view>
</template>
</page-nav>
@ -88,7 +88,15 @@ import voice from '@/core/utils/voice';
remarkInput: '',
result: {},
showResult: false,
submitting: false
submitting: false,
// 扫描计数:仅在登记成功时 +1,同一快递单号重复扫描仅计数一次,进入页面从 0 开始,退出页面即清零(不持久化)
scanCount: 0,
// 已计数的快递单号集合(内存去重,不持久化,退出页面即清空)
countedWaybills: [],
// ===== 弱网处理状态 =====
isNetworkConnected: true,
pendingSubmitQueue: [],
isFlushingPendingQueue: false
};
},
computed: {
@ -102,6 +110,12 @@ import voice from '@/core/utils/voice';
}
},
onLoad() {
// 扫描计数每次进入页面从 0 开始(含已计数字号集合清空)
this.scanCount = 0;
this.countedWaybills = [];
// 弱网处理:初始化网络状态并监听变化
this.initNetworkStatus();
this.bindNetworkStatusChange();
this.$store.dispatch('broadcast/setCallbacks', {
onResult: this.onScanData
});
@ -109,11 +123,15 @@ import voice from '@/core/utils/voice';
},
onShow() {
this.$store.dispatch('broadcast/resume');
// 返回页面时重新检测网络并尝试补提(兜底 onNetworkStatusChange 未触发场景)
this.initNetworkStatus();
},
onHide() {
this.$store.dispatch('broadcast/pause');
},
onUnload() {
this.stopNetworkPolling();
this.unbindNetworkStatusChange();
this.$store.dispatch('broadcast/stop');
},
methods: {
@ -143,64 +161,258 @@ import voice from '@/core/utils/voice';
speakVoice(text) {
voice.speak(text, { minInterval: 800 });
},
// ===== 弱网处理:网络状态监听 =====
initNetworkStatus() {
uni.getNetworkType({
success: res => {
const networkType = String(res && res.networkType ? res.networkType : '').toLowerCase();
// 仅明确的在线网络类型视为在线(none/unknown/空 均视为离线)
this.isNetworkConnected = ['wifi', '2g', '3g', '4g', '5g', 'ethernet'].includes(networkType);
if (this.isNetworkConnected) {
this.flushPendingSubmitQueue();
}
},
fail: () => {
// 获取失败保守视为在线,交由请求失败兜底入队
this.isNetworkConnected = true;
}
});
},
bindNetworkStatusChange() {
if (this._networkStatusChangeHandler) {
return;
}
this._networkStatusChangeHandler = res => {
const networkType = String(res && res.networkType ? res.networkType : '').toLowerCase();
// 以 networkType 白名单判断在线(兼容部分设备 isConnected 缺失/不准确)
const isConnected = ['wifi', '2g', '3g', '4g', '5g', 'ethernet'].includes(networkType);
this.isNetworkConnected = isConnected;
if (isConnected) {
this.flushPendingSubmitQueue();
}
};
uni.onNetworkStatusChange(this._networkStatusChangeHandler);
},
unbindNetworkStatusChange() {
if (!this._networkStatusChangeHandler) {
return;
}
if (typeof uni.offNetworkStatusChange === 'function') {
uni.offNetworkStatusChange(this._networkStatusChangeHandler);
}
this._networkStatusChangeHandler = null;
},
// 补提兜底轮询:离线入队后定时重查网络,网络恢复时自动补提(兼容 onNetworkStatusChange 未触发场景)
startNetworkPolling() {
if (this._networkPollTimer) {
return;
}
this._networkPollTimer = setInterval(() => {
if (!this.pendingSubmitQueue.length) {
this.stopNetworkPolling();
return;
}
this.initNetworkStatus();
}, 5000);
},
stopNetworkPolling() {
if (this._networkPollTimer) {
clearInterval(this._networkPollTimer);
this._networkPollTimer = null;
}
},
// ===== 弱网处理:补提队列 =====
enqueuePendingSubmit(waybillCode, remark = '') {
const normalizedCode = String(waybillCode || '').trim();
if (!normalizedCode) return;
if (this.pendingSubmitQueue.some(item => item.code === normalizedCode)) return;
this.pendingSubmitQueue.push({
code: normalizedCode,
remark: String(remark || '').trim()
});
},
dequeuePendingSubmit(waybillCode) {
const normalizedCode = String(waybillCode || '').trim();
this.pendingSubmitQueue = this.pendingSubmitQueue.filter(item => item.code !== normalizedCode);
},
// 等待提交锁空闲(150ms 轮询),避免补提与用户实时提交并发冲突
async waitForSubmitIdle() {
const maxWait = 10000;
const start = Date.now();
while (this.submitting) {
if (Date.now() - start > maxWait) break;
await this.sleep(150);
}
},
async flushPendingSubmitQueue() {
if (!this.isNetworkConnected || this.isFlushingPendingQueue || !this.pendingSubmitQueue.length) {
return;
}
this.isFlushingPendingQueue = true;
try {
while (this.isNetworkConnected && this.pendingSubmitQueue.length) {
// 等待当前提交结束后再补提,串行化避免并发竞态
await this.waitForSubmitIdle();
const head = this.pendingSubmitQueue[0];
if (!head) break;
const beforeCode = head.code;
try {
const response = await this.requestReturnRegister(head.code, head.remark, 8000);
this.handleReturnRegisterResponse(response, head.code, head.remark);
// 响应处理内部已出队,若仍在队首则手动出队
if (this.pendingSubmitQueue[0] && this.pendingSubmitQueue[0].code === beforeCode) {
this.pendingSubmitQueue.shift();
}
} catch (error) {
if (!this.isNetworkConnected) {
break;
}
// 非并发原因(如非弱网错误)且未出队,退出防止死循环
if (this.pendingSubmitQueue[0] && this.pendingSubmitQueue[0].code === beforeCode && !this.submitting) {
break;
}
}
}
} finally {
this.isFlushingPendingQueue = false;
// 队列已清空,停止补提轮询
if (!this.pendingSubmitQueue.length) {
this.stopNetworkPolling();
}
}
},
// ===== 弱网处理:请求超时与错误判断 =====
sleep(ms = 0) {
return new Promise(resolve => {
setTimeout(resolve, Number(ms) || 0);
});
},
createSubmitTimeoutError(timeoutMs) {
const error = new Error(`提交超时(${timeoutMs}ms)`);
error.code = 'REQUEST_TIMEOUT';
error.errMsg = `request:fail timeout ${timeoutMs}`;
return error;
},
requestReturnRegister(waybillCode, remark = '', timeoutMs = 8000) {
const requestPromise = this.$http('returnReceived.create', {
waybill_code: waybillCode,
remark: String(remark || '').trim()
}, '', false);
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => {
reject(this.createSubmitTimeoutError(timeoutMs));
}, timeoutMs);
});
return Promise.race([requestPromise, timeoutPromise]);
},
// 仅在输入框值与本次提交一致时清除,避免补提误清用户正在输入的备注
clearInputIfSame(waybillCode, remark = '') {
if (this.scanInput === waybillCode) {
this.scanInput = '';
}
if (this.remarkInput === String(remark || '').trim()) {
this.remarkInput = '';
}
},
// 登记响应处理:成功与业务失败均出队;重试/补提安全(服务端 30 日幂等不会重复登记)
handleReturnRegisterResponse(res, waybillCode, remark = '') {
if (res && res.flag === 'failure') {
this.dequeuePendingSubmit(waybillCode);
uni.showToast({ title: (res && (res.msg || res.message)) || '登记失败', icon: 'none' });
this.speakVoice('登记失败');
this.clearInputIfSame(waybillCode, remark);
return;
}
this.dequeuePendingSubmit(waybillCode);
// 后端返回的业务记录在 data 或 record 字段,且部分状态字段(duplicated/is_original_return/store_remark)在顶层。
// 将顶层与业务记录合并,保证快递号(waybill_code)等字段能正常取到
let payload = (res && typeof res === 'object') ? res : {};
const body = (res && (res.data || res.record)) || null;
if (body && typeof body === 'object' && !Array.isArray(body)) {
payload = { ...res, ...body };
}
this.result = payload || {};
this.showResult = true;
// 登记成功,扫描计数 +1;同一快递单号重复扫描仅计数一次(失败/无效单号不计入)
if (!this.countedWaybills.includes(waybillCode)) {
this.countedWaybills.push(waybillCode);
this.scanCount += 1;
}
this.clearInputIfSame(waybillCode, remark);
if (this.result.duplicated) {
uni.showToast({ title: '30日内已登记', icon: 'none' });
this.speakVoice('已登记');
} else if (this.result.is_original_return) {
uni.showToast({ title: '原单退回登记成功', icon: 'success' });
this.speakVoice('登记成功');
} else {
uni.showToast({ title: '退件登记成功', icon: 'success' });
this.speakVoice('登记成功');
}
},
/**
* 退回包裹扫码登记
* 调用 returnReceived.create 登记退回收件运单号:
* - 30日内同仓库同单号幂等(以第一次为准,duplicated=true)
* - 反查 wms_order_express 判定是否原单退回,命中则回填 order_express_id/order_id/store_id 并标记 is_back='Y'
* - warehouse_id 由服务端注入 ctx.user.store_id,前端禁止传入
* - 弱网:离线/请求层失败一律入队补提,网络恢复自动提交(8s 超时兜底;登录过期等登录态错误不入队)
*/
async submitReturnRegister(code) {
const waybillCode = String(code || '').trim();
if (!waybillCode || this.submitting) return;
if (!waybillCode) return;
const remark = this.remarkInput.trim();
// 正在提交时不再静默丢弃,入队串行处理
if (this.submitting) {
this.enqueuePendingSubmit(waybillCode, remark);
uni.showToast({ title: '正在登记,已加入队列', icon: 'none' });
return;
}
// 离线:直接入队补提
if (!this.isNetworkConnected) {
this.enqueuePendingSubmit(waybillCode, remark);
uni.showToast({ title: '当前离线,已加入补提队列', icon: 'none' });
this.speakVoice('已加入队列');
this.clearInputIfSame(waybillCode, remark);
this.startNetworkPolling();
return;
}
this.submitting = true;
uni.showLoading({ title: '登记中...', mask: true });
try {
const res = await this.$http('returnReceived.create', {
waybill_code: waybillCode,
remark: this.remarkInput.trim()
}, '', false);
if (res && res.flag !== 'failure') {
const payload = (res && res.data && typeof res.data === 'object' && !Array.isArray(res.data))
? res.data
: res;
this.result = payload || {};
this.showResult = true;
this.scanInput = '';
this.remarkInput = '';
if (this.result.duplicated) {
uni.showToast({ title: '30日内已登记', icon: 'none' });
this.speakVoice('已登记');
} else if (this.result.is_original_return) {
uni.showToast({ title: '原单退回登记成功', icon: 'success' });
this.speakVoice('登记成功');
try {
const res = await this.requestReturnRegister(waybillCode, remark, 8000);
this.handleReturnRegisterResponse(res, waybillCode, remark);
} catch (error) {
const authText = String((error && (error.msg || error.message || error.errMsg)) || '').toLowerCase();
// 登录态错误不入队,直接提示
if (authText.includes('登录已过期') || authText.includes('未登录') || authText.includes('401')) {
const msg = String((error && (error.msg || error.message)) || '登录已过期,请重新登录');
uni.showToast({ title: msg, icon: 'none' });
this.speakVoice('登记失败');
this.clearInputIfSame(waybillCode, remark);
} else {
uni.showToast({ title: '退件登记成功', icon: 'success' });
this.speakVoice('登记成功');
// 断网 / 弱网 / 其它请求层错误:一律入队补提,等待网络恢复自动提交。
// 不依赖 isNetworkConnected 与弱网关键词匹配——兼容浏览器 H5 离线时
// getNetworkType 误报在线(返回 4g/wifi)、错误文案不匹配弱网关键词等场景
this.enqueuePendingSubmit(waybillCode, remark);
uni.showToast({
title: this.isNetworkConnected ? '网络较差,已加入补提队列' : '当前离线,已加入补提队列',
icon: 'none'
});
this.speakVoice('已加入队列');
this.clearInputIfSame(waybillCode, remark);
this.startNetworkPolling();
}
} else {
uni.showToast({ title: (res && (res.msg || res.message)) || '登记失败', icon: 'none' });
this.speakVoice('登记失败');
}
} catch (e) {
const msg = String((e && (e.msg || e.message)) || '网络异常');
uni.showToast({ title: msg, icon: 'none' });
this.speakVoice('登记失败');
} finally {
this.submitting = false;
uni.hideLoading();
// 兜底触发补提(flush 自身调用时 isFlushingPendingQueue=true 直接返回,无递归)
this.flushPendingSubmitQueue();
}
},
handleReset() {
this.resetForm();
},
resetForm() {
this.scanInput = '';
this.remarkInput = '';
this.result = {};
this.showResult = false;
this.submitting = false;
this.scanFocused = true;
}
}
};
@ -248,17 +460,22 @@ import voice from '@/core/utils/voice';
}
}
/* ===== 重置按钮 ===== */
.nav-reset {
padding: 8rpx 0;
/* ===== 扫描计数 ===== */
.nav-scan-count {
display: flex;
align-items: center;
justify-content: center;
height: 64rpx;
background-color: #52c41a;
border-radius: 8rpx;
padding: 0 16rpx;
margin-left: 16rpx;
.nav-reset-text {
font-size: 32rpx;
color: #fff;
background-color: #2979ff;
padding: 8rpx 24rpx;
border-radius: 8rpx;
.nav-scan-count-text {
font-size: 34rpx;
color: #ffffff;
white-space: nowrap;
line-height: 1;
}
}