WMS_PDA/pages/work/order/picking.vue

748 lines
21 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="order-picking-page">
<view class="normar_container">
<view class="page-header">
<page-nav :title="title"></page-nav>
<view class="search-panel">
<view class="search-input-wrap">
<u-search
v-model="keyword"
placeholder="请输入快递号/运单号"
:bg-color="'#f5f5f5'"
shape="round"
:show-action="false"
@search="handleSearch"
@clear="handleSearch"
></u-search>
<view class="search-actions">
<view class="scan-btn" @click="handleScanTrigger">
<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>
<scroll-view class="status-tabs" scroll-x>
<view
v-for="item in statusTabs"
:key="item.value"
class="status-tab"
:class="{ 'status-tab--active': status === item.value }"
@click="switchStatus(item.value)"
>
{{ item.label }}
</view>
</scroll-view>
<view class="summary-panel">
<view class="summary-row"><text class="summary-label">波次号:</text><text class="summary-value">{{ headerSummary.waveNo || '--' }}</text></view>
<view class="summary-row"><text class="summary-label">总商品数量:</text><text class="summary-value">{{ headerSummary.quantityTotal }}</text></view>
<view class="summary-inline-row">
<view class="summary-inline-item"><text class="summary-label">待复核:</text><text class="summary-value">{{ headerSummary.pendingReviewCount }}</text></view>
<view class="summary-inline-item"><text class="summary-label">已复核:</text><text class="summary-value">{{ headerSummary.reviewedCount }}</text></view>
</view>
</view>
</view>
<scroll-view class="list-content" scroll-y>
<view v-if="displayList.length === 0" class="empty-state">
<u-icon name="list" size="88" color="#c0c4cc"></u-icon>
<text class="empty-text">暂无订单</text>
</view>
<view v-else class="list-wrap">
<view class="order-item" v-for="item in displayList" :key="item.id">
<view class="item-row item-row--with-status"><text class="label">货主:</text><text class="value">{{ item.ownerName || '--' }}</text><text class="order-status" :class="`order-status--${normalizeStatus(item.pickingStatus)}`">{{ getPickingStatusText(item.pickingStatus) }}</text></view>
<view class="item-row"><text class="label">库位:</text><text class="value">{{ item.spaceName || '--' }}</text></view>
<view class="item-row"><text class="label">库位状态:</text><text class="value">{{ getSpaceStatusText(item.spaceStatus) }}</text></view>
<view class="item-row"><text class="label">商品数量:</text><text class="value">{{ item.quantity }}</text></view>
<view class="item-row"><text class="label">复核状态:</text><text class="value">{{ getReviewStatusText(item.reviewed, item.inspectionStatus) }}</text></view>
<view class="item-footer">
<view></view>
<u-button type="primary" size="mini" :customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff' }" @click="goPicking(item)">进入拣货</u-button>
</view>
</view>
</view>
<view class="safe-area-bottom"></view>
</scroll-view>
<pagination class="order-pagination" :pageNum.sync="currentPage" :pageSize="pageSize" :total="totalItems" :showTotal="true"
:prevText="'上一页'" :nextText="'下一页'" :showFirstLast="true" :firstText="'首页'" :lastText="'末页'"
@change="handlePageChange" />
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: '订单拣货',
keyword: '',
fullDisplay: true,
headerSummary: {
waveNo: '--',
pendingReviewCount: 0,
reviewedCount: 0,
quantityTotal: 0
},
loading: false,
status: 'all',
pageSize: 10,
currentPage: 1,
totalItems: 0,
onOrderPickingUpdated: null,
fullList: [],
filteredList: [],
displayList: []
}
},
computed: {
statusTabs() {
return [
{ label: '全部', value: 'all' },
{ label: '待拣货', value: 'pending' },
{ label: '拣货中', value: 'picking' },
{ label: '已完成', value: 'done' }
]
}
},
onLoad(options) {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
this.onOrderPickingUpdated = payload => {
this.applyOrderUpdate(payload);
};
uni.$on('order:picking:updated', this.onOrderPickingUpdated);
if (options && options.status) {
this.status = options.status;
}
if (options && options.waybill_code) {
this.keyword = String(options.waybill_code || '').trim();
this.handleSearch({
silentTip: true
});
}
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
if (this.onOrderPickingUpdated) {
uni.$off('order:picking:updated', this.onOrderPickingUpdated);
this.onOrderPickingUpdated = null;
}
},
methods: {
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[OrderPicking] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[OrderPicking] 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 scanResult = this.normalizeScanResult(result);
if (!scanResult) {
return;
}
this.keyword = scanResult;
this.handleSearch();
},
handleScanTrigger() {
this.safeDispatchBroadcast('resume');
uni.showToast({
title: '请使用扫描枪扫码',
icon: 'none'
});
},
getApiErrorMessage(error, fallback = '请求失败') {
const message = error?.message || error?.msg || error?.errMsg || error?.data?.message;
return String(message || fallback);
},
resetHeaderSummary() {
this.headerSummary = {
waveNo: '--',
pendingReviewCount: 0,
reviewedCount: 0,
quantityTotal: 0
};
},
extractHeaderSummary(response) {
const dataSource = (response?.data?.data && typeof response.data.data === 'object' && !Array.isArray(response.data.data))
? response.data.data
: ((response?.data && typeof response.data === 'object' && !Array.isArray(response.data))
? response.data
: ((response?.result && typeof response.result === 'object' && !Array.isArray(response.result))
? response.result
: ((response && typeof response === 'object' && !Array.isArray(response)) ? response : null)));
if (!dataSource) {
this.resetHeaderSummary();
return;
}
const summary = dataSource.summary && typeof dataSource.summary === 'object' && !Array.isArray(dataSource.summary)
? dataSource.summary
: {};
const toNumber = value => {
const num = Number(value);
return Number.isNaN(num) ? 0 : num;
};
this.headerSummary = {
waveNo: dataSource.wave_no || dataSource.waveNo || summary.wave_no || summary.waveNo || '--',
pendingReviewCount: toNumber(summary.pending_review_count ?? summary.pendingReviewCount ?? dataSource.pending_review_count ?? dataSource.pendingReviewCount),
reviewedCount: toNumber(summary.reviewed_count ?? summary.reviewedCount ?? dataSource.reviewed_count ?? dataSource.reviewedCount),
quantityTotal: toNumber(summary.quantity_total ?? summary.quantityTotal ?? dataSource.quantity_total ?? dataSource.quantityTotal)
};
},
normalizeStatus(value) {
const text = String(value || '').toLowerCase();
if (!text) {
return 'pending';
}
if (['fin', 'finished', 'done', 'completed', 'complete', 'success'].includes(text)) {
return 'done';
}
if (['picking', 'pick', 'doing', 'processing', 'progress', 'part'].includes(text)) {
return 'picking';
}
return 'pending';
},
extractOrderList(response) {
if (Array.isArray(response)) {
return response;
}
const candidates = [
response?.data,
response?.data?.data,
response?.data?.list,
response?.data?.rows,
response?.data?.items,
response?.data?.result,
response?.list,
response?.rows,
response?.items,
response?.result
];
for (let i = 0; i < candidates.length; i += 1) {
if (Array.isArray(candidates[i])) {
return candidates[i];
}
}
return [];
},
normalizeOrderItem(item, index) {
const source = item && typeof item === 'object' ? item : {};
const summary = source.summary && typeof source.summary === 'object' ? source.summary : {};
const locationSpace = source.location_space && typeof source.location_space === 'object' ? source.location_space : {};
const storeWarehouse = source.store_warehouse && typeof source.store_warehouse === 'object' ? source.store_warehouse : {};
const detailList = Array.isArray(source.details)
? source.details
: (Array.isArray(summary.details) ? summary.details : []);
const pickingStatus = source.picking_status || source.pick_status || source.status || summary.picking_status;
const inspectionStatus = source.inspection_status || summary.inspection_status;
return {
id: source.id || source.order_id || source.pick_id || source.waybill_code || `pick_${index}`,
orderId: Number(source.order_id || source.orderId || 0),
orderItemId: Number(source.order_item_id || source.orderItemId || 0),
orderNo: source.order_no || source.order_code || source.waybill_code || source.waybillCode || '--',
customerName: source.customer_name || source.consignee || source.receiver_name || '--',
waveNo: source.wave_no || summary.wave_no || source.wave_code || source.batch_no || '--',
ownerName: storeWarehouse.store_remask || storeWarehouse.store_name || source.owner_name || source.ownerName || '--',
quantity: Number(source.quantity || summary.quantity || source.need_qty || summary.need_qty || 0),
spaceName: source.space_name || locationSpace.space_code || locationSpace.custom_name || summary.space_name || '--',
spaceStatus: locationSpace.space_status || source.space_status || '',
pickingStatus: pickingStatus || 'pending',
inspectionStatus: inspectionStatus || '',
reviewed: Boolean(source.reviewed),
skuCount: Number(summary.sku_count || source.sku_count || summary.item_count || source.item_count || source.goods_count || source.detail_count || 0),
needQty: Number(summary.need_qty || source.need_qty || summary.pick_qty || source.pick_qty || summary.total_qty || source.total_qty || source.total_quantity || 0),
pickedQty: Number(summary.picked_qty || source.picked_qty || summary.done_qty || source.done_qty || source.finish_qty || source.finished_qty || 0),
status: this.normalizeStatus(pickingStatus),
createTime: source.created_at || source.create_time || source.createdAt || '--',
detailList
};
},
applyFilteredList(resetPage = true) {
this.filteredList = this.fullList.filter(item => this.status === 'all' || item.status === this.status);
this.totalItems = this.filteredList.length;
if (resetPage) {
this.currentPage = 1;
}
this.refreshDisplayList();
},
async handleSearch(options = {}) {
const resetPage = options.resetPage !== false;
const silentTip = options.silentTip === true;
const waybillCode = String(this.keyword || '').trim();
if (!waybillCode) {
this.fullList = [];
this.resetHeaderSummary();
this.applyFilteredList(true);
if (!silentTip) {
uni.showToast({
title: '请输入快递号/运单号',
icon: 'none'
});
}
return;
}
this.loading = true;
try {
const response = await this.$http('pick.query', {
waybill_code: waybillCode,
full_display: Boolean(this.fullDisplay)
});
this.extractHeaderSummary(response);
const orderList = this.extractOrderList(response)
.map((item, index) => this.normalizeOrderItem(item, index));
this.fullList = orderList;
this.applyFilteredList(resetPage);
} catch (error) {
this.fullList = [];
this.resetHeaderSummary();
this.applyFilteredList(true);
uni.showToast({
title: this.getApiErrorMessage(error, '查询失败'),
icon: 'none'
});
} finally {
this.loading = false;
}
},
refreshDisplayList() {
const source = Array.isArray(this.filteredList) ? this.filteredList : [];
const totalPage = Math.max(Math.ceil(source.length / this.pageSize), 1);
if (this.currentPage > totalPage) {
this.currentPage = totalPage;
}
const start = (this.currentPage - 1) * this.pageSize;
this.displayList = source.slice(start, start + this.pageSize);
},
handlePageChange(page) {
this.currentPage = Number(page || 1);
this.refreshDisplayList();
},
switchStatus(nextStatus) {
this.status = nextStatus;
this.applyFilteredList(true);
},
getStatusText(status) {
const map = {
pending: '待拣货',
picking: '拣货中',
done: '已完成'
};
return map[status] || '未知状态';
},
getPickingStatusText(status) {
return this.getStatusText(this.normalizeStatus(status));
},
getReviewStatusText(reviewed, inspectionStatus) {
if (reviewed === true) {
return '已复核';
}
const text = String(inspectionStatus || '').toLowerCase();
if (!text || ['pending', 'padding', 'wait', 'waiting', 'todo'].includes(text)) {
return '待复核';
}
if (['reviewed', 'done', 'completed', 'finish', 'finished', 'success'].includes(text)) {
return '已复核';
}
return text;
},
getSpaceStatusText(status) {
const text = String(status || '').toUpperCase();
const map = {
AVAILABLE: '可用',
DISABLED: '禁用',
LOCKED: '锁定'
};
return map[text] || (status || '--');
},
goPicking(item) {
const orderId = Number(item?.orderId || 0);
const orderItemId = Number(item?.orderItemId || 0);
if (!orderId || !orderItemId) {
uni.showToast({
title: '缺少订单参数',
icon: 'none'
});
return;
}
const params = [
`id=${encodeURIComponent(String(item.id || ''))}`,
`orderId=${encodeURIComponent(String(orderId))}`,
`orderItemId=${encodeURIComponent(String(orderItemId))}`,
`orderNo=${encodeURIComponent(String(item.orderNo || ''))}`,
`customerName=${encodeURIComponent(String(item.customerName || ''))}`,
`waveNo=${encodeURIComponent(String(item.waveNo || ''))}`,
`spaceName=${encodeURIComponent(String(item.spaceName || ''))}`,
`status=${encodeURIComponent(String(item.status || 'pending'))}`,
`needQty=${encodeURIComponent(String(item.needQty || 0))}`,
`pickedQty=${encodeURIComponent(String(item.pickedQty || 0))}`
];
this.$tools.routerTo(`/pages/work/order/detail?${params.join('&')}`);
},
applyOrderUpdate(payload) {
if (!payload || typeof payload !== 'object') {
return;
}
const targetId = String(payload.id || '');
const targetOrderNo = String(payload.orderNo || '');
const nextStatus = String(payload.status || '').trim();
const nextPickedQty = Number(payload.pickedQty);
const index = this.fullList.findIndex(item => {
if (!item || typeof item !== 'object') {
return false;
}
const matchId = targetId && String(item.id || '') === targetId;
const matchOrderNo = targetOrderNo && String(item.orderNo || '') === targetOrderNo;
return matchId || matchOrderNo;
});
if (index < 0) {
return;
}
const source = this.fullList[index];
const merged = {
...source
};
if (nextStatus) {
merged.status = nextStatus;
}
if (!Number.isNaN(nextPickedQty)) {
merged.pickedQty = Math.max(0, Math.min(nextPickedQty, Number(merged.needQty || 0)));
}
this.$set(this.fullList, index, merged);
this.applyFilteredList(false);
},
}
}
</script>
<style lang="scss" scoped>
.order-picking-page {
min-height: 100vh;
background: #f8f9fa;
display: flex;
flex-direction: column;
}
::v-deep .normar_container {
min-height: 100vh;
display: flex;
flex-direction: column;
}
.page-header {
position: sticky;
top: 0;
z-index: 10;
background: #fff;
border-bottom: 1rpx solid #f2f2f2;
}
.search-panel {
padding: 16rpx 24rpx;
}
.search-input-wrap {
display: flex;
align-items: center;
background: #fff;
border-radius: 26rpx;
padding: 8rpx 12rpx;
border: 1rpx solid #dbe7ff;
}
.search-actions {
display: flex;
align-items: center;
margin-left: 12rpx;
}
.scan-btn {
width: 64rpx;
height: 64rpx;
display: flex;
align-items: center;
justify-content: center;
}
.search-divider {
width: 1rpx;
height: 34rpx;
background: #e6eaf2;
}
.search-btn {
padding: 0 20rpx;
height: 64rpx;
display: flex;
align-items: center;
justify-content: center;
}
.search-btn__text {
font-size: 26rpx;
color: #2979ff;
font-weight: 600;
}
.status-tabs {
white-space: nowrap;
padding: 0 24rpx 16rpx;
}
.status-tab {
display: inline-flex;
align-items: center;
justify-content: center;
height: 52rpx;
padding: 0 24rpx;
margin-right: 12rpx;
font-size: 24rpx;
color: #666;
background: #f6f7fb;
border-radius: 26rpx;
}
.status-tab--active {
color: #2979ff;
background: #edf4ff;
}
.summary-panel {
margin: 0 24rpx 16rpx;
padding: 16rpx 20rpx;
background: #f8fbff;
border: 1rpx solid #e4efff;
border-radius: 12rpx;
}
.summary-row {
display: flex;
align-items: center;
font-size: 24rpx;
line-height: 38rpx;
}
.summary-label {
width: 180rpx;
font-size: 24rpx;
line-height: 38rpx;
color: #909399;
}
.summary-value {
flex: 1;
font-size: 24rpx;
line-height: 38rpx;
color: #303133;
font-weight: 500;
}
.summary-inline-row {
display: flex;
align-items: center;
justify-content: space-between;
}
.summary-inline-item {
flex: 1;
display: flex;
align-items: center;
}
.summary-inline-item + .summary-inline-item {
margin-left: 16rpx;
}
.summary-inline-item .summary-label {
width: 132rpx;
}
.summary-inline-item .summary-value {
flex: 0;
min-width: 40rpx;
}
.list-content {
height: 100rpx;
flex: 1;
padding: 20rpx 24rpx 0;
box-sizing: border-box;
}
.order-item {
background: #fff;
border-radius: 14rpx;
padding: 20rpx;
margin-bottom: 16rpx;
}
.item-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12rpx;
}
.item-header--status-only {
justify-content: flex-end;
}
.item-row--with-status .order-status {
margin-left: 12rpx;
}
.order-no {
font-size: 30rpx;
font-weight: 600;
color: #303133;
}
.order-status {
font-size: 22rpx;
padding: 6rpx 14rpx;
border-radius: 18rpx;
}
.order-status--pending {
background: #fff4e8;
color: #fa8c16;
}
.order-status--picking {
background: #edf4ff;
color: #2979ff;
}
.order-status--done {
background: #eafaf0;
color: #19be6b;
}
.item-row {
display: flex;
align-items: center;
font-size: 24rpx;
line-height: 38rpx;
}
.label {
width: 128rpx;
color: #909399;
}
.value {
flex: 1;
color: #303133;
}
.item-footer {
margin-top: 16rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.create-time {
font-size: 22rpx;
color: #999;
}
.empty-state {
min-height: 540rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.empty-text {
margin-top: 12rpx;
font-size: 26rpx;
color: #999;
}
.safe-area-bottom {
height: calc(20rpx + env(safe-area-inset-bottom));
}
.order-pagination {
background: #fff;
position: relative;
}
::v-deep .order-pagination .page-indicator {
padding: 16rpx 0;
}
.order-pagination::after {
content: '';
display: block;
height: env(safe-area-inset-bottom);
}
</style>