WMS_PDA/pages/work/order/groupon-picking-detail.vue

809 lines
22 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="groupon-picking-detail-page">
<view class="normar_container">
<page-nav :title="title">
<template #right>
<view class="nav-right-action" :class="{ 'nav-right-action--active': onlyMine }" @click="toggleOnlyMine">{{ onlyMine ? '查看全部' : '只看我的' }}</view>
</template>
</page-nav>
<scroll-view class="detail-scroll" scroll-y>
<view v-if="displayOrderList.length === 0" class="empty-state">
<u-icon name="list" size="86" color="#c0c4cc"></u-icon>
<text class="empty-text">暂无可拣货团购单</text>
</view>
<view v-else class="record-list">
<view v-for="item in displayOrderList" :key="item.id" class="record-item">
<view class="record-main">
<view class="record-left">
<view class="record-line"><text class="record-label">波次号:</text><text class="record-value">{{ item.waveNo || '--' }}</text></view>
<view class="record-line"><text class="record-label">拣货员:</text><text class="record-value">{{ item.pickerName || '--' }}</text></view>
</view>
<view class="record-right">
<text class="record-count">未复核 {{ item.pendingCount }}</text>
</view>
</view>
<view class="record-footer">
<u-button
type="primary"
size="mini"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff', fontSize: '26rpx', height: '64rpx', lineHeight: '64rpx', padding: '0 20rpx' }"
@click="showRecordDetail(item)"
>
打印面单
</u-button>
</view>
</view>
</view>
<view class="safe-area-bottom"></view>
</scroll-view>
<view class="pagination-wrap">
<pagination
:pageNum.sync="currentPage"
:pageSize="pageSize"
:total="paginationTotal"
:showTotal="true"
:prevText="'上一页'"
:nextText="'下一页'"
:showFirstLast="true"
:firstText="'首页'"
:lastText="'末页'"
@change="handlePageChange"
/>
</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>
<script>
export default {
data() {
return {
title: '团购拣货详情',
onlyMine: false,
currentUserId: '',
grabCount: 0,
pageSize: 20,
currentPage: 1,
paginationTotal: 0,
showPrintPopup: false,
showPrintStationDropdown: false,
printStationName: '--',
printStationId: '',
printStationList: [],
printMessage: '',
pendingPrintCount: 0,
printRequestCode: '',
printWaveGroups: [],
printWavePlatformPrintData: null,
printTargetList: [],
orderList: []
};
},
computed: {
displayOrderList() {
if (!this.onlyMine) {
return this.orderList;
}
return this.orderList.filter(item => item.isMine);
}
},
onLoad(options) {
this.currentUserId = String(this.$store?.getters?.user?.id || this.$store?.getters?.user?.user_id || '').trim();
const hasGrabCountParam = options && Object.prototype.hasOwnProperty.call(options, 'grabCount');
const parsedGrabCount = Number(options?.grabCount || 0);
this.grabCount = hasGrabCountParam ? Math.max(0, parsedGrabCount) : 6;
this.loadBatchWaveNoList();
},
methods: {
buildBatchListParams(page = this.currentPage) {
return {
pagination: {
page: Number(page || 1),
pageSize: Number(this.pageSize || 20)
},
where: {
source: 0,
wave_type: 1
}
};
},
extractPagination(payload, response) {
return payload?.pagination || payload?.page || response?.data?.pagination || response?.pagination || null;
},
extractBatchListPayload(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' && !Array.isArray(current)) {
return current;
}
}
return {};
},
extractBatchList(payload, response) {
const candidates = [
payload?.list,
payload?.rows,
payload?.items,
payload?.data?.list,
response?.data?.list,
response?.data?.data?.list,
response?.list
];
for (let i = 0; i < candidates.length; i += 1) {
if (Array.isArray(candidates[i])) {
return candidates[i];
}
}
return [];
},
normalizeBatchWaveList(list) {
if (!Array.isArray(list)) {
return [];
}
return list
.map(item => {
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,
isMine: !!this.currentUserId && !!assigneeId && assigneeId === this.currentUserId
};
})
.filter(item => !!item.waveNo)
.map((item, index) => ({
...item,
id: item.id || `batch-${this.currentPage}-${index + 1}`
}));
},
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;
}
}
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 {
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.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.paginationTotal = 0;
uni.showToast({
title: '波次列表加载失败',
icon: 'none'
});
}
},
toggleOnlyMine() {
this.onlyMine = !this.onlyMine;
},
buildMockOrderList(count) {
const listCount = Math.max(0, Number(count || 0));
return Array.from({ length: listCount }).map((_, index) => {
const waveNo = `GW${new Date().getFullYear()}${String(index + 1).padStart(4, '0')}`;
const orderNo = `TG${Date.now().toString().slice(-6)}${String(index + 1).padStart(2, '0')}`;
const isMine = index % 2 === 0;
return {
id: `${orderNo}-${index + 1}`,
waveId: `${index + 1}`,
waveNo,
pickerName: isMine ? '我' : `拣货员${(index % 3) + 1}`,
pendingCount: (index % 5) + 1,
isMine
};
});
},
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));
if (targetPage === this.currentPage) {
return;
}
this.currentPage = targetPage;
this.loadBatchWaveNoList(targetPage);
}
}
};
</script>
<style lang="scss" scoped>
.groupon-picking-detail-page {
height: 100vh;
background: #f8f9fa;
}
.normar_container {
height: 100%;
display: flex;
flex-direction: column;
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;
display: flex;
justify-content: flex-end;
}
.nav-right-action {
font-size: 32rpx;
line-height: 36rpx;
color: #ffffff;
padding: 8rpx 18rpx;
border-radius: 6rpx;
background: #2979ff;
}
.nav-right-action--active {
background: #1f67e6;
}
.detail-scroll {
flex: 1;
min-height: 0;
height: auto;
padding: 20rpx 24rpx 0;
box-sizing: border-box;
}
.pagination-wrap {
background: #ffffff;
border-top: 1rpx solid #f0f0f0;
padding: 0 24rpx env(safe-area-inset-bottom);
flex-shrink: 0;
}
.record-list {
display: flex;
flex-direction: column;
gap: 14rpx;
}
.record-item {
background: #ffffff;
border-radius: 12rpx;
padding: 18rpx;
border: 1rpx solid #ebeef5;
}
.record-main {
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.record-left {
flex: 1;
min-width: 0;
}
.record-line {
display: flex;
align-items: center;
font-size: 32rpx;
line-height: 52rpx;
}
.record-line + .record-line {
margin-top: 8rpx;
}
.record-label {
width: 170rpx;
min-width: 170rpx;
color: #909399;
white-space: nowrap;
flex-shrink: 0;
}
.record-value {
flex: 1;
color: #303133;
}
.record-right {
min-width: 180rpx;
display: flex;
flex-direction: column;
align-items: flex-end;
margin-left: 16rpx;
}
.record-count {
font-size: 30rpx;
line-height: 40rpx;
color: #fa8c16;
}
.record-status {
margin-top: 12rpx;
font-size: 30rpx;
line-height: 40rpx;
color: #2979ff;
}
.record-footer {
margin-top: 14rpx;
display: flex;
justify-content: flex-end;
}
.empty-state {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.empty-text {
margin-top: 18rpx;
font-size: 28rpx;
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));
}
</style>