修改拣货、复核发货模块

This commit is contained in:
zm2000 2026-06-07 17:58:42 +08:00
parent 1999865c88
commit 31eb640fc3
2 changed files with 326 additions and 49 deletions

View File

@ -168,6 +168,8 @@
itemBarcodeCache: {},
pickedItemKeys: [],
pickedStateStorageKey: 'order_picking_picked_state_v1',
confirmedOrderIds: [],
confirmedOrderStateStorageKey: 'order_picking_confirmed_order_ids_v1',
boundCartNo: '',
boundCartName: '',
bindCartNoInput: '',
@ -178,6 +180,7 @@
bindCartQueryKeyword: '',
boundCartStorageKey: 'order_picking_bound_cart_v1',
submittingWavePickTask: false,
currentWavePickSubmitPromise: null,
wavePickSubmitQueue: [],
isNetworkConnected: true,
isFlushingWavePickSubmitQueue: false,
@ -362,7 +365,8 @@
continue;
}
try {
await this.requestWavePickTaskSubmit(taskIdNumber, 8000);
const response = await this.requestWavePickTaskSubmit(taskIdNumber, 8000);
this.handleWavePickTaskSubmitResponse(response);
this.wavePickSubmitQueue.shift();
} catch (error) {
if (!this.isNetworkConnected || this.isWeakNetworkError(error)) {
@ -462,6 +466,108 @@
const map = this.loadPickedStateMap();
const restored = Array.isArray(map[String(taskIdNumber)]) ? map[String(taskIdNumber)] : [];
this.pickedItemKeys = restored.filter(Boolean);
},
loadConfirmedOrderStateMap() {
try {
const raw = uni.getStorageSync(this.confirmedOrderStateStorageKey);
if (!raw) {
return {};
}
if (typeof raw === 'string') {
const parsed = JSON.parse(raw);
return parsed && typeof parsed === 'object' ? parsed : {};
}
return raw && typeof raw === 'object' ? raw : {};
} catch (error) {
return {};
}
},
saveConfirmedOrderStateMap(map) {
try {
uni.setStorageSync(this.confirmedOrderStateStorageKey, map || {});
} catch (error) {
// ignore storage write error
}
},
normalizeConfirmedOrderIds(orderIds) {
if (!Array.isArray(orderIds)) {
return [];
}
return Array.from(new Set(orderIds
.map(id => Number(id))
.filter(id => Number.isFinite(id) && id > 0)));
},
persistConfirmedOrderIdsForCurrentTask(orderIds) {
const taskIdNumber = this.getCurrentTaskIdNumber();
const normalizedOrderIds = this.normalizeConfirmedOrderIds(orderIds);
if (!taskIdNumber) {
this.confirmedOrderIds = normalizedOrderIds;
return;
}
const map = this.loadConfirmedOrderStateMap();
map[String(taskIdNumber)] = normalizedOrderIds;
this.saveConfirmedOrderStateMap(map);
this.confirmedOrderIds = normalizedOrderIds;
},
restoreConfirmedOrderIdsForCurrentTask() {
const taskIdNumber = this.getCurrentTaskIdNumber();
if (!taskIdNumber) {
this.confirmedOrderIds = [];
return;
}
const map = this.loadConfirmedOrderStateMap();
this.confirmedOrderIds = this.normalizeConfirmedOrderIds(map[String(taskIdNumber)]);
},
clearConfirmedOrderIdsForTask(taskIdNumber) {
const normalizedTaskId = Number(taskIdNumber || 0);
if (!normalizedTaskId) {
this.confirmedOrderIds = [];
return;
}
const map = this.loadConfirmedOrderStateMap();
delete map[String(normalizedTaskId)];
this.saveConfirmedOrderStateMap(map);
if (normalizedTaskId === this.getCurrentTaskIdNumber()) {
this.confirmedOrderIds = [];
}
},
extractConfirmedOrderIdsFromSubmitResponse(response) {
const payload = response || {};
const candidateLists = [
payload?.confirmed_order_ids,
payload?.confirmedOrderIds,
payload?.data?.confirmed_order_ids,
payload?.data?.confirmedOrderIds,
payload?.data?.data?.confirmed_order_ids,
payload?.data?.data?.confirmedOrderIds,
payload?.result?.confirmed_order_ids,
payload?.result?.confirmedOrderIds,
payload?.result?.data?.confirmed_order_ids,
payload?.result?.data?.confirmedOrderIds
];
for (let i = 0; i < candidateLists.length; i += 1) {
const normalizedOrderIds = this.normalizeConfirmedOrderIds(candidateLists[i]);
if (normalizedOrderIds.length) {
return normalizedOrderIds;
}
}
return [];
},
handleWavePickTaskSubmitResponse(response) {
console.log('[pick.wavePickTaskSubmit] response:', response);
const confirmedOrderIds = this.extractConfirmedOrderIdsFromSubmitResponse(response);
console.log('[pick.wavePickTaskSubmit] confirmed_order_ids:', confirmedOrderIds);
if (!confirmedOrderIds.length) {
console.log('[pick.wavePickTaskSubmit] no confirmed_order_ids extracted');
return response;
}
const mergedOrderIds = [
...this.confirmedOrderIds,
...confirmedOrderIds
];
this.persistConfirmedOrderIdsForCurrentTask(mergedOrderIds);
console.log('[pick.wavePickTaskSubmit] merged confirmedOrderIds:', this.normalizeConfirmedOrderIds(mergedOrderIds));
return response;
},
getBoundCartTaskKey() {
return String(this.getCurrentTaskIdNumber() || '').trim();
@ -776,6 +882,9 @@
return error;
},
requestWavePickTaskSubmit(taskIdNumber, timeoutMs = 8000) {
console.log('[pick.wavePickTaskSubmit] request:', {
task_id: taskIdNumber
});
const requestPromise = this.$http('pick.wavePickTaskSubmit', {
task_id: taskIdNumber
});
@ -789,48 +898,53 @@
async submitWavePickTaskIntermediate() {
const taskIdNumber = this.getCurrentTaskIdNumber();
if (!taskIdNumber || this.submittingWavePickTask) {
return;
return this.currentWavePickSubmitPromise;
}
if (!this.isNetworkConnected) {
this.enqueueWavePickSubmitTask(taskIdNumber);
uni.showToast({
title: '当前离线,已加入补提队列',
icon: 'none'
});
return;
}
const maxAttempts = 3;
let lastError = null;
this.submittingWavePickTask = true;
try {
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
try {
await this.requestWavePickTaskSubmit(taskIdNumber, 8000);
this.dequeueWavePickSubmitTask(taskIdNumber);
return;
} catch (error) {
lastError = error;
const isWeakNetwork = this.isWeakNetworkError(error);
if (!this.isNetworkConnected) {
this.enqueueWavePickSubmitTask(taskIdNumber);
break;
}
if (!isWeakNetwork || attempt >= maxAttempts) {
break;
}
await this.sleep(attempt * 600);
}
}
this.currentWavePickSubmitPromise = (async () => {
if (!this.isNetworkConnected) {
this.enqueueWavePickSubmitTask(taskIdNumber);
uni.showToast({
title: '当前离线,已加入补提队列',
icon: 'none'
});
return;
}
const fallbackMessage = this.isWeakNetworkError(lastError)
? '网络较差,提交拣货中间态失败,请重试'
: '提交拣货中间态失败';
this.showErrorModal(this.getApiErrorMessage(lastError, fallbackMessage));
} finally {
this.submittingWavePickTask = false;
}
const maxAttempts = 3;
let lastError = null;
this.submittingWavePickTask = true;
try {
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
try {
const response = await this.requestWavePickTaskSubmit(taskIdNumber, 8000);
this.handleWavePickTaskSubmitResponse(response);
this.dequeueWavePickSubmitTask(taskIdNumber);
return;
} catch (error) {
lastError = error;
const isWeakNetwork = this.isWeakNetworkError(error);
if (!this.isNetworkConnected) {
this.enqueueWavePickSubmitTask(taskIdNumber);
break;
}
if (!isWeakNetwork || attempt >= maxAttempts) {
break;
}
await this.sleep(attempt * 600);
}
}
if (!this.isNetworkConnected) {
return;
}
const fallbackMessage = this.isWeakNetworkError(lastError)
? '网络较差,提交拣货中间态失败,请重试'
: '提交拣货中间态失败';
this.showErrorModal(this.getApiErrorMessage(lastError, fallbackMessage));
} finally {
this.submittingWavePickTask = false;
this.currentWavePickSubmitPromise = null;
}
})();
return this.currentWavePickSubmitPromise;
},
handleScanKeywordEntry(rawKeyword) {
const scanText = this.normalizeScanResult(rawKeyword);
@ -1026,7 +1140,14 @@
if (payload.mode === 2 && Array.isArray(options?.order_ids) && options.order_ids.length) {
payload.order_ids = options.order_ids;
}
return this.$http('pick.wavePickTaskComplete', payload, '', false);
console.log('[pick.wavePickTaskComplete] request:', payload);
return this.$http('pick.wavePickTaskComplete', payload, '', false).then(response => {
console.log('[pick.wavePickTaskComplete] response:', response);
return response;
}).catch(error => {
console.log('[pick.wavePickTaskComplete] error:', error);
throw error;
});
},
handleCompletePick() {
this.showActionSheet = false;
@ -1047,7 +1168,7 @@
}
uni.showModal({
title: '完成拣货',
content: '确认全部完成当前拣货任务吗?',
content: '确认完成当前拣货任务吗?',
success: async res => {
if (!res?.confirm) {
return;
@ -1056,8 +1177,19 @@
title: '正在提交...'
});
try {
if (this.currentWavePickSubmitPromise) {
await this.currentWavePickSubmitPromise;
}
const confirmedOrderIds = this.normalizeConfirmedOrderIds(this.confirmedOrderIds);
const completeMode = confirmedOrderIds.length ? 2 : 1;
console.log('[pick.wavePickTaskComplete] derived state:', {
task_id: taskIdNumber,
confirmedOrderIds,
completeMode
});
const response = await this.requestWavePickTaskComplete(taskIdNumber, {
mode: 1
mode: completeMode,
order_ids: confirmedOrderIds
});
if (String(response?.flag || '').toLowerCase() === 'failure') {
this.showErrorModal(response?.message || '完成拣货失败');
@ -1102,6 +1234,7 @@
this.selectedBindCartItem = null;
this.bindCartQueryKeyword = '';
this.pickedItemKeys = [];
this.clearConfirmedOrderIdsForTask(taskIdNumber);
} catch (error) {
this.showErrorModal(this.getApiErrorMessage(error, '完成拣货失败'));
} finally {
@ -1254,6 +1387,7 @@
}))
};
this.restorePickedStateForCurrentTask();
this.restoreConfirmedOrderIdsForCurrentTask();
this.restoreBoundCartForCurrentTask();
this.selectedIndex = 0;
},

