修改复核发货,面单补打功能

This commit is contained in:
zm2000 2026-07-31 19:08:07 +08:00
parent c290eecc2b
commit 2a7847de15
2 changed files with 118 additions and 8 deletions

View File

@ -379,6 +379,12 @@ export default {
auth: true,
method: "POST",
isSystemApi: true
},
unlockWavePlatformPrintDataByGroup: {
path: "order.print.unlockWavePlatformPrintDataByGroup",
auth: true,
method: "POST",
isSystemApi: true
}
},
wave: {

View File

@ -822,6 +822,110 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
.map(group => (group && typeof group === 'object' ? group : null))
.filter(group => !!group);
},
/**
* 提取 getWavePlatformPrintData 返回的 locked_wave_groups(打印锁占用的分组)
* 已打印面单的数据会出现在 locked_wave_groups,而 waveGroups 为空
* @param {object} payload
*/
extractLockedWaveGroups(payload) {
const groups = Array.isArray(payload?.locked_wave_groups) ? payload.locked_wave_groups : [];
return groups
.map(group => (group && typeof group === 'object' ? group : null))
.filter(group => !!group);
},
/**
* 将 locked_wave_groups 转换为 unlockWavePlatformPrintDataByGroup 所需的 groups 分组条件
* 每个(波次 + 平台 + 系统快递编码)组合为一个分组
* @param {Array} lockedWaveGroups 打印锁占用的波次平台分组
*/
buildUnlockGroups(lockedWaveGroups) {
const groups = [];
(Array.isArray(lockedWaveGroups) ? lockedWaveGroups : []).forEach(waveGroup => {
const waveId = waveGroup?.wave_id ?? waveGroup?.waveId ?? waveGroup?.id ?? '';
const platforms = Array.isArray(waveGroup?.platforms) ? waveGroup.platforms : [];
if (platforms.length) {
platforms.forEach(platform => {
groups.push({
wave_id: waveId,
platform: platform?.platform ?? platform?.platform_code ?? '',
sys_logistics_code: platform?.sys_logistics_code ?? platform?.sysLogisticsCode ?? platform?.logistics_code ?? '',
order_ids: Array.isArray(platform?.order_ids) ? platform.order_ids : []
});
});
} else if (waveId !== '' && waveId != null) {
// 无平台嵌套时按波次兜底
groups.push({ wave_id: waveId, platform: '', sys_logistics_code: '', order_ids: [] });
}
});
return groups.filter(group => group.wave_id !== '' && group.wave_id != null);
},
/**
* 按分组解锁波次平台打印锁(order.print.unlockWavePlatformPrintDataByGroup)
* 将传入的分组中已锁定的订单 print_lock_status 置为 none
* @param {Array} lockedWaveGroups 打印锁占用的波次平台分组(用于构建 groups 条件)
* @returns {Promise<object>} 解锁结果(summary / unlocked_order_ids / unlocked_orders 等)
*/
async unlockWavePlatformPrintDataByGroup(lockedWaveGroups) {
const warehouseId = this.resolveWarehouseId();
if (!warehouseId) {
throw new Error('缺少仓库ID');
}
const groups = this.buildUnlockGroups(lockedWaveGroups);
if (!groups.length) {
throw new Error('缺少可解锁的分组条件');
}
const waveIds = Array.from(new Set(
groups.map(g => g.wave_id).filter(id => id !== '' && id != null)
));
const params = {
warehouse_id: warehouseId,
wave_ids: waveIds,
group_type: 'platform_express',
unlock_scope: 'group',
groups
};
this.debugLog('unlockWavePlatformPrintDataByGroup 请求参数', params);
const response = await this.$http('order.print.unlockWavePlatformPrintDataByGroup', params);
this.debugLog('unlockWavePlatformPrintDataByGroup 返回数据', response);
return response;
},
/**
* 获取团购(团单)模式波次平台可打印数据。
* 已打印面单(打印锁占用)时 getWavePlatformPrintData 返回的 waveGroups 为空、
* locked_wave_groups 有值,需先按分组解锁打印锁,解锁后重新获取可打印数据
* @param {object} item 订单/波次对象
* @returns {Promise<Array>} waveGroups
*/
async fetchGroupWavePrintData(item) {
const warehouseId = this.resolveWarehouseId();
const waveId = String(item?.waveId || item?.id || '').trim();
const requestData = async () => {
const response = await this.$http('order.print.getWavePlatformPrintData', { warehouse_id: warehouseId, wave_ids: [waveId] });
return this.extractWavePlatformPrintPayload(response);
};
let payload = await requestData();
let waveGroups = this.normalizeWaveGroups(payload);
const lockedWaveGroups = this.extractLockedWaveGroups(payload);
// 打印锁占用:waveGroups 为空 + locked_wave_groups 有值 → 先解锁再重新获取
if (!waveGroups.length && lockedWaveGroups.length) {
try {
const unlockResponse = await this.unlockWavePlatformPrintDataByGroup(lockedWaveGroups);
const unlockPayload = unlockResponse?.data?.data
|| unlockResponse?.data
|| unlockResponse?.result
|| unlockResponse
|| {};
const unlockedIds = unlockPayload?.unlocked_order_ids || [];
const unlockedCount = Array.isArray(unlockedIds) ? unlockedIds.length : 0;
console.log(`[handlePrintOrder] 波次平台打印锁解锁成功,解锁订单数: ${unlockedCount}`);
} catch (error) {
throw new Error(`解锁打印锁失败:${String(error?.message || error?.msg || error?.errMsg || '请稍后重试')}`);
}
payload = await requestData();
waveGroups = this.normalizeWaveGroups(payload);
}
return waveGroups;
},
buildPrintRequestCode() {
const timePart = Date.now().toString(36);
const randomPart = Math.random().toString(36).slice(2, 10);
@ -3042,13 +3146,17 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
return [];
},
handleReprint() {
// 使用当前 detailInfo 作为 item 调用打印
// 使用当前 detailInfo 作为 item 调用打印(携带打印状态字段,供补打前解锁判断)
const item = {
id: this.detailInfo?.orderId || this.detailInfo?.recordId,
orderId: this.detailInfo?.orderId,
orderIds: this.detailInfo?.orderIds,
waveNo: this.detailInfo?.waveNo,
waveId: this.detailInfo?.waveId
waveId: this.detailInfo?.waveId,
unprintedCount: this.detailInfo?.unprintedCount,
orderCount: this.detailInfo?.orderCount,
totalOrders: this.detailInfo?.totalOrders,
isPrinted: this.detailInfo?.isPrinted
};
this.handlePrintOrder(item);
},
@ -3120,14 +3228,10 @@ import ReviewDetail from './order-review-comps/ReviewDetail.vue';
uni.showLoading({ title: '处理打印中...' });
try {
// 1. 获取打印数据
// 1. 获取打印数据(团购模式:若打印锁占用则先按分组解锁,解锁后重新获取可打印数据)
let waveGroups;
if (this.listType === 'group') {
const warehouseId = this.resolveWarehouseId();
const waveId = String(item?.waveId || item?.id || '').trim();
const response = await this.$http('order.print.getWavePlatformPrintData', { warehouse_id: warehouseId, wave_ids: [waveId] });
const payload = this.extractWavePlatformPrintPayload(response);
waveGroups = this.normalizeWaveGroups(payload);
waveGroups = await this.fetchGroupWavePrintData(item);
} else {
const params = this.buildOrderPrintDataParams(item);
const response = await this.$http('order.print.getOrderPrintData', params);