修改散单、团购拣货页面的打印、底部分页功能

This commit is contained in:
zm2000 2026-06-02 17:56:37 +08:00
parent 2e41d72791
commit 5a6d95914e
2 changed files with 543 additions and 95 deletions

View File

@ -53,6 +53,46 @@
/>
</view>
</view>
<u-popup v-if="showPrintPopup" :show="showPrintPopup" mode="bottom" :closeable="true" border-radius="20" :z-index="10090" @close="handlePrintPopupClose">
<view class="print-popup">
<view class="print-popup-title">打印设置</view>
<view class="print-row print-row--station">
<text class="print-label">打印台</text>
<view class="print-picker" @click="togglePrintStationDropdown">
<text class="print-picker-value">{{ printStationName || '--' }}</text>
<u-icon :name="showPrintStationDropdown ? 'arrow-up' : 'arrow-down'" size="24" color="#909399"></u-icon>
</view>
<view v-if="showPrintStationDropdown" class="print-station-dropdown">
<view
v-for="station in printStationList"
:key="station.id"
class="print-station-option"
:class="{ 'print-station-option--active': station.id === printStationId }"
@click.stop="handlePrintStationSelect(station)"
>
{{ station.name }}
</view>
</view>
</view>
<view class="print-row print-row--action">
<text class="print-label">打印</text>
<u-button
type="primary"
size="mini"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff', fontSize: '26rpx', height: '64rpx', lineHeight: '64rpx', padding: '0 20rpx' }"
@click="handleConfirmPrint"
@tap="handleConfirmPrint"
>
打印
</u-button>
</view>
<view class="print-row print-row--message">
<text class="print-label">打印消息</text>
<text class="print-message">{{ printMessage || '暂无打印消息' }}</text>
</view>
</view>
</u-popup>
</view>
</template>
@ -67,6 +107,17 @@
pageSize: 20,
currentPage: 1,
paginationTotal: 0,
showPrintPopup: false,
showPrintStationDropdown: false,
printStationName: '--',
printStationId: '',
printStationList: [],
printMessage: '',
pendingPrintCount: 0,
printRequestCode: '',
printWaveGroups: [],
printWavePlatformPrintData: null,
printTargetList: [],
orderList: []
};
},
@ -142,11 +193,13 @@
const source = item && typeof item === 'object' ? item : {};
const waveNo = String(source.wave_no || '').trim();
const rowId = source.wave_id ?? source.waveId ?? source.id ?? waveNo;
const waveId = source.wave_id ?? source.waveId ?? source.id ?? '';
const pickerName = String(source.picker_name || source.pickerName || source.user_name || source.userName || '--').trim() || '--';
const pendingCount = Number(source.pending_count ?? source.pendingCount ?? source.unreviewed_count ?? source.unreviewedCount ?? 0);
const assigneeId = String((source.picker_id ?? source.pickerId ?? source.user_id ?? source.userId) || '').trim();
return {
id: String(rowId || ''),
waveId: typeof waveId === 'number' ? waveId : String(waveId || '').trim(),
waveNo,
pickerName,
pendingCount: Number.isFinite(pendingCount) ? pendingCount : 0,
@ -177,6 +230,147 @@
}
return 0;
},
resolveWarehouseId() {
const user = this.$store?.getters?.user || {};
const userInfo = this.$store?.getters?.userInfo || {};
const candidates = [
user?.store_id,
user?.storeId,
userInfo?.store_id,
userInfo?.storeId,
uni.getStorageSync('store_id'),
uni.getStorageSync('storeId'),
user?.warehouse_id,
user?.warehouseId,
userInfo?.warehouse_id,
userInfo?.warehouseId,
uni.getStorageSync('warehouse_id'),
uni.getStorageSync('warehouseId')
];
for (let i = 0; i < candidates.length; i += 1) {
const value = Number(candidates[i]);
if (Number.isFinite(value) && value > 0) {
return value;
}
}
return 0;
},
normalizeWaveIds(list) {
const sourceList = Array.isArray(list) ? list : [];
const normalized = sourceList
.map(item => item?.waveId ?? item?.id ?? '')
.map(value => (typeof value === 'number' ? value : String(value || '').trim()))
.filter(value => value !== '' && value !== '--');
return Array.from(new Set(normalized));
},
buildWavePlatformPrintParams() {
const warehouseId = this.resolveWarehouseId();
const waveIds = this.normalizeWaveIds(this.printTargetList);
return {
warehouse_id: warehouseId,
wave_ids: waveIds
};
},
extractWavePlatformPrintPayload(response) {
const candidates = [
response?.data?.data,
response?.data,
response?.result,
response
];
for (let i = 0; i < candidates.length; i += 1) {
const current = candidates[i];
if (current && typeof current === 'object') {
return current;
}
}
return {};
},
normalizeWaveGroups(payload) {
const groups = Array.isArray(payload?.waveGroups) ? payload.waveGroups : [];
return groups
.map(group => (group && typeof group === 'object' ? group : null))
.filter(group => !!group);
},
buildPrintRequestCode() {
const timePart = Date.now().toString(36);
const randomPart = Math.random().toString(36).slice(2, 10);
return `PRINT_${timePart}_${randomPart}`;
},
async requestWavePlatformPrintData() {
const params = this.buildWavePlatformPrintParams();
console.log('[GrouponPickingDetail] getWavePlatformPrintData params:', params);
try {
const response = await this.$http('order.print.getWavePlatformPrintData', params);
console.log('[GrouponPickingDetail] getWavePlatformPrintData success:', response);
const payload = this.extractWavePlatformPrintPayload(response);
const waveGroups = this.normalizeWaveGroups(payload);
if (!waveGroups.length) {
throw new Error('未获取到可打印的waveGroups');
}
this.printWavePlatformPrintData = payload;
this.printWaveGroups = waveGroups;
this.printRequestCode = this.buildPrintRequestCode();
return payload;
} catch (error) {
console.error('[GrouponPickingDetail] getWavePlatformPrintData error:', error);
throw error;
}
},
buildPrintRecordWhere() {
return {};
},
buildPrintRecordParams() {
return {
page: 1,
pageSize: 20,
where: this.buildPrintRecordWhere()
};
},
extractPrintRecordList(response) {
const list = response?.data?.list || response?.data?.data?.list;
return Array.isArray(list) ? list : [];
},
normalizePrintStations(list) {
return list
.map(item => {
const source = item && typeof item === 'object' ? item : {};
const id = String(source.id ?? source.print_station_id ?? source.printStationId ?? '').trim();
const name = String(source.name || source.station_name || source.print_station_name || '').trim();
return {
id,
name
};
})
.filter(item => !!item.id && !!item.name);
},
async loadPrintStations() {
const response = await this.$http('print.getList', this.buildPrintRecordParams());
const list = this.extractPrintRecordList(response);
const stations = this.normalizePrintStations(list);
this.printStationList = stations;
this.printStationId = stations[0]?.id || '';
this.printStationName = stations[0]?.name || '--';
},
togglePrintStationDropdown() {
if (!this.printStationList.length) {
uni.showToast({
title: '暂无可用打印台',
icon: 'none'
});
return;
}
this.showPrintStationDropdown = !this.showPrintStationDropdown;
},
handlePrintStationSelect(station) {
this.printStationId = String(station?.id || '');
this.printStationName = String(station?.name || '--');
this.showPrintStationDropdown = false;
},
handlePrintPopupClose() {
this.showPrintPopup = false;
this.showPrintStationDropdown = false;
},
async loadBatchWaveNoList(page = this.currentPage) {
const targetPage = Math.max(1, Number(page || 1));
try {
@ -209,6 +403,7 @@
const isMine = index % 2 === 0;
return {
id: `${orderNo}-${index + 1}`,
waveId: `${index + 1}`,
waveNo,
pickerName: isMine ? '我' : `拣货员${(index % 3) + 1}`,
pendingCount: (index % 5) + 1,
@ -216,17 +411,131 @@
};
});
},
showRecordDetail(item) {
if (!item) return;
uni.showModal({
title: '打印面单',
showCancel: false,
content: [
`波次号:${item.waveNo || '--'}`,
`拣货员:${item.pickerName || '--'}`,
`未复核数量:${item.pendingCount || 0}`
].join('\n')
async showRecordDetail(item) {
const target = item && typeof item === 'object' ? item : null;
console.log('[GrouponPickingDetail] print button clicked:', target);
if (!target) {
uni.showToast({
title: '未找到可打印波次',
icon: 'none'
});
return;
}
const targetWaveId = target.waveId ?? target.id ?? '';
if (targetWaveId === '' || targetWaveId === null || targetWaveId === undefined) {
uni.showToast({
title: '波次缺少wave_id,无法打印',
icon: 'none'
});
return;
}
this.printTargetList = [{
...target,
waveId: targetWaveId
}];
this.printWaveGroups = [];
this.printWavePlatformPrintData = null;
try {
await this.requestWavePlatformPrintData();
} catch (error) {
const message = String(error?.message || error?.msg || error?.errMsg || '打印数据获取失败');
this.printMessage = message;
uni.showToast({
title: message,
icon: 'none'
});
return;
}
try {
await this.loadPrintStations();
} catch (error) {
this.printStationList = [];
this.printStationId = '';
this.printStationName = '--';
uni.showToast({
title: '打印台加载失败',
icon: 'none'
});
}
this.pendingPrintCount = Number(target.pendingCount || 0);
this.printMessage = `待打印未复核订单 ${this.pendingPrintCount} 条`;
this.showPrintStationDropdown = false;
this.showPrintPopup = true;
},
buildPrintSendParams() {
if (!this.printRequestCode) {
this.printRequestCode = this.buildPrintRequestCode();
}
return {
type: 'express',
printStationId: this.printStationId,
requestCode: this.printRequestCode,
data: {
waveGroups: Array.isArray(this.printWaveGroups) ? this.printWaveGroups : []
}
};
},
async handleConfirmPrint() {
console.log('[GrouponPickingDetail] handleConfirmPrint clicked:', {
printStationId: this.printStationId,
printStationName: this.printStationName,
printStationListLength: Array.isArray(this.printStationList) ? this.printStationList.length : 0,
pendingPrintCount: this.pendingPrintCount,
waveGroupsLength: Array.isArray(this.printWaveGroups) ? this.printWaveGroups.length : 0
});
if (!this.printStationList.length || !this.printStationId || !this.printStationName || this.printStationName === '--') {
console.warn('[GrouponPickingDetail] handleConfirmPrint blocked: invalid print station');
this.printMessage = '请选择打印台';
uni.showToast({
title: '请选择打印台',
icon: 'none'
});
return;
}
if (!Array.isArray(this.printWaveGroups) || !this.printWaveGroups.length) {
console.warn('[GrouponPickingDetail] handleConfirmPrint blocked: waveGroups empty');
this.printMessage = '未获取到打印数据';
uni.showToast({
title: '未获取到打印数据',
icon: 'none'
});
return;
}
const params = this.buildPrintSendParams();
const effectivePrintCount = Number(this.pendingPrintCount || 0) > 0
? Number(this.pendingPrintCount || 0)
: this.printWaveGroups.length;
console.log('[GrouponPickingDetail] print.send params:', params);
uni.showLoading({
title: '发送打印中...'
});
try {
const response = await this.$http('print.send', params);
console.log('[GrouponPickingDetail] print.send success:', response);
const success = response?.flag !== 'failure' && response?.code !== '500' && response?.code !== 500;
if (!success) {
throw new Error(response?.message || response?.msg || '打印失败');
}
this.printMessage = `打印已发送,未复核订单 ${effectivePrintCount} 条`;
uni.showToast({
title: `已发起打印${effectivePrintCount}条`,
icon: 'none'
});
this.showPrintPopup = false;
} catch (error) {
console.error('[GrouponPickingDetail] print.send error:', error);
const message = String(error?.message || error?.msg || error?.errMsg || '打印失败');
this.printMessage = message;
uni.showToast({
title: message,
icon: 'none'
});
} finally {
uni.hideLoading();
}
},
handlePageChange(page) {
const targetPage = Math.max(1, Number(page || 1));
@ -253,6 +562,11 @@
overflow: hidden;
}
::v-deep .u-popup,
::v-deep .u-popup-mask {
z-index: 10090 !important;
}
::v-deep .nav-title .right {
width: auto;
min-width: 136rpx;
@ -377,6 +691,118 @@
color: #909399;
}
.print-popup {
padding: 24rpx 24rpx calc(20rpx + env(safe-area-inset-bottom));
background: #ffffff;
border-top-left-radius: 20rpx;
border-top-right-radius: 20rpx;
}
.print-popup-title {
font-size: 34rpx;
font-weight: 600;
color: #303133;
text-align: left;
margin-bottom: 20rpx;
}
.print-row {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
padding: 16rpx 0;
border-bottom: 1rpx solid #f5f5f5;
gap: 16rpx;
}
.print-row--station {
align-items: flex-start;
padding-top: 8rpx;
}
.print-row--station .print-label {
padding-top: 10rpx;
}
.print-label {
min-width: 120rpx;
font-size: 30rpx;
color: #606266;
line-height: 44rpx;
}
.print-picker {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
justify-content: space-between;
padding: 10rpx 16rpx;
border: 1rpx solid #dcdfe6;
border-radius: 10rpx;
background: #fafafa;
}
.print-picker-value {
flex: 1;
font-size: 28rpx;
color: #303133;
padding-right: 16rpx;
word-break: break-all;
}
.print-station-dropdown {
position: absolute;
right: 0;
top: calc(100% - 4rpx);
width: calc(100% - 144rpx);
max-height: 360rpx;
overflow-y: auto;
background: #ffffff;
border: 1rpx solid #ebeef5;
border-radius: 12rpx;
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.08);
z-index: 12;
}
.print-station-option {
padding: 16rpx 20rpx;
font-size: 28rpx;
line-height: 40rpx;
color: #303133;
}
.print-station-option + .print-station-option {
border-top: 1rpx solid #f5f5f5;
}
.print-station-option--active {
color: #2979ff;
background: rgba(41, 121, 255, 0.08);
}
.print-row--action .u-btn {
min-width: 160rpx;
}
.print-row--message {
align-items: flex-start;
justify-content: flex-start;
border-bottom: none;
padding-bottom: 0;
padding-top: 12rpx;
}
.print-message {
flex: 1;
font-size: 28rpx;
line-height: 40rpx;
color: #606266;
text-align: left;
word-break: break-all;
}
.safe-area-bottom {
height: calc(30rpx + env(safe-area-inset-bottom));
}

View File

@ -108,7 +108,7 @@
<u-button
type="primary"
size="mini"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff' }"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff', fontSize: '26rpx', height: '64rpx', lineHeight: '64rpx', padding: '0 20rpx' }"
@click="handleConfirmPrint"
>
打印
@ -134,6 +134,7 @@
currentUserId: '',
pageSize: 20,
currentPage: 1,
paginationTotal: 0,
showPrintPopup: false,
showPrintStationDropdown: false,
printStationName: '--',
@ -149,47 +150,8 @@
};
},
computed: {
filteredOrderList() {
let list = this.onlyMine
? this.orderList.filter(item => item.isMine)
: this.orderList;
const keyword = this.normalizeKeyword(this.keyword).toLowerCase();
if (!keyword) {
return list;
}
list = list.filter(item => {
const waybillCode = this.normalizeKeyword(item?.waybillCode).toLowerCase();
const cartNo = this.normalizeKeyword(item?.cartNo).toLowerCase();
return waybillCode.includes(keyword) || cartNo.includes(keyword);
});
return list;
},
paginationTotal() {
return this.filteredOrderList.length;
},
displayOrderList() {
const page = Math.max(1, Number(this.currentPage || 1));
const size = Math.max(1, Number(this.pageSize || 20));
const start = (page - 1) * size;
return this.filteredOrderList.slice(start, start + size);
}
},
watch: {
keyword() {
this.currentPage = 1;
},
onlyMine() {
this.currentPage = 1;
},
paginationTotal(newTotal) {
const total = Number(newTotal || 0);
const maxPage = Math.max(1, Math.ceil(total / this.pageSize));
if (this.currentPage > maxPage) {
this.currentPage = maxPage;
}
return Array.isArray(this.orderList) ? this.orderList : [];
}
},
onLoad(options) {
@ -204,8 +166,7 @@
this.grabCount = hasGrabCountParam
? Math.max(0, parsedGrabCount)
: 5;
this.orderList = this.buildMockOrderList(this.grabCount);
this.loadBatchWaveNoList();
this.loadBatchWaveNoList(1);
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
@ -220,18 +181,25 @@
this.safeDispatchBroadcast('stop');
},
methods: {
buildBatchListParams() {
buildBatchListParams(page = this.currentPage) {
const where = {
source: 0,
wave_type: 2
};
if (this.onlyMine && this.currentUserId) {
where.picker_id = this.currentUserId;
}
return {
pagination: {
page: 1,
pageSize: 20
page: Math.max(1, Number(page || 1)),
pageSize: Math.max(1, Number(this.pageSize || 20))
},
where: {
source: 0,
wave_type: 2
}
where
};
},
extractPagination(payload, response) {
return payload?.pagination || payload?.page || response?.data?.pagination || response?.pagination || null;
},
extractBatchListPayload(response) {
const candidates = [
response?.data?.data,
@ -268,35 +236,67 @@
if (!Array.isArray(list)) {
return [];
}
return list.map(item => {
const source = item && typeof item === 'object' ? item : {};
return {
waveNo: String(source.wave_no || '').trim(),
waveId: source.wave_id ?? source.waveId ?? source.id ?? ''
};
}).filter(item => !!item.waveNo);
return list
.map((item, index) => {
const source = item && typeof item === 'object' ? item : {};
const waveNo = String(source.wave_no || source.waveNo || '').trim();
const waveId = source.wave_id ?? source.waveId ?? source.id ?? '';
const rowId = source.id ?? waveId ?? waveNo ?? `batch-${this.currentPage}-${index + 1}`;
const pickerName = String(source.picker_name || source.pickerName || source.user_name || source.userName || '--').trim() || '--';
const cartNo = String(source.cart_code || source.cartCode || source.cart_no || source.cartNo || '--').trim() || '--';
const unreviewedCount = Number(source.unreviewed_count ?? source.unreviewedCount ?? source.pending_count ?? source.pendingCount ?? 0);
const assigneeId = String((source.picker_id ?? source.pickerId ?? source.user_id ?? source.userId) || '').trim();
return {
id: String(rowId || `batch-${this.currentPage}-${index + 1}`),
waveId: typeof waveId === 'number' ? waveId : String(waveId || '').trim(),
waveNo,
pickerName,
cartNo,
unreviewedCount: Number.isFinite(unreviewedCount) ? unreviewedCount : 0,
status: String(source.status || 'pending'),
waybillCode: String(source.waybill_no || source.waybillCode || source.waybill_code || ''),
isMine: !!this.currentUserId && !!assigneeId && assigneeId === this.currentUserId
};
})
.filter(item => !!item.waveNo);
},
applyWaveNoToMockList(batchWaveList) {
const count = batchWaveList.length ? batchWaveList.length : this.grabCount;
const mockList = this.buildMockOrderList(count);
if (batchWaveList.length) {
mockList.forEach((item, index) => {
const current = batchWaveList[index] || {};
item.waveNo = current.waveNo || item.waveNo;
item.waveId = current.waveId || '';
});
resolvePaginationTotal(payload, response, pagination, list) {
const candidates = [
pagination?.total,
payload?.total,
payload?.count,
payload?.totalCount,
response?.data?.total,
response?.total,
Array.isArray(list) ? list.length : 0
];
for (let i = 0; i < candidates.length; i += 1) {
const value = Number(candidates[i]);
if (Number.isFinite(value) && value >= 0) {
return value;
}
}
this.orderList = mockList;
return 0;
},
async loadBatchWaveNoList() {
async loadBatchWaveNoList(page = this.currentPage) {
const targetPage = Math.max(1, Number(page || 1));
try {
const response = await this.$http('order.wave.batchList', this.buildBatchListParams());
const response = await this.$http('order.wave.batchList', this.buildBatchListParams(targetPage));
const payload = this.extractBatchListPayload(response);
const list = this.extractBatchList(payload, response);
const pagination = this.extractPagination(payload, response);
const batchWaveList = this.normalizeBatchWaveList(list);
this.applyWaveNoToMockList(batchWaveList);
this.orderList = batchWaveList;
this.paginationTotal = this.resolvePaginationTotal(payload, response, pagination, list);
this.currentPage = Number((pagination?.page ?? targetPage) || targetPage);
this.pageSize = Number((pagination?.pageSize ?? this.pageSize) || this.pageSize);
} catch (error) {
this.orderList = this.buildMockOrderList(this.grabCount);
this.orderList = [];
this.paginationTotal = 0;
uni.showToast({
title: '波次列表加载失败',
icon: 'none'
});
}
},
resolveWarehouseId() {
@ -676,6 +676,8 @@
},
toggleOnlyMine() {
this.onlyMine = !this.onlyMine;
this.currentPage = 1;
this.loadBatchWaveNoList(1);
},
buildMockOrderList(count) {
const listCount = Math.max(0, Number(count || 0));
@ -724,7 +726,7 @@
},
async handlePrintAllUnreviewed(item) {
const target = item && typeof item === 'object' ? item : null;
if (!target || Number(target.unreviewedCount || 0) <= 0) {
if (!target) {
uni.showToast({
title: '暂无未复核订单可打印',
icon: 'none'
@ -782,10 +784,6 @@
});
return;
}
if (this.pendingPrintCount <= 0) {
this.printMessage = '暂无可打印订单';
return;
}
if (!Array.isArray(this.printWaveGroups) || !this.printWaveGroups.length) {
this.printMessage = '未获取到打印数据';
uni.showToast({
@ -796,6 +794,9 @@
}
const params = this.buildPrintSendParams();
const effectivePrintCount = Number(this.pendingPrintCount || 0) > 0
? Number(this.pendingPrintCount || 0)
: this.printWaveGroups.length;
uni.showLoading({
title: '发送打印中...'
});
@ -805,9 +806,9 @@
if (!success) {
throw new Error(response?.message || response?.msg || '打印失败');
}
this.printMessage = `打印已发送,未复核订单 ${this.pendingPrintCount} 条`;
this.printMessage = `打印已发送,未复核订单 ${effectivePrintCount} 条`;
uni.showToast({
title: `已发起打印${this.pendingPrintCount}条`,
title: `已发起打印${effectivePrintCount}条`,
icon: 'none'
});
this.showPrintPopup = false;
@ -823,7 +824,12 @@
}
},
handlePageChange(page) {
this.currentPage = Math.max(1, Number(page || 1));
const targetPage = Math.max(1, Number(page || 1));
if (targetPage === this.currentPage) {
return;
}
this.currentPage = targetPage;
this.loadBatchWaveNoList(targetPage);
}
}
};
@ -1061,14 +1067,17 @@
}
.print-popup {
padding: 24rpx;
padding: 24rpx 24rpx calc(20rpx + env(safe-area-inset-bottom));
background: #ffffff;
border-top-left-radius: 20rpx;
border-top-right-radius: 20rpx;
}
.print-popup-title {
font-size: 32rpx;
font-size: 34rpx;
font-weight: 600;
color: #303133;
margin-bottom: 18rpx;
margin-bottom: 20rpx;
}
.print-row {
@ -1082,6 +1091,10 @@
position: relative;
}
.print-row--station .print-label {
padding-top: 10rpx;
}
.print-row--action {
align-items: center;
}
@ -1091,6 +1104,7 @@
}
.print-label {
min-width: 130rpx;
width: 130rpx;
font-size: 28rpx;
line-height: 40rpx;
@ -1106,27 +1120,35 @@
.print-picker {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
justify-content: space-between;
padding: 10rpx 16rpx;
border: 1rpx solid #dcdfe6;
border-radius: 10rpx;
background: #fafafa;
}
.print-picker-value {
flex: 1;
font-size: 28rpx;
line-height: 40rpx;
color: #303133;
padding-right: 16rpx;
word-break: break-all;
}
.print-station-dropdown {
position: absolute;
left: 130rpx;
right: 0;
top: 74rpx;
top: calc(100% - 4rpx);
width: calc(100% - 154rpx);
max-height: 300rpx;
overflow-y: auto;
background: #ffffff;
border: 1rpx solid #ebeef5;
border-radius: 8rpx;
border-radius: 10rpx;
z-index: 10091;
}