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

690 lines
17 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="scatter-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>
<view class="search-filter">
<view class="search-box">
<view class="search-box-inner">
<u-search
v-model="keyword"
placeholder="请输入快递单号/车号"
:bg-color="'#f5f5f5'"
shape="round"
:show-action="false"
@search="handleSearch"
@clear="clearSearch"
></u-search>
<view class="search-actions">
<view class="scan-btn" @click="handleCameraScan">
<u-icon name="scan" size="38rpx" color="#2979ff"></u-icon>
</view>
<view class="search-divider"></view>
<view class="search-btn" @click="handleSearch">
<text class="search-btn__text">搜索</text>
</view>
</view>
</view>
</view>
</view>
<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" @click="goPickGoodsDetail(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 class="record-line"><text class="record-label">车号:</text><text class="record-value">{{ item.cartNo || '--' }}</text></view>
</view>
<view class="record-right">
<text class="record-count">未复核 {{ item.unreviewedCount }}</text>
<text class="record-status">{{ getStatusText(item.status) }}</text>
</view>
</view>
<view class="record-footer" @click.stop>
<u-button
type="primary"
size="mini"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff', fontSize: '26rpx', height: '64rpx', lineHeight: '64rpx', padding: '0 20rpx' }"
@click.native.stop="handlePrintAllUnreviewed"
>
打印所有未复核订单
</u-button>
</view>
</view>
</view>
<view class="safe-area-bottom"></view>
</scroll-view>
<u-popup :show="showPrintPopup" mode="bottom" :closeable="true" border-radius="20" @close="showPrintPopup = false">
<view class="print-popup">
<view class="print-popup-title">打印设置</view>
<view class="print-row">
<text class="print-label">打印台</text>
<text class="print-value">{{ printStationName }}</text>
</view>
<view class="print-row print-row--action">
<text class="print-label">打印</text>
<u-button
type="primary"
size="mini"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff' }"
@click="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>
</view>
</template>
<script>
export default {
data() {
return {
title: '拣货详情(未复核)',
grabCount: 0,
keyword: '',
onlyMine: false,
currentUserId: '',
showPrintPopup: false,
printStationName: '默认打印台',
printMessage: '',
pendingPrintCount: 0,
orderList: []
};
},
computed: {
displayOrderList() {
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;
}
},
onLoad(options) {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
this.currentUserId = String(this.$store?.getters?.user?.id || this.$store?.getters?.user?.user_id || '');
const hasGrabCountParam = options && Object.prototype.hasOwnProperty.call(options, 'grabCount');
const parsedGrabCount = Number(options?.grabCount || 0);
this.grabCount = hasGrabCountParam
? Math.max(0, parsedGrabCount)
: 5;
this.orderList = this.buildMockOrderList(this.grabCount);
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
},
methods: {
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[ScatterPickingDetail] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[ScatterPickingDetail] broadcast/${action} 调用异常:`, error);
}
},
normalizeKeyword(value) {
return String(value || '').replace(/\s+/g, '');
},
normalizeScanResult(scanResult) {
if (!scanResult) {
return '';
}
if (typeof scanResult === 'string') {
return this.normalizeKeyword(scanResult);
}
if (typeof scanResult.result === 'string') {
return this.normalizeKeyword(scanResult.result);
}
if (Array.isArray(scanResult.result)) {
const firstResult = scanResult.result.find(item => item);
if (typeof firstResult === 'string') {
return this.normalizeKeyword(firstResult);
}
if (firstResult && typeof firstResult.data === 'string') {
return this.normalizeKeyword(firstResult.data);
}
}
if (typeof scanResult.data === 'string') {
return this.normalizeKeyword(scanResult.data);
}
return '';
},
handleBroadcastResult(result) {
const scanText = this.normalizeScanResult(result);
if (!scanText) {
return;
}
this.keyword = scanText;
this.handleSearch();
},
handleSearch() {
this.keyword = this.normalizeKeyword(this.keyword);
this.requestScanOrder(this.keyword);
},
handleCameraScan() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
success: (res) => {
const scanResult = this.normalizeScanResult(res);
if (!scanResult) {
uni.showToast({
title: '未识别到有效条码',
icon: 'none'
});
return;
}
this.keyword = scanResult;
this.handleSearch();
},
fail: (error) => {
const errMsg = String(error?.errMsg || '').toLowerCase();
if (errMsg.includes('cancel')) {
return;
}
uni.showToast({
title: '扫码失败,请重试',
icon: 'none'
});
}
});
},
clearSearch() {
this.keyword = '';
},
buildScanOrderParams(keyword) {
const value = this.normalizeKeyword(keyword);
return {
keyword: value,
value,
waybill_no: value,
waybillCode: value,
waybill_code: value,
cart_code: value,
cartCode: value
};
},
extractScanOrderPayload(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 {};
},
normalizeScanOrderResult(payload) {
const order = payload?.order && typeof payload.order === 'object' ? payload.order : {};
const orderId = Number(payload?.order_id || order?.order_id || order?.id || 0);
const waybillNo = String(
payload?.waybill_no
|| order?.waybill_no
|| order?.waybillCode
|| order?.waybill_code
|| ''
).trim();
const matchType = String(payload?.match_type || '').trim();
const cartMatchView = payload?.cart_match_view && typeof payload.cart_match_view === 'object'
? payload.cart_match_view
: null;
return {
matchType,
cartMatchView,
orderId,
waybillNo,
order,
items: Array.isArray(payload?.items) ? payload.items : [],
expresses: Array.isArray(payload?.expresses) ? payload.expresses : [],
logs: Array.isArray(payload?.logs) ? payload.logs : []
};
},
handleScanOrderSuccess(result) {
const order = result?.order || {};
const orderId = Number(result?.orderId || 0);
if (!orderId) {
uni.showToast({
title: '未查询到订单',
icon: 'none'
});
return;
}
if (result?.matchType === 'cart') {
uni.showToast({
title: '车号命中,已定位订单',
icon: 'none'
});
}
const params = [
`recordId=${encodeURIComponent(String(orderId))}`,
`orderId=${encodeURIComponent(String(orderId))}`,
`waveNo=${encodeURIComponent(String(order?.wave_no || order?.waveNo || '--'))}`,
`pickerName=${encodeURIComponent(String(order?.picker_name || order?.pickerName || '--'))}`,
`cartNo=${encodeURIComponent(String(order?.cart_code || order?.cartCode || order?.cart_no || order?.cartNo || '--'))}`,
`status=${encodeURIComponent(String(order?.status || 'pending'))}`,
`unreviewedCount=${encodeURIComponent(String(order?.unreviewed_count || order?.unreviewedCount || 0))}`,
`waybillNo=${encodeURIComponent(String(result?.waybillNo || '--'))}`,
`matchType=${encodeURIComponent(String(result?.matchType || ''))}`
];
this.$tools.routerTo(`/pages/work/order/scatter-pick-goods-detail?${params.join('&')}`);
},
async requestScanOrder(keyword) {
const normalizedKeyword = this.normalizeKeyword(keyword);
if (!normalizedKeyword) {
uni.showToast({
title: '请输入快递单号或车号',
icon: 'none'
});
return;
}
uni.showLoading({
title: '查询订单中...'
});
try {
const response = await this.$http('order.recheckOrder.scanOrder', this.buildScanOrderParams(normalizedKeyword));
const payload = this.extractScanOrderPayload(response);
const result = this.normalizeScanOrderResult(payload);
this.handleScanOrderSuccess(result);
} catch (error) {
const message = String(error?.message || error?.msg || error?.errMsg || '').trim();
uni.showToast({
title: message || '订单查询失败',
icon: 'none'
});
} finally {
uni.hideLoading();
}
},
toggleOnlyMine() {
this.onlyMine = !this.onlyMine;
},
buildMockOrderList(count) {
const listCount = Math.max(0, Number(count || 0));
return Array.from({ length: listCount }).map((_, index) => {
const waveNo = `W${new Date().getFullYear()}${String(index + 1).padStart(4, '0')}`;
const orderNo = `SD${Date.now().toString().slice(-6)}${String(index + 1).padStart(2, '0')}`;
const assigneeId = this.currentUserId || `mock_user_${(index % 2) + 1}`;
const isMine = index % 2 === 0;
const pickerName = isMine ? '我' : `拣货员${(index % 3) + 1}`;
return {
id: `${orderNo}-${index + 1}`,
waveNo,
unreviewedCount: (index % 4) + 1,
pickerName,
cartNo: `A${String((index % 12) + 1).padStart(2, '0')}`,
orderNo,
waybillCode: `WB${String(index + 1).padStart(8, '0')}`,
quantity: (index % 5) + 1,
status: 'pending',
assigneeId,
isMine
};
});
},
getStatusText(status) {
const map = {
pending: '待拣货',
picking: '拣货中',
done: '已完成'
};
return map[status] || '待拣货';
},
goPickGoodsDetail(item) {
if (!item) {
return;
}
const params = [
`recordId=${encodeURIComponent(String(item.id || ''))}`,
`waveNo=${encodeURIComponent(String(item.waveNo || '--'))}`,
`pickerName=${encodeURIComponent(String(item.pickerName || '--'))}`,
`cartNo=${encodeURIComponent(String(item.cartNo || '--'))}`,
`status=${encodeURIComponent(String(item.status || 'pending'))}`,
`unreviewedCount=${encodeURIComponent(String(item.unreviewedCount || 0))}`
];
this.$tools.routerTo(`/pages/work/order/scatter-pick-goods-detail?${params.join('&')}`);
},
handlePrintAllUnreviewed() {
const targetList = this.displayOrderList.filter(item => Number(item.unreviewedCount || 0) > 0);
if (!targetList.length) {
uni.showToast({
title: '暂无未复核订单可打印',
icon: 'none'
});
return;
}
this.pendingPrintCount = targetList.length;
this.printMessage = `待打印未复核订单 ${targetList.length} 条`;
this.showPrintPopup = true;
},
handleConfirmPrint() {
if (this.pendingPrintCount <= 0) {
this.printMessage = '暂无可打印订单';
return;
}
this.printMessage = `打印已发送,未复核订单 ${this.pendingPrintCount} 条`;
uni.showToast({
title: `已发起打印${this.pendingPrintCount}条`,
icon: 'none'
});
}
}
};
</script>
<style lang="scss" scoped>
.scatter-picking-detail-page {
min-height: 100vh;
background: #f8f9fa;
}
::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 {
color: #ffffff;
background: #1f67e6;
}
.detail-scroll {
height: calc(100vh - 120rpx - 112rpx - env(safe-area-inset-bottom));
padding: 20rpx 24rpx 0;
box-sizing: border-box;
}
.search-filter {
background: #ffffff;
padding: 20rpx 24rpx;
border: 1rpx solid #f0f0f0;
border-top: none;
border-radius: 0;
}
.search-box {
position: relative;
}
.search-box-inner {
position: relative;
}
::v-deep .search-box-inner .u-search {
width: 100%;
}
::v-deep .search-box-inner .u-search__content {
padding-right: 200rpx;
}
::v-deep .search-box-inner .u-search__content__close {
margin-right: 12rpx;
}
.search-actions {
position: absolute;
right: 24rpx;
top: 50%;
transform: translateY(-50%);
height: 68rpx;
display: flex;
align-items: center;
}
.scan-btn {
height: 68rpx;
padding: 0 8rpx 0 4rpx;
display: flex;
align-items: center;
justify-content: center;
&:active {
opacity: 0.88;
}
}
.search-divider {
width: 1rpx;
height: 28rpx;
background: #dcdfe6;
margin: 0 16rpx 0 10rpx;
}
.search-btn {
height: 68rpx;
padding: 0 8rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
&:active {
opacity: 0.88;
}
}
.search-btn__text {
font-size: 30rpx;
color: #2979ff;
font-weight: 500;
line-height: 1;
}
.record-list {
display: flex;
flex-direction: column;
gap: 14rpx;
}
.record-item {
background: #ffffff;
border-radius: 12rpx;
padding: 18rpx;
border: 1rpx solid #ebeef5;
}
.record-item:active {
opacity: 0.75;
}
.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;
flex-wrap: nowrap;
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;
word-break: keep-all;
overflow-wrap: normal;
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;
}
.safe-area-bottom {
height: calc(30rpx + env(safe-area-inset-bottom));
}
.print-popup {
padding: 24rpx;
}
.print-popup-title {
font-size: 32rpx;
font-weight: 600;
color: #303133;
margin-bottom: 18rpx;
}
.print-row {
display: flex;
align-items: flex-start;
padding: 16rpx 0;
border-bottom: 1rpx solid #f2f3f5;
}
.print-row--action {
align-items: center;
}
.print-row--message {
border-bottom: none;
}
.print-label {
width: 130rpx;
font-size: 28rpx;
line-height: 40rpx;
color: #909399;
}
.print-value {
flex: 1;
font-size: 28rpx;
line-height: 40rpx;
color: #303133;
}
.print-message {
flex: 1;
font-size: 28rpx;
line-height: 40rpx;
color: #303133;
}
</style>