View File

@ -150,6 +150,38 @@
</view>
</view>
</u-popup>
<u-popup :show="showStationListPopup" mode="bottom" :closeable="true" border-radius="20" :z-index="10090" @close="showStationListPopup = false">
<view class="print-popup">
<view class="print-popup-title">打印台列表</view>
<scroll-view class="station-list-scroll" scroll-y>
<view v-if="printStationList.length === 0" class="station-list-empty">暂无打印台数据</view>
<view
v-for="station in printStationList"
:key="station.id"
class="station-list-item"
@click="handleStationListItemClick(station)"
>
<text class="station-list-item__name">{{ station.name }}</text>
</view>
<view class="safe-bottom-in-popup"></view>
</scroll-view>
<view v-if="stationListTotal > 0" class="station-list-pagination">
<pagination
:pageNum.sync="stationListPage"
:pageSize="stationListPageSize"
:total="stationListTotal"
:showTotal="true"
:prevText="'上一页'"
:nextText="'下一页'"
:showFirstLast="true"
:firstText="'首页'"
:lastText="'末页'"
@change="handleStationListPageChange"
/>
</view>
</view>
</u-popup>
</view>
</template>
@ -165,11 +197,15 @@
pageSize: 20,
currentPage: 1,
paginationTotal: 0,
showStationListPopup: false,
showPrintPopup: false,
showPrintStationDropdown: false,
printStationName: '--',
printStationId: '',
printStationList: [],
stationListPage: 1,
stationListPageSize: 20,
stationListTotal: 0,
printMessage: '',
pendingPrintCount: 0,
printRequestCode: '',
@ -469,9 +505,9 @@
buildPrintRecordWhere() {
return {};
},
buildPrintRecordParams() {
buildPrintRecordParams(page = 1) {
return {
page: 1,
page: Math.max(1, Number(page || 1)),
pageSize: 20,
where: this.buildPrintRecordWhere()
};
@ -480,6 +516,23 @@
const list = response?.data?.list || response?.data?.data?.list;
return Array.isArray(list) ? list : [];
},
extractPrintRecordTotal(response) {
const candidates = [
response?.data?.total,
response?.data?.pagination?.total,
response?.data?.data?.total,
response?.data?.count,
response?.total,
response?.count
];
for (let i = 0; i < candidates.length; i += 1) {
const value = Number(candidates[i]);
if (Number.isFinite(value) && value >= 0) {
return value;
}
}
return 0;
},
normalizePrintStations(list) {
return list
.map(item => {
@ -493,13 +546,18 @@
})
.filter(item => !!item.id && !!item.name);
},
async loadPrintStations() {
const response = await this.$http('print.getList', this.buildPrintRecordParams());
async loadPrintStations(page = 1) {
const response = await this.$http('print.getList', this.buildPrintRecordParams(page));
const list = this.extractPrintRecordList(response);
const total = this.extractPrintRecordTotal(response);
const stations = this.normalizePrintStations(list);
this.printStationList = stations;
this.printStationId = stations[0]?.id || '';
this.printStationName = stations[0]?.name || '--';
this.stationListTotal = total;
this.stationListPage = Math.max(1, Number(page || 1));
if (stations.length && !this.printStationId) {
this.printStationId = stations[0]?.id || '';
this.printStationName = stations[0]?.name || '--';
}
},
togglePrintStationDropdown() {
if (!this.printStationList.length) {
@ -757,8 +815,49 @@
uni.hideLoading();
}
},
toggleUnboundPrintStationOnly() {
async toggleUnboundPrintStationOnly() {
this.showUnboundPrintStationOnly = true;
this.stationListPage = 1;
this.stationListTotal = 0;
this.printStationList = [];
this.printStationId = '';
this.printStationName = '--';
uni.showLoading({
title: '加载打印台...'
});
try {
await this.loadPrintStations(1);
this.showStationListPopup = true;
} catch (error) {
uni.showToast({
title: '打印台列表加载失败',
icon: 'none'
});
} finally {
uni.hideLoading();
}
},
handleStationListPageChange(page) {
const targetPage = Math.max(1, Number(page || 1));
if (targetPage === this.stationListPage) {
return;
}
this.stationListPage = targetPage;
this.loadPrintStations(targetPage);
},
handleStationListItemClick(station) {
if (!station || !station.id) {
return;
}
this.showStationListPopup = false;
setTimeout(() => {
this.printStationId = String(station.id);
this.printStationName = String(station.name || '--');
uni.showToast({
title: `已绑定打印台:${station.name}`,
icon: 'none'
});
}, 300);
},
getStatusText(status) {
const map = {
@ -1312,4 +1411,48 @@
line-height: 40rpx;
color: #303133;
}
.station-list-scroll {
max-height: 600rpx;
padding: 0 10rpx;
}
.station-list-pagination {
padding: 16rpx 10rpx 4rpx;
border-top: 1rpx solid #f2f3f5;
}
.station-list-empty {
text-align: center;
padding: 60rpx 0;
font-size: 28rpx;
color: #909399;
}
.station-list-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 20rpx;
border-bottom: 1rpx solid #f2f3f5;
}
.station-list-item:active {
background: #f5f6fa;
}
.station-list-item__name {
font-size: 30rpx;
color: #303133;
font-weight: 500;
}
.station-list-item__id {
font-size: 26rpx;
color: #909399;
}
.safe-bottom-in-popup {
height: calc(10rpx + env(safe-area-inset-bottom));
}
</style>