WMS_PDA/pages/work/order/picking.vue
2026-05-10 03:58:36 +08:00

828 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">
<page-nav :title="title">
<template #right>
<view class="nav-complete-btn nav-complete-btn--disabled">完成收货</view>
</template>
</page-nav>
<view v-if="!taskId" class="empty-wrap">
<view class="empty-card">
<u-icon name="scan" size="72rpx" color="#2979ff"></u-icon>
<text class="empty-title">开始拣货</text>
<text class="empty-desc">扫描快递号或拣货单开始拣货</text>
</view>
</view>
<view v-else class="content-wrap">
<view class="search-card">
<view class="search-input-wrap">
<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 v-if="loadingTaskDetail" class="loading-wrap">
<text class="loading-text">任务详情加载中...</text>
</view>
<template v-else>
<view class="top-detail-panel">
<view v-if="!selectedPickItem" class="list-empty">暂无拣货数据</view>
<view v-else class="pick-card">
<view class="detail-main">
<view class="detail-main-left">
<u-image
v-if="selectedItemImageUrl"
:src="selectedItemImageUrl"
width="120rpx"
height="120rpx"
mode="aspectFill"
@click="previewSelectedItemImage"
></u-image>
<view v-else class="pick-image-empty">{{ selectedItemImageLoading ? '图片加载中...' : '暂无商品图片' }}</view>
</view>
<view class="detail-main-right">
<view class="pick-card__head">
<text class="pick-name">{{ selectedPickItem.itemName || '--' }}</text>
</view>
<view class="pick-row"><text class="pick-label">商品条码:</text><text class="pick-value">{{ selectedItemBarcodeLoading ? '条码加载中...' : (selectedItemBarcode || '--') }}</text></view>
<view class="pick-row"><text class="pick-label">库位:</text><text class="pick-value pick-value--highlight">{{ selectedPickItem.spaceName || '--' }}</text></view>
<view class="pick-row"><text class="pick-label">应拣总数:</text><text class="pick-value">{{ selectedPickItem.totalQty }}</text></view>
</view>
</view>
<view class="alloc-panel">
<view class="pick-row pick-row--top"><text class="pick-label">分配篮号:</text></view>
<scroll-view class="alloc-scroll" scroll-y>
<view class="alloc-wrap" v-if="selectedPickItem.boxAllocations && selectedPickItem.boxAllocations.length">
<view class="alloc-item" v-for="alloc in selectedPickItem.boxAllocations" :key="`${selectedPickItem.itemCode}-${alloc.boxId}`">
<text class="alloc-text">{{ alloc.boxNo }}号篮: {{ alloc.allocatedQty }}</text>
</view>
</view>
<view v-else class="alloc-empty">暂无分配</view>
<view class="alloc-safe-bottom"></view>
</scroll-view>
</view>
</view>
</view>
<scroll-view class="bottom-grid-panel" scroll-y>
<view v-if="filteredPickItems.length === 0" class="list-empty">暂无拣货数据</view>
<view v-else class="index-grid">
<view
v-for="(item, index) in filteredPickItems"
:key="`${item.spaceId}-${item.itemCode}-${index}`"
class="index-cell"
:class="{ 'index-cell--active': selectedIndex === index }"
@click="selectPickItem(index)"
>
<text class="index-text">{{ index + 1 }}</text>
</view>
</view>
<view class="safe-bottom"></view>
</scroll-view>
</template>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: '订单拣货',
taskId: '',
keyword: '',
selectedIndex: 0,
loadingTaskDetail: false,
selectedItemImageLoading: false,
selectedItemImageUrl: '',
selectedItemImageUrls: [],
itemImageCache: {},
itemImageListCache: {},
selectedItemBarcodeLoading: false,
selectedItemBarcode: '',
itemBarcodeCache: {},
taskInfo: {
taskId: '',
taskNo: '',
batchNo: '',
status: 0
},
boxList: [],
pickingSummary: {
totalLines: 0,
totalQty: 0,
distinctSpaces: 0,
distinctItems: 0
},
pickingView: {
modeCode: '',
modeName: '--',
items: []
}
};
},
computed: {
modeName() {
return this.pickingView.modeName || '--';
},
filteredPickItems() {
const list = Array.isArray(this.pickingView.items) ? this.pickingView.items : [];
const key = String(this.keyword || '').trim().toLowerCase();
if (!key) {
return list;
}
return list.filter(item => {
const fields = [
item.itemCode,
item.itemName,
item.spaceName,
item.spaceBarcode
]
.map(value => String(value || '').toLowerCase());
const allocText = (Array.isArray(item.boxAllocations) ? item.boxAllocations : [])
.map(alloc => `${alloc.boxNo}`)
.join(',')
.toLowerCase();
return fields.some(text => text.includes(key)) || allocText.includes(key);
});
},
selectedPickItem() {
if (!this.filteredPickItems.length) {
return null;
}
return this.filteredPickItems[this.selectedIndex] || this.filteredPickItems[0];
}
},
watch: {
filteredPickItems(newList) {
if (!Array.isArray(newList) || newList.length === 0) {
this.selectedIndex = 0;
return;
}
if (this.selectedIndex > newList.length - 1) {
this.selectedIndex = 0;
}
},
selectedPickItem: {
handler(item) {
this.loadSelectedItemImage(item);
this.loadSelectedItemBarcode(item);
},
immediate: true
}
},
onLoad(options) {
const incomingTaskId = options?.taskId || options?.task_id || '';
if (incomingTaskId !== '') {
this.taskId = String(incomingTaskId || '').trim();
this.requestWavePickTaskDetail();
}
},
methods: {
getApiErrorMessage(error, fallback = '请求失败') {
const message = error?.message || error?.msg || error?.errMsg || error?.data?.message;
return String(message || fallback);
},
extractTaskDetailPayload(response) {
return response?.data?.data || response?.data || response?.result || response || {};
},
normalizeTaskDetailPayload(payload = {}) {
const task = payload?.task || {};
const summary = payload?.picking_summary || {};
const view = payload?.picking_view || {};
const viewItems = Array.isArray(view?.items) ? view.items : [];
this.taskInfo = {
taskId: task?.task_id ?? this.taskId,
taskNo: task?.task_no || '',
batchNo: task?.batch_no || '',
status: Number(task?.status || 0)
};
this.boxList = Array.isArray(payload?.boxes) ? payload.boxes : [];
this.pickingSummary = {
totalLines: Number(summary?.total_lines || 0),
totalQty: Number(summary?.total_qty || 0),
distinctSpaces: Number(summary?.distinct_spaces || 0),
distinctItems: Number(summary?.distinct_items || 0)
};
this.pickingView = {
modeCode: view?.mode_code ?? '',
modeName: view?.mode_name || '--',
items: viewItems.map(item => ({
spaceId: item?.space_id ?? '',
spaceName: item?.space_name || item?.location_space?.custom_name || '--',
spaceBarcode: item?.location_space?.custom_barcode || '--',
itemCode: item?.item_code || '--',
itemName: item?.item_name || '--',
stockId: Number(item?.stock_id || item?.item_snapshot?.stock_id || 0),
totalQty: Number(item?.total_qty || 0),
boxAllocations: (Array.isArray(item?.box_allocations) ? item.box_allocations : []).map(alloc => ({
boxId: alloc?.box_id ?? '',
boxNo: alloc?.box_no ?? '--',
allocatedQty: Number(alloc?.allocated_qty || 0)
}))
}))
};
this.selectedIndex = 0;
},
async requestWavePickTaskDetail() {
const taskIdNumber = Number(this.taskId || 0);
if (!taskIdNumber) {
return;
}
this.loadingTaskDetail = true;
try {
const response = await this.$http('pick.wavePickTaskDetail', {
task_id: taskIdNumber
});
const payload = this.extractTaskDetailPayload(response);
this.normalizeTaskDetailPayload(payload);
} catch (error) {
this.pickingView.items = [];
uni.showToast({
title: this.getApiErrorMessage(error, '任务详情获取失败'),
icon: 'none'
});
} finally {
this.loadingTaskDetail = false;
}
},
clearSearch() {
this.keyword = '';
},
getSelectedItemImageKey(item) {
if (!item || typeof item !== 'object') {
return '';
}
return String(item.stockId || item.itemCode || '').trim();
},
extractImageListFromGetImagesResponse(response) {
if (!response || typeof response !== 'object') {
return [];
}
const candidates = [
response.data,
response.data && response.data.data,
response.data && response.data.images,
response.data && response.data.list,
response.data && response.data.rows,
response.data && response.data.records,
response.data && response.data.result,
response.data && response.data.result && response.data.result.images,
response.data && response.data.result && response.data.result.list,
response.images,
response.list,
response.rows,
response.records
];
for (let i = 0; i < candidates.length; i += 1) {
const current = candidates[i];
if (!current) {
continue;
}
if (Array.isArray(current)) {
return current;
}
if (typeof current === 'object') {
const objectCandidates = [current.images, current.list, current.rows, current.records, current.data];
for (let j = 0; j < objectCandidates.length; j += 1) {
if (Array.isArray(objectCandidates[j])) {
return objectCandidates[j];
}
}
}
}
return [];
},
resolveImageUrlFromEntry(entry) {
if (!entry) {
return '';
}
if (typeof entry === 'string') {
return entry;
}
if (typeof entry !== 'object') {
return '';
}
return String(
entry.url ||
entry.path ||
entry.fileUrl ||
entry.file_url ||
(entry.file && (entry.file.file_url || entry.file.fileUrl)) ||
entry.image_url ||
entry.img_url ||
entry.src ||
''
).trim();
},
async loadSelectedItemImage(item) {
if (!item) {
this.selectedItemImageUrl = '';
this.selectedItemImageUrls = [];
this.selectedItemImageLoading = false;
return;
}
const imageKey = this.getSelectedItemImageKey(item);
if (!imageKey) {
this.selectedItemImageUrl = '';
this.selectedItemImageUrls = [];
this.selectedItemImageLoading = false;
return;
}
if (Object.prototype.hasOwnProperty.call(this.itemImageCache, imageKey)) {
this.selectedItemImageUrl = this.itemImageCache[imageKey] || '';
this.selectedItemImageUrls = Array.isArray(this.itemImageListCache[imageKey]) ? this.itemImageListCache[imageKey] : [];
this.selectedItemImageLoading = false;
return;
}
this.selectedItemImageLoading = true;
this.selectedItemImageUrl = '';
this.selectedItemImageUrls = [];
try {
const stockId = Number(item.stockId || 0);
const response = await this.$http('common.getImages', {
id: stockId,
business_id: stockId,
stock_id: stockId,
type: 'stock',
business_type: 'stock'
});
const list = this.extractImageListFromGetImagesResponse(response);
const urls = list.map(entry => this.resolveImageUrlFromEntry(entry)).filter(Boolean);
const firstUrl = urls[0] || '';
this.$set(this.itemImageCache, imageKey, firstUrl || '');
this.$set(this.itemImageListCache, imageKey, urls);
if (this.getSelectedItemImageKey(this.selectedPickItem) === imageKey) {
this.selectedItemImageUrl = firstUrl || '';
this.selectedItemImageUrls = urls;
}
} catch (error) {
this.$set(this.itemImageCache, imageKey, '');
this.$set(this.itemImageListCache, imageKey, []);
if (this.getSelectedItemImageKey(this.selectedPickItem) === imageKey) {
this.selectedItemImageUrl = '';
this.selectedItemImageUrls = [];
}
} finally {
if (this.getSelectedItemImageKey(this.selectedPickItem) === imageKey) {
this.selectedItemImageLoading = false;
}
}
},
getSelectedItemBarcodeKey(item) {
if (!item || typeof item !== 'object') {
return '';
}
return String(item.stockId || '').trim();
},
extractBarcodeListFromResponse(response) {
const candidates = [
response?.data,
response?.data?.data,
response?.list,
response
];
for (let i = 0; i < candidates.length; i += 1) {
if (Array.isArray(candidates[i])) {
return candidates[i];
}
}
return [];
},
resolveBarcodeFromEntry(entry) {
if (!entry) {
return '';
}
if (typeof entry === 'string') {
return entry.trim();
}
if (typeof entry !== 'object') {
return '';
}
return String(entry.barcode || entry.code || '').trim();
},
async loadSelectedItemBarcode(item) {
if (!item) {
this.selectedItemBarcode = '';
this.selectedItemBarcodeLoading = false;
return;
}
const barcodeKey = this.getSelectedItemBarcodeKey(item);
if (!barcodeKey) {
this.selectedItemBarcode = '';
this.selectedItemBarcodeLoading = false;
return;
}
if (Object.prototype.hasOwnProperty.call(this.itemBarcodeCache, barcodeKey)) {
this.selectedItemBarcode = this.itemBarcodeCache[barcodeKey] || '';
this.selectedItemBarcodeLoading = false;
return;
}
this.selectedItemBarcodeLoading = true;
this.selectedItemBarcode = '';
try {
const stockId = Number(item.stockId || 0);
const response = await this.$http('stock.warehouse.getBarcodes', {
id: stockId
});
const list = this.extractBarcodeListFromResponse(response);
const firstBarcode = this.resolveBarcodeFromEntry(list[0]);
this.$set(this.itemBarcodeCache, barcodeKey, firstBarcode || '');
if (this.getSelectedItemBarcodeKey(this.selectedPickItem) === barcodeKey) {
this.selectedItemBarcode = firstBarcode || '';
}
} catch (error) {
this.$set(this.itemBarcodeCache, barcodeKey, '');
if (this.getSelectedItemBarcodeKey(this.selectedPickItem) === barcodeKey) {
this.selectedItemBarcode = '';
}
} finally {
if (this.getSelectedItemBarcodeKey(this.selectedPickItem) === barcodeKey) {
this.selectedItemBarcodeLoading = false;
}
}
},
handleSearch() {
this.keyword = String(this.keyword || '').trim();
},
selectPickItem(index) {
this.selectedIndex = Number(index || 0);
},
previewSelectedItemImage() {
const urls = Array.isArray(this.selectedItemImageUrls) && this.selectedItemImageUrls.length
? this.selectedItemImageUrls
: (this.selectedItemImageUrl ? [this.selectedItemImageUrl] : []);
if (!urls.length) {
return;
}
const currentIndex = this.selectedItemImageUrl ? Math.max(urls.indexOf(this.selectedItemImageUrl), 0) : 0;
this.$tools.previewImage(urls, currentIndex);
},
handleCameraScan() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['barCode', 'qrCode'],
success: res => {
const scanText = String(res?.result || '').trim();
if (!scanText) {
uni.showToast({
title: '未识别到有效条码',
icon: 'none'
});
return;
}
this.keyword = scanText;
this.handleSearch();
},
fail: () => {
uni.showToast({
title: '扫码失败,请重试',
icon: 'none'
});
}
});
}
}
};
</script>
<style lang="scss" scoped>
.order-picking-page {
min-height: 100vh;
background: #f8f9fa;
}
::v-deep .normar_container {
min-height: 100vh;
display: flex;
flex-direction: column;
}
.empty-wrap {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 24rpx;
box-sizing: border-box;
}
.empty-card {
width: 100%;
max-width: 620rpx;
background: #ffffff;
border-radius: 16rpx;
border: 1rpx solid #e8eefc;
padding: 48rpx 24rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 14rpx;
}
.empty-title {
font-size: 36rpx;
line-height: 1.2;
color: #303133;
font-weight: 600;
}
.empty-desc {
font-size: 30rpx;
line-height: 1.4;
color: #606266;
text-align: center;
}
.content-wrap {
flex: 1;
padding: 24rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: 16rpx;
min-height: 0;
}
.top-detail-panel {
flex: 1;
min-height: 0;
}
.search-card {
background: #ffffff;
border-radius: 12rpx;
padding: 20rpx;
border: 1rpx solid #ebeef5;
}
.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: 32rpx;
color: #2979ff;
font-weight: 600;
}
.nav-complete-btn {
height: 52rpx;
line-height: 52rpx;
padding: 0 12rpx;
border-radius: 10rpx;
font-size: 22rpx;
text-align: center;
white-space: nowrap;
}
.nav-complete-btn--disabled {
background: #f2f3f5;
color: #c0c4cc;
border: 1rpx solid #e4e7ed;
pointer-events: none;
}
.loading-wrap {
background: #ffffff;
border-radius: 12rpx;
padding: 24rpx;
border: 1rpx solid #ebeef5;
}
.loading-text {
font-size: 30rpx;
color: #606266;
}
.bottom-grid-panel {
flex: 0 0 300rpx;
height: 300rpx;
background: #ffffff;
border-radius: 12rpx;
padding: 12rpx;
border: 1rpx solid #ebeef5;
}
.list-empty {
background: #ffffff;
border-radius: 12rpx;
padding: 28rpx;
border: 1rpx solid #ebeef5;
font-size: 30rpx;
color: #909399;
}
.pick-card {
background: #ffffff;
border-radius: 12rpx;
padding: 20rpx;
border: 1rpx solid #ebeef5;
height: 100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
.pick-card__head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12rpx;
}
.pick-name {
font-size: 32rpx;
color: #303133;
font-weight: 600;
flex: 1;
}
.pick-row {
display: flex;
align-items: center;
font-size: 28rpx;
line-height: 44rpx;
margin-top: 6rpx;
}
.detail-main {
display: flex;
align-items: flex-start;
gap: 16rpx;
}
.detail-main-left {
width: 120rpx;
min-width: 120rpx;
}
.detail-main-right {
flex: 1;
min-width: 0;
}
.pick-image-empty {
width: 120rpx;
height: 120rpx;
border-radius: 10rpx;
border: 1rpx dashed #dcdfe6;
color: #909399;
font-size: 22rpx;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
padding: 6rpx;
box-sizing: border-box;
}
.pick-row--top {
margin-top: 10rpx;
}
.alloc-panel {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.alloc-scroll {
flex: 1;
min-height: 0;
}
.pick-label {
width: 150rpx;
min-width: 150rpx;
color: #909399;
}
.pick-value {
color: #303133;
}
.pick-value--highlight {
color: #2979ff;
font-weight: 700;
}
.index-grid {
display: flex;
flex-wrap: wrap;
gap: 8rpx;
}
.alloc-wrap {
display: flex;
flex-wrap: wrap;
gap: 8rpx;
margin-top: 8rpx;
}
.alloc-item {
padding: 6rpx 12rpx;
border-radius: 999rpx;
background: #f2f7ff;
}
.alloc-text {
font-size: 24rpx;
color: #2979ff;
}
.alloc-empty {
font-size: 26rpx;
color: #909399;
margin-top: 8rpx;
}
.alloc-safe-bottom {
height: 8rpx;
}
.index-cell {
flex: 0 0 calc((100% - 32rpx) / 5);
width: calc((100% - 32rpx) / 5);
aspect-ratio: 1 / 1;
box-sizing: border-box;
border-radius: 12rpx;
background: #f5f7fa;
border: 1rpx solid #e4e7ed;
display: flex;
align-items: center;
justify-content: center;
}
.index-cell--active {
background: #eaf2ff;
border-color: #2979ff;
}
.index-text {
font-size: 34rpx;
font-weight: 600;
color: #2979ff;
}
.safe-bottom {
height: calc(20rpx + env(safe-area-inset-bottom));
}
</style>