655 lines
16 KiB
Vue
655 lines
16 KiB
Vue
<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>
|
||
<view class="mode-panel">
|
||
<text class="mode-title">拣货模式</text>
|
||
<view class="mode-switch-group">
|
||
<view
|
||
class="mode-switch-btn"
|
||
:class="{ 'mode-switch-btn--active': pickMode === 'F' }"
|
||
@click="switchPickMode('F')"
|
||
>
|
||
F拣货(先拣后分)
|
||
</view>
|
||
<view
|
||
class="mode-switch-btn"
|
||
:class="{ 'mode-switch-btn--active': pickMode === 'E' }"
|
||
@click="switchPickMode('E')"
|
||
>
|
||
E拣货(边拣边分)
|
||
</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>
|
||
|
||
<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-header">
|
||
<text class="order-no">{{ item.orderNo }}</text>
|
||
<text class="order-status" :class="`order-status--${item.status}`">{{ getStatusText(item.status) }}</text>
|
||
</view>
|
||
<view class="item-row"><text class="label">客户:</text><text class="value">{{ item.customerName || '--' }}</text></view>
|
||
<view class="item-row"><text class="label">波次:</text><text class="value">{{ item.waveNo || '--' }}</text></view>
|
||
<view class="item-row"><text class="label">SKU数:</text><text class="value">{{ item.skuCount }}</text></view>
|
||
<view class="item-row"><text class="label">应拣数量:</text><text class="value">{{ item.needQty }}</text></view>
|
||
<view class="item-row"><text class="label">已拣数量:</text><text class="value">{{ item.pickedQty }}</text></view>
|
||
<view class="item-footer">
|
||
<text class="create-time">{{ item.createTime }}</text>
|
||
<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: '',
|
||
pickMode: 'F',
|
||
fullDisplay: true,
|
||
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.mode) {
|
||
const mode = String(options.mode || '').toUpperCase();
|
||
if (mode === 'F' || mode === 'E') {
|
||
this.pickMode = mode;
|
||
}
|
||
}
|
||
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'
|
||
});
|
||
},
|
||
switchPickMode(mode) {
|
||
if (mode !== 'F' && mode !== 'E') {
|
||
return;
|
||
}
|
||
this.pickMode = mode;
|
||
},
|
||
getApiErrorMessage(error, fallback = '请求失败') {
|
||
const message = error?.message || error?.msg || error?.errMsg || error?.data?.message;
|
||
return String(message || fallback);
|
||
},
|
||
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 inspectionStatus = source.inspection_status || source.pick_status || source.status;
|
||
return {
|
||
id: source.id || source.order_id || source.pick_id || source.waybill_code || `pick_${index}`,
|
||
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 || source.wave_code || source.batch_no || '--',
|
||
skuCount: Number(source.sku_count || source.item_count || source.goods_count || source.detail_count || 0),
|
||
needQty: Number(source.need_qty || source.pick_qty || source.total_qty || source.total_quantity || 0),
|
||
pickedQty: Number(source.picked_qty || source.done_qty || source.finish_qty || source.finished_qty || source.finished_qty || 0),
|
||
status: this.normalizeStatus(inspectionStatus),
|
||
createTime: source.created_at || source.create_time || source.createdAt || '--'
|
||
};
|
||
},
|
||
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.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)
|
||
});
|
||
const orderList = this.extractOrderList(response)
|
||
.map((item, index) => this.normalizeOrderItem(item, index));
|
||
this.fullList = orderList;
|
||
this.applyFilteredList(resetPage);
|
||
} catch (error) {
|
||
this.fullList = [];
|
||
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] || '未知状态';
|
||
},
|
||
goPicking(item) {
|
||
const params = [
|
||
`id=${encodeURIComponent(String(item.id || ''))}`,
|
||
`orderNo=${encodeURIComponent(String(item.orderNo || ''))}`,
|
||
`customerName=${encodeURIComponent(String(item.customerName || ''))}`,
|
||
`waveNo=${encodeURIComponent(String(item.waveNo || ''))}`,
|
||
`status=${encodeURIComponent(String(item.status || 'pending'))}`,
|
||
`needQty=${encodeURIComponent(String(item.needQty || 0))}`,
|
||
`pickedQty=${encodeURIComponent(String(item.pickedQty || 0))}`,
|
||
`mode=${encodeURIComponent(String(this.pickMode || 'F'))}`
|
||
];
|
||
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);
|
||
},
|
||
getPickModeText() {
|
||
return this.pickMode === 'E' ? 'E拣货(边拣边分)' : 'F拣货(先拣后分)';
|
||
}
|
||
}
|
||
}
|
||
</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;
|
||
}
|
||
|
||
.mode-panel {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 0 24rpx 16rpx;
|
||
}
|
||
|
||
.mode-title {
|
||
font-size: 24rpx;
|
||
color: #606266;
|
||
padding-right: 16rpx;
|
||
}
|
||
|
||
.mode-switch-group {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
background: #f6f7fb;
|
||
border-radius: 12rpx;
|
||
padding: 6rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.mode-switch-btn {
|
||
flex: 1;
|
||
height: 56rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 23rpx;
|
||
color: #606266;
|
||
border-radius: 10rpx;
|
||
}
|
||
|
||
.mode-switch-btn--active {
|
||
background: #fff;
|
||
color: #2979ff;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
|
||
.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> |