WMS_PDA/pages/work/order/detail.vue

763 lines
20 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="picking-detail-page">
<view class="normar_container">
<page-nav :title="title"></page-nav>
<view class="summary-card">
<view class="summary-head">
<text class="order-no">{{ orderInfo.orderNo || '--' }}</text>
<text class="mode-tag">{{ pickModeText }}</text>
</view>
<view class="summary-row"><text class="label">客户:</text><text class="value">{{ orderInfo.customerName || '--' }}</text></view>
<view class="summary-row"><text class="label">波次:</text><text class="value">{{ orderInfo.waveNo || '--' }}</text></view>
<view class="summary-row"><text class="label">状态:</text><text class="value">{{ statusText }}</text></view>
<view class="summary-row"><text class="label">拣货进度:</text><text class="value">{{ orderInfo.pickedQty || 0 }}/{{ orderInfo.needQty || 0 }}</text></view>
</view>
<view class="section-title-row">
<view class="section-title">拣货明细</view>
<view class="scan-entry" @click="handleScanBarcode">
<u-icon name="scan" size="26" color="#2979ff"></u-icon>
<text class="scan-entry__text">扫码拣货</text>
</view>
</view>
<view class="detail-list">
<view class="detail-item" v-for="(line, detailIndex) in detailList" :key="line.lineId" @longpress.stop="handleLineLongPress(line, detailIndex)">
<view class="detail-head">
<text class="sku-name">{{ line.skuName }}</text>
<view class="detail-head-right">
<text v-if="line.noBarcodeVerified" class="verify-tag">无条码核对</text>
<text v-if="line.locationErrorReported" class="error-tag">库位报错</text>
<text v-if="line.pickedQty >= line.needQty" class="picked-tag">已拣</text>
<text class="space">{{ line.space }}</text>
</view>
</view>
<view class="detail-row"><text class="label">SKU:</text><text class="value">{{ line.skuCode }}</text></view>
<view class="detail-row"><text class="label">条码:</text><text class="value">{{ line.barcode || '--' }}</text></view>
<view class="detail-row"><text class="label">篮号:</text><text class="value">{{ getBasketNoText(line) }}</text></view>
<view class="detail-row"><text class="label">应拣:</text><text class="value">{{ line.needQty }}</text></view>
<view class="detail-row"><text class="label">已拣:</text><text class="value">{{ line.pickedQty }}</text></view>
</view>
</view>
<view class="action-bar">
<u-button
v-if="orderInfo.status === 'pending'"
type="primary"
:customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff' }"
@click="startPicking"
>开始拣货</u-button>
<u-button
v-else-if="orderInfo.status === 'picking'"
type="success"
@click="completePicking"
>完成拣货</u-button>
<u-button v-else type="info" :disabled="true">已完成</u-button>
</view>
<u-popup :show="locationErrorPopupVisible" mode="bottom" :closeable="true" border-radius="20" @close="closeLocationErrorPopup">
<view class="location-error-popup">
<view class="popup-title">库位报错(拍照上传)</view>
<view class="popup-line">商品:{{ currentActionLine && currentActionLine.skuName ? currentActionLine.skuName : '--' }}</view>
<view class="popup-line">库位:{{ currentActionLine && currentActionLine.space ? currentActionLine.space : '--' }}</view>
<view class="popup-label">异常说明</view>
<u-textarea v-model="locationErrorRemark" placeholder="请输入异常说明(选填)" height="120" border="surround"></u-textarea>
<view class="popup-label">异常图片</view>
<view class="photo-list">
<view v-for="(img, imgIndex) in locationErrorImages" :key="img + '-' + imgIndex" class="photo-item">
<u-image :src="img" mode="aspectFill" width="120rpx" height="120rpx" @click="previewLocationErrorImage(imgIndex)"></u-image>
<view class="photo-remove" @click="removeLocationErrorImage(imgIndex)">×</view>
</view>
<view v-if="locationErrorImages.length < 3" class="photo-add" @click="chooseLocationErrorImage">
<u-icon name="camera" size="26" color="#2979ff"></u-icon>
<text class="photo-add-text">拍照</text>
</view>
</view>
<view class="popup-actions">
<u-button @click="closeLocationErrorPopup">取消</u-button>
<u-button type="error" :loading="locationErrorSubmitting" @click="submitLocationError">提交报错</u-button>
</view>
</view>
</u-popup>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: '拣货详情',
pickMode: 'F',
orderInfo: {
id: '',
orderNo: '',
customerName: '',
waveNo: '',
status: 'pending',
needQty: 0,
pickedQty: 0
},
detailList: [],
locationErrorPopupVisible: false,
currentActionLineIndex: -1,
locationErrorRemark: '',
locationErrorImages: [],
locationErrorSubmitting: false
}
},
computed: {
pickModeText() {
return this.pickMode === 'E' ? 'E拣货(边拣边分)' : 'F拣货(先拣后分)';
},
statusText() {
const map = {
pending: '待拣货',
picking: '拣货中',
done: '已完成'
};
return map[this.orderInfo.status] || '未知状态';
},
currentActionLine() {
if (this.currentActionLineIndex < 0) {
return null;
}
return this.detailList[this.currentActionLineIndex] || null;
}
},
onLoad(options) {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
if (options && options.mode) {
const mode = String(options.mode || '').toUpperCase();
if (mode === 'F' || mode === 'E') {
this.pickMode = mode;
}
}
this.orderInfo = {
id: options?.id || '',
orderNo: options?.orderNo || '--',
customerName: options?.customerName || '--',
waveNo: options?.waveNo || '--',
status: options?.status || 'pending',
needQty: Number(options?.needQty || 0),
pickedQty: Number(options?.pickedQty || 0)
};
this.detailList = this.buildMockDetails(this.orderInfo);
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
},
methods: {
getBasketNoText(line) {
if (!line || typeof line !== 'object') {
return '--';
}
const basketNo = String(line.basketNo || '').trim();
if (basketNo) {
return basketNo;
}
const space = String(line.space || '').trim();
if (!space) {
return '--';
}
const segments = space.split('-').filter(Boolean);
return segments[segments.length - 1] || space;
},
speakPickResult(line) {
if (!line || typeof line !== 'object') {
return;
}
const basketNo = this.getBasketNoText(line);
const qty = Number(line.needQty || 0);
const speakText = `篮号${basketNo},数量${qty}`;
try {
const task = this.$tools && typeof this.$tools.speakText === 'function'
? this.$tools.speakText(speakText, { force: true })
: null;
if (task && typeof task.catch === 'function') {
task.catch(() => {});
}
} catch (error) {}
},
handleLineLongPress(line, index) {
if (!line || typeof line !== 'object') {
return;
}
uni.showActionSheet({
itemList: ['无条码核对', '库位报错(拍照上传)'],
success: (res) => {
if (res.tapIndex === 0) {
this.handleNoBarcodeVerify(index);
return;
}
if (res.tapIndex === 1) {
this.openLocationErrorPopup(index);
}
},
fail: () => {}
});
},
handleNoBarcodeVerify(index) {
const line = this.detailList[index];
if (!line) {
return;
}
if (Number(line.pickedQty || 0) >= Number(line.needQty || 0)) {
uni.showToast({
title: '该商品已拣完成',
icon: 'none'
});
return;
}
const updatedLine = {
...line,
pickedQty: Number(line.needQty || 0),
noBarcodeVerified: true,
noBarcodeVerifiedAt: Date.now()
};
this.$set(this.detailList, index, updatedLine);
this.recalculateOrderProgress();
this.emitOrderUpdate();
this.speakPickResult(updatedLine);
uni.showToast({
title: '已完成无条码核对',
icon: 'success'
});
},
openLocationErrorPopup(index) {
this.currentActionLineIndex = index;
this.locationErrorRemark = '';
this.locationErrorImages = [];
this.locationErrorPopupVisible = true;
},
closeLocationErrorPopup() {
this.locationErrorPopupVisible = false;
this.currentActionLineIndex = -1;
this.locationErrorSubmitting = false;
},
chooseLocationErrorImage() {
if (this.locationErrorImages.length >= 3) {
return;
}
uni.chooseImage({
count: 1,
sourceType: ['camera'],
sizeType: ['compressed'],
success: (res) => {
const filePath = res?.tempFilePaths?.[0] || res?.tempFiles?.[0]?.path;
if (!filePath) {
uni.showToast({
title: '拍照失败,请重试',
icon: 'none'
});
return;
}
this.locationErrorImages = [...this.locationErrorImages, filePath].slice(0, 3);
},
fail: () => {}
});
},
removeLocationErrorImage(index) {
this.locationErrorImages.splice(index, 1);
},
previewLocationErrorImage(index) {
if (!this.locationErrorImages.length) {
return;
}
uni.previewImage({
urls: this.locationErrorImages,
current: this.locationErrorImages[index] || this.locationErrorImages[0]
});
},
submitLocationError() {
const line = this.currentActionLine;
if (!line) {
this.closeLocationErrorPopup();
return;
}
if (!this.locationErrorImages.length) {
uni.showToast({
title: '请先拍照上传',
icon: 'none'
});
return;
}
this.locationErrorSubmitting = true;
const updatedLine = {
...line,
locationErrorReported: true,
locationErrorRemark: String(this.locationErrorRemark || '').trim(),
locationErrorImages: [...this.locationErrorImages],
locationErrorReportedAt: Date.now()
};
this.$set(this.detailList, this.currentActionLineIndex, updatedLine);
this.emitOrderUpdate();
this.locationErrorSubmitting = false;
this.locationErrorPopupVisible = false;
this.currentActionLineIndex = -1;
uni.showToast({
title: '库位报错已提交',
icon: 'success'
});
},
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[OrderDetail] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[OrderDetail] 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.markPickedByBarcode(scanResult);
},
handleScanBarcode() {
this.safeDispatchBroadcast('resume');
uni.showToast({
title: '请使用扫描枪扫码',
icon: 'none'
});
},
markPickedByBarcode(barcode) {
const normalizedBarcode = String(barcode || '').trim();
if (!normalizedBarcode) {
return;
}
const index = this.detailList.findIndex(line => String(line.barcode || '').trim() === normalizedBarcode);
if (index < 0) {
uni.showToast({
title: '无扫描记录',
icon: 'none'
});
return;
}
const targetLine = this.detailList[index];
if (Number(targetLine.pickedQty || 0) >= Number(targetLine.needQty || 0)) {
uni.showToast({
title: '该商品已拣完成',
icon: 'none'
});
return;
}
const updatedLine = {
...targetLine,
pickedQty: Number(targetLine.needQty || 0)
};
this.$set(this.detailList, index, updatedLine);
this.recalculateOrderProgress();
this.emitOrderUpdate();
this.speakPickResult(updatedLine);
uni.showToast({
title: `已拣:${updatedLine.skuName}`,
icon: 'success'
});
},
recalculateOrderProgress() {
const totalPicked = this.detailList.reduce((sum, line) => {
return sum + Number(line.pickedQty || 0);
}, 0);
const totalNeed = this.detailList.reduce((sum, line) => {
return sum + Number(line.needQty || 0);
}, 0);
this.orderInfo.needQty = totalNeed;
this.orderInfo.pickedQty = Math.max(0, Math.min(totalPicked, totalNeed));
if (this.orderInfo.pickedQty >= totalNeed && totalNeed > 0) {
this.orderInfo.status = 'done';
return;
}
if (this.orderInfo.pickedQty > 0) {
this.orderInfo.status = 'picking';
return;
}
this.orderInfo.status = 'pending';
},
emitOrderUpdate() {
uni.$emit('order:picking:updated', {
id: this.orderInfo.id,
orderNo: this.orderInfo.orderNo,
status: this.orderInfo.status,
pickedQty: this.orderInfo.pickedQty,
needQty: this.orderInfo.needQty
});
},
startPicking() {
if (this.orderInfo.status !== 'pending') {
return;
}
this.orderInfo.status = 'picking';
this.emitOrderUpdate();
uni.showToast({
title: '已开始拣货',
icon: 'success'
});
},
completePicking() {
if (this.orderInfo.status !== 'picking') {
return;
}
this.orderInfo.status = 'done';
this.detailList = this.detailList.map(line => ({
...line,
pickedQty: Number(line.needQty || 0)
}));
this.recalculateOrderProgress();
this.emitOrderUpdate();
uni.showToast({
title: '拣货完成',
icon: 'success'
});
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 300);
},
buildMockDetails(orderInfo) {
const total = Number(orderInfo.needQty || 0);
const picked = Number(orderInfo.pickedQty || 0);
const firstNeed = Math.max(Math.floor(total * 0.4), 1);
const secondNeed = Math.max(Math.floor(total * 0.35), 1);
const thirdNeed = Math.max(total - firstNeed - secondNeed, 1);
const firstPicked = Math.min(firstNeed, picked);
const secondPicked = Math.min(secondNeed, Math.max(picked - firstPicked, 0));
const thirdPicked = Math.min(thirdNeed, Math.max(picked - firstPicked - secondPicked, 0));
return [
{
lineId: `${orderInfo.orderNo}-1`,
skuName: '陶瓷马克杯 350ml',
skuCode: 'SKU-CP-350',
barcode: '6901001000011',
basketNo: 'A01',
space: 'A-01-03',
needQty: firstNeed,
pickedQty: firstPicked
},
{
lineId: `${orderInfo.orderNo}-2`,
skuName: '密封保鲜盒 2L',
skuCode: 'SKU-FB-2000',
barcode: '6901001000028',
basketNo: 'B02',
space: 'B-02-08',
needQty: secondNeed,
pickedQty: secondPicked
},
{
lineId: `${orderInfo.orderNo}-3`,
skuName: '厨房清洁布 5片装',
skuCode: 'SKU-KC-005',
barcode: '6901001000035',
basketNo: 'C03',
space: 'C-03-12',
needQty: thirdNeed,
pickedQty: thirdPicked
}
];
}
}
}
</script>
<style lang="scss" scoped>
.picking-detail-page {
min-height: 100vh;
background: #f8f9fa;
}
.summary-card {
margin: 20rpx 24rpx 0;
padding: 20rpx;
background: #fff;
border-radius: 14rpx;
}
.summary-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12rpx;
}
.order-no {
font-size: 30rpx;
font-weight: 600;
color: #303133;
}
.mode-tag {
font-size: 22rpx;
color: #2979ff;
background: #edf4ff;
padding: 6rpx 12rpx;
border-radius: 16rpx;
}
.summary-row,
.detail-row {
display: flex;
align-items: center;
font-size: 24rpx;
line-height: 38rpx;
}
.label {
width: 120rpx;
color: #909399;
}
.value {
flex: 1;
color: #303133;
}
.section-title-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 24rpx 12rpx;
}
.section-title {
font-size: 26rpx;
font-weight: 600;
color: #303133;
}
.scan-entry {
display: inline-flex;
align-items: center;
justify-content: center;
height: 46rpx;
padding: 0 14rpx;
background: #edf4ff;
border-radius: 23rpx;
}
.scan-entry__text {
font-size: 22rpx;
font-weight: 600;
color: #2979ff;
margin-left: 6rpx;
}
.detail-list {
padding: 0 24rpx 160rpx;
}
.detail-item {
background: #fff;
border-radius: 14rpx;
padding: 18rpx 20rpx;
margin-bottom: 12rpx;
}
.detail-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8rpx;
}
.detail-head-right {
display: inline-flex;
align-items: center;
}
.verify-tag {
font-size: 20rpx;
color: #2979ff;
background: #edf4ff;
padding: 4rpx 10rpx;
border-radius: 12rpx;
margin-right: 8rpx;
}
.error-tag {
font-size: 20rpx;
color: #fa3534;
background: #fff2f0;
padding: 4rpx 10rpx;
border-radius: 12rpx;
margin-right: 8rpx;
}
.picked-tag {
font-size: 20rpx;
color: #19be6b;
background: #eafaf0;
padding: 4rpx 10rpx;
border-radius: 12rpx;
margin-right: 8rpx;
}
.sku-name {
font-size: 26rpx;
font-weight: 600;
color: #303133;
}
.space {
font-size: 22rpx;
color: #606266;
background: #f6f7fb;
padding: 4rpx 10rpx;
border-radius: 12rpx;
}
.action-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom));
background: #fff;
border-top: 1rpx solid #f0f0f0;
box-sizing: border-box;
}
.location-error-popup {
padding: 26rpx 24rpx calc(20rpx + env(safe-area-inset-bottom));
}
.popup-title {
font-size: 30rpx;
font-weight: 600;
color: #303133;
margin-bottom: 16rpx;
}
.popup-line {
font-size: 24rpx;
line-height: 38rpx;
color: #606266;
}
.popup-label {
font-size: 24rpx;
color: #303133;
font-weight: 600;
margin: 16rpx 0 10rpx;
}
.photo-list {
display: flex;
align-items: center;
flex-wrap: wrap;
}
.photo-item {
position: relative;
width: 120rpx;
height: 120rpx;
margin-right: 12rpx;
margin-bottom: 12rpx;
}
.photo-remove {
position: absolute;
right: -10rpx;
top: -10rpx;
width: 34rpx;
height: 34rpx;
border-radius: 17rpx;
background: rgba(0, 0, 0, 0.6);
color: #fff;
font-size: 26rpx;
display: flex;
align-items: center;
justify-content: center;
}
.photo-add {
width: 120rpx;
height: 120rpx;
border: 1rpx dashed #bdd4ff;
border-radius: 10rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-bottom: 12rpx;
}
.photo-add-text {
font-size: 22rpx;
color: #2979ff;
margin-top: 4rpx;
}
.popup-actions {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 12rpx;
margin-top: 8rpx;
}
</style>