WMS_PDA/pages/work/order/scatter-pick-goods-detail.vue
2026-06-12 14:10:32 +08:00

1665 lines
43 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-pick-goods-detail-page">
<view class="normar_container">
<page-nav :title="title">
<template #right>
<view v-if="isIntercepted" class="nav-right-complete nav-right-complete--intercept" @click="handleIntercept">确认拦截</view>
<view v-else class="nav-right-complete" :class="{ 'nav-right-complete--disabled': !canConfirmRecheck }" @click="canConfirmRecheck && handleComplete()">确认复核</view>
</template>
</page-nav>
<view class="page-head">
<view class="page-head-row page-head-row--top">
<text class="page-head-value">{{ detailInfo.listType === 'single' ? detailInfo.waybillNo : detailInfo.waveNo }}</text>
</view>
<view class="page-head-row page-head-row--wave">
<text class="page-head-label">{{ detailInfo.listType === 'group' ? '运单:' : '波次:' }}</text>
<text class="page-head-wave">{{ detailInfo.listType === 'group' ? (detailInfo.waybillNo || '--') : (detailInfo.waveNo || '--') }}</text>
</view>
<view class="page-head-row page-head-row--bottom">
<text class="page-head-picker">拣货人:{{ detailInfo.pickerName }}</text>
<view class="page-head-actions">
<view class="page-head-btn" @click="handleReprint">面单补打</view>
<view class="page-head-btn page-head-btn--primary" @click="handleWeigh">称重</view>
</view>
</view>
</view>
<view v-if="goodsList.length === 0" class="empty-state empty-state--content">
<u-icon name="list" size="86" color="#c0c4cc"></u-icon>
<text class="empty-text">暂无拣货商品</text>
</view>
<view v-else class="content-layout">
<view class="top-module">
<view class="top-card">
<view class="top-main">
<view class="goods-image-name-row">
<view class="goods-thumb" @click.stop="previewCurrentGoodsImage">
<u-image
v-if="getCurrentGoodsImageList().length <= 1"
class="goods-image"
:src="currentGoods.imageUrl || ''"
mode="aspectFill"
width="240rpx"
height="240rpx"
>
<template #error>
<view class="image-placeholder image-placeholder--large">
<u-icon name="photo" size="32" color="#c0c4cc"></u-icon>
</view>
</template>
</u-image>
<view v-else class="goods-image-grid">
<view
v-for="(img, imgIndex) in getCurrentGoodsImageGridList()"
:key="img.url + '-' + imgIndex"
class="grid-cell"
:class="{ 'grid-cell--empty': !img.url }"
>
<template v-if="img.url">
<u-image
class="grid-image"
:src="img.url"
mode="aspectFill"
width="100%"
height="100%"
>
<template #error>
<view class="image-placeholder image-placeholder--small">
<u-icon name="photo" size="24" color="#c0c4cc"></u-icon>
</view>
</template>
</u-image>
<view v-if="imgIndex === 3 && getCurrentGoodsExtraImageCount() > 0" class="more-mask">
<text class="more-text">+{{ getCurrentGoodsExtraImageCount() }}</text>
</view>
</template>
<view v-else class="image-placeholder image-placeholder--small image-placeholder--empty">
<u-icon name="photo" size="24" color="#c0c4cc"></u-icon>
</view>
</view>
</view>
</view>
<text class="goods-name">{{ currentGoods.skuName || '--' }}</text>
</view>
<view class="top-info">
<view class="goods-row" :class="{ 'goods-row--barcode-highlight': isCurrentBarcodeMatched }"><view class="label">条码:</view><text class="value">{{ currentGoods.barcode || '--' }}</text></view>
<view class="goods-row"><view class="label">货主:</view><text class="value">{{ detailInfo.storeRemark || '--' }}</text></view>
<view class="goods-row goods-row--qty" :class="{ 'goods-row--scanned-complete': isScannedComplete }">
<view class="qty-item"><view class="label">已扫:</view><text class="value">{{ currentGoods.scannedQty || 0 }}</text></view>
<view class="qty-divider"></view>
<view class="qty-item"><view class="label">蓝号:</view><text class="value">{{ detailInfo.waveIndex || '--' }}</text></view>
</view>
<view class="goods-row goods-row--qty">
<view class="qty-item"><view class="label">总数:</view><text class="value">{{ currentGoods.planQty || 0 }}</text></view>
<view class="qty-divider"></view>
<view class="qty-item"><view class="label">规格:</view><text class="value">{{ currentGoods.location || '--' }}</text></view>
</view>
<view class="goods-row"><view class="label label--package">打包要求:</view><text class="value">{{ currentGoods.packageRequirement }}</text></view>
<view class="goods-row goods-row--pick-btn"><view class="pick-list-title-btn" @click="togglePickListSection">商品列表</view></view>
</view>
</view>
<view class="switch-row">
<u-button size="mini" @click="showPrevGoods" :disabled="!hasPrevGoods">上一个</u-button>
<text class="switch-index">{{ currentGoodsIndex + 1 }}/{{ goodsList.length }}</text>
<u-button type="primary" size="mini" :customStyle="{ backgroundColor: '#2979ff', borderColor: '#2979ff' }" @click="showNextGoods" :disabled="!hasNextGoods">下一个</u-button>
</view>
</view>
</view>
<scroll-view class="bottom-module" scroll-y>
<view class="bottom-module-title" v-show="showPickListSection">商品列表</view>
<view class="pick-list-scroll" v-show="showPickListSection">
<view class="pick-list">
<view
v-for="(item, index) in goodsList"
:key="item.id"
class="pick-item-wrap"
@click="selectGoods(index)"
>
<view class="metric-card-btn" :class="{ 'metric-card-btn--active': index === currentGoodsIndex, 'metric-card-btn--matched': isGoodsMatched(item) }">
<view class="order-corner"></view>
<view class="metric-diagonal"></view>
<text class="metric-order">{{ item.lineNo || 0 }}</text>
<text class="metric-product">{{ item.planQty || 0 }}</text>
<text class="metric-scanned">{{ item.scannedQty || 0 }}</text>
</view>
</view>
</view>
</view>
<view class="safe-area-bottom"></view>
</scroll-view>
</view>
<view class="bottom-summary">
<text class="bottom-summary-text">合计:<text class="bottom-summary-value">{{ totalPlanQty }}</text></text>
<text class="bottom-summary-scan">已扫:<text class="bottom-summary-value">{{ totalScannedQty }}</text><text class="bottom-summary-split">/</text><text class="bottom-summary-total">{{ totalPlanQty }}</text>件</text>
</view>
</view>
<u-popup :show="showWeighPopup" mode="center" :closeable="true" border-radius="20" :z-index="10090" @close="showWeighPopup = false">
<view class="weigh-popup">
<view class="weigh-popup-title">称重</view>
<view class="weigh-popup-body">
<view class="weigh-row">
<text class="weigh-label">重量 <text class="weigh-required">*</text></text>
<view class="weigh-control">
<view class="weigh-btn weigh-btn--minus" @click="weighDecrement">-</view>
<input
class="weigh-input"
type="digit"
:value="weighWeight > 0 ? String(weighWeight) : ''"
placeholder="请输入重量"
placeholder-style="color:#c0c4cc;font-size:28rpx"
@input="handleWeighInput"
/>
<view class="weigh-btn weigh-btn--plus" @click="weighIncrement">+</view>
<text class="weigh-unit">kg</text>
</view>
</view>
</view>
<view class="weigh-popup-footer">
<view class="weigh-footer-btn weigh-footer-btn--cancel" @click="showWeighPopup = false">取消</view>
<view class="weigh-footer-btn weigh-footer-btn--save" @click="handleWeighSave">保存</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
export default {
data() {
return {
title: '订单商品详情',
currentGoodsIndex: 0,
confirmingRecheck: false,
matchedGoodsId: '',
matchedGoodsState: {},
showPickListSection: true,
showWeighPopup: false,
weighWeight: 0,
detailInfo: {
recordId: '',
orderId: 0,
waveId: '',
waveNo: '--',
waybillNo: '--',
matchType: '',
recheckStatus: '',
pickerName: '--',
cartNo: '--',
status: 'pending',
unreviewedCount: 0,
storeRemark: '',
waveIndex: '',
orderIds: [],
interceptStatus: ''
},
goodsList: []
};
},
watch: {
goodsList: {
handler() {
const total = this.totalPlanQty;
const scanned = this.totalScannedQty;
if (total > 0 && scanned >= total) {
uni.showToast({
title: '全部商品已扫描完成,可点击确认复核',
icon: 'none',
duration: 2000
});
}
},
deep: true
}
},
computed: {
headMatchLabel() {
if (this.detailInfo?.matchType === 'waybill') {
return '快递单号';
}
if (this.detailInfo?.matchType === 'cart') {
return '车号';
}
return '波次号';
},
headMatchValue() {
if (this.detailInfo?.matchType === 'waybill') {
return this.detailInfo?.waybillNo || '--';
}
if (this.detailInfo?.matchType === 'cart') {
return this.detailInfo?.cartNo || '--';
}
return this.detailInfo?.waveNo || '--';
},
currentGoods() {
return this.goodsList[this.currentGoodsIndex] || {};
},
hasPrevGoods() {
return this.currentGoodsIndex > 0;
},
hasNextGoods() {
return this.currentGoodsIndex < this.goodsList.length - 1;
},
isRecheckFinished() {
return String(this.detailInfo?.recheckStatus || '').toLowerCase() === 'fin';
},
isIntercepted() {
const status = String(this.detailInfo?.interceptStatus || '').trim().toLowerCase();
return !!status && status !== 'none' && status !== '';
},
isCurrentBarcodeMatched() {
const currentId = String(this.currentGoods?.id || '');
if (!currentId) {
return false;
}
return !!this.matchedGoodsState[currentId];
},
totalPlanQty() {
return this.goodsList.reduce((sum, item) => sum + (item.planQty || 0), 0);
},
totalScannedQty() {
return this.goodsList.reduce((sum, item) => sum + (item.scannedQty || 0), 0);
},
isScannedComplete() {
const plan = Number(this.currentGoods?.planQty || 0);
const scanned = Number(this.currentGoods?.scannedQty || 0);
return plan > 0 && scanned >= plan;
},
isAllMatched() {
return this.goodsList.every(item => {
const id = String(item?.id || '');
if (!id) return false;
return !!this.matchedGoodsState[id];
});
},
isAllScanned() {
return this.goodsList.every(item => (item.scannedQty || 0) >= (item.planQty || 0));
},
canConfirmRecheck() {
return this.isAllMatched && this.isAllScanned;
}
},
onLoad(options) {
const safeDecode = (val) => {
if (!val) return '';
try {
return decodeURIComponent(String(val));
} catch (e) {
return String(val);
}
};
const matchType = String(options?.matchType || '').trim();
const recheckStatus = String(options?.recheckStatus || '').trim().toLowerCase();
let parsedOrderIds = [];
try {
const raw = String(options?.orderIds || '').trim();
if (raw) {
parsedOrderIds = JSON.parse(decodeURIComponent(raw));
}
} catch (e) {
parsedOrderIds = [];
}
this.detailInfo = {
recordId: options?.recordId || '',
orderId: Number(options?.orderId || options?.recordId || 0),
waveId: String(options?.waveId || '').trim(),
waveNo: safeDecode(options?.waveNo) || '--',
waybillNo: safeDecode(options?.waybillNo) || '--',
matchType,
recheckStatus,
pickerName: safeDecode(options?.pickerName) || '--',
cartNo: safeDecode(options?.cartNo) || '--',
status: options?.status || 'pending',
unreviewedCount: Number(options?.unreviewedCount || 0),
listType: String(options?.listType || '').trim(),
storeRemark: safeDecode(options?.storeRemark),
waveIndex: String(options?.waveIndex || '').trim(),
orderIds: Array.isArray(parsedOrderIds) ? parsedOrderIds : [],
interceptStatus: String(options?.interceptStatus || '').trim()
};
if (this.isRecheckFinished) {
uni.showToast({
title: '该订单已复核完成,禁止再次进入',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 300);
return;
}
const cacheKey = String(options?.cacheKey || '').trim();
const cacheResult = this.getCachedScanOrderResult(cacheKey);
if (cacheResult.hasCache) {
this.goodsList = this.buildGoodsListByItems(cacheResult.items);
} else {
this.goodsList = this.buildMockGoodsList();
}
this.currentGoodsIndex = 0;
this.matchedGoodsState = {};
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
},
onShow() {
if (this.isRecheckFinished) {
return;
}
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
},
methods: {
isGoodsMatched(item) {
const id = String(item?.id || '');
if (!id) {
return false;
}
return !!this.matchedGoodsState[id];
},
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[ScatterPickGoodsDetail] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[ScatterPickGoodsDetail] broadcast/${action} 调用异常:`, error);
}
},
normalizeBarcode(value) {
return String(value || '').replace(/\s+/g, '').toUpperCase();
},
normalizeScanResult(scanResult) {
if (!scanResult) {
return '';
}
if (typeof scanResult === 'string') {
return this.normalizeBarcode(scanResult);
}
if (typeof scanResult.result === 'string') {
return this.normalizeBarcode(scanResult.result);
}
if (Array.isArray(scanResult.result)) {
const firstResult = scanResult.result.find(item => item);
if (typeof firstResult === 'string') {
return this.normalizeBarcode(firstResult);
}
if (firstResult && typeof firstResult.data === 'string') {
return this.normalizeBarcode(firstResult.data);
}
}
if (typeof scanResult.data === 'string') {
return this.normalizeBarcode(scanResult.data);
}
return '';
},
extractBarcodeCandidates(item) {
const sourceList = [
item?.barcode,
item?.skuCode
];
const result = [];
sourceList.forEach(source => {
const text = String(source || '').trim();
if (!text) {
return;
}
text
.split(/[;,,|\s]+/)
.map(part => this.normalizeBarcode(part))
.filter(part => !!part)
.forEach(part => result.push(part));
});
return Array.from(new Set(result));
},
handleBroadcastResult(result) {
const scanCode = this.normalizeScanResult(result);
if (!scanCode) {
return;
}
const matchIndex = this.goodsList.findIndex(item => {
const candidates = this.extractBarcodeCandidates(item);
return candidates.includes(scanCode);
});
if (matchIndex < 0) {
uni.showToast({
title: '条码不匹配',
icon: 'none'
});
return;
}
this.currentGoodsIndex = matchIndex;
this.matchedGoodsId = String(this.goodsList[matchIndex]?.id || '');
if (this.matchedGoodsId) {
if (typeof this.$set === 'function') {
this.$set(this.matchedGoodsState, this.matchedGoodsId, true);
} else {
this.matchedGoodsState[this.matchedGoodsId] = true;
}
}
const matchedItem = this.goodsList[matchIndex];
const itemName = matchedItem?.skuName || '商品';
const maxQty = matchedItem?.planQty || 0;
const currentScanned = matchedItem?.scannedQty || 0;
// 总数小于3时,不弹输入框,扫一次已扫+1
if (maxQty < 3) {
const newScanned = Math.min(currentScanned + 1, maxQty);
if (typeof this.$set === 'function') {
this.$set(this.goodsList, matchIndex, {
...matchedItem,
scannedQty: newScanned
});
} else {
this.goodsList[matchIndex].scannedQty = newScanned;
}
uni.showToast({ title: `已扫:${newScanned}/${maxQty}`, icon: 'none' });
return;
}
uni.showModal({
title: `扫描成功:${itemName}`,
content: `请输入数量(共 ${maxQty},已扫 ${currentScanned}):`,
editable: true,
placeholderText: '请输入数量',
success: (res) => {
if (!res.confirm) return;
const inputQty = this.toPositiveNumber(res.content, 0);
if (inputQty <= 0) {
uni.showToast({ title: '请输入有效数量', icon: 'none' });
return;
}
const newScanned = Math.min(inputQty, maxQty);
if (typeof this.$set === 'function') {
this.$set(this.goodsList, matchIndex, {
...matchedItem,
scannedQty: newScanned
});
} else {
this.goodsList[matchIndex].scannedQty = newScanned;
}
uni.showToast({
title: `已录入 ${newScanned} 个`,
icon: 'success'
});
}
});
},
toPositiveNumber(value, fallback = 0) {
const num = Number(value);
if (Number.isFinite(num) && num >= 0) {
return num;
}
return fallback;
},
getCachedScanOrderResult(cacheKey) {
const key = String(cacheKey || '').trim();
if (!key) {
return {
hasCache: false,
items: []
};
}
let cached = null;
try {
cached = uni.getStorageSync(key);
uni.removeStorageSync(key);
} catch (error) {
console.warn('[ScatterPickGoodsDetail] 读取 scanOrder 缓存失败:', error);
}
if (!cached || typeof cached !== 'object') {
return {
hasCache: true,
items: []
};
}
return {
hasCache: true,
items: Array.isArray(cached.items) ? cached.items : []
};
},
buildGoodsListByItems(items) {
const sourceList = Array.isArray(items) ? items : [];
return sourceList.map((item, index) => {
// 判断是否为 stock 对象(直接包含 item_name 等字段)
const isStockItem = !!item?.stock_id || (!!item?.item_name && !!item?.plan_qty);
const stockItem = isStockItem ? item : (Array.isArray(item?.stock) && item.stock.length > 0 ? item.stock[0] : null);
const snapshot = item?.item_snapshot && typeof item.item_snapshot === 'object'
? item.item_snapshot
: {};
const stockImages = stockItem ? (Array.isArray(stockItem.images) ? stockItem.images : []) : [];
const snapshotImages = [
...(Array.isArray(snapshot?.images) ? snapshot.images : []),
...(Array.isArray(snapshot?.image_list) ? snapshot.image_list : [])
]
.map(url => String(url || '').trim())
.filter(url => !!url);
const itemImages = (Array.isArray(item?.images) ? item.images : [])
.map(url => String(url || '').trim())
.filter(url => !!url);
const snapshotSingleImage = String(snapshot?.image || snapshot?.pic || '').trim();
const images = stockImages.length
? stockImages
: (snapshotImages.length
? snapshotImages
: (snapshotSingleImage ? [snapshotSingleImage] : itemImages));
const imageUrl = images.length > 0 ? String(images[0] || '') : '';
const planQty = this.toPositiveNumber(stockItem?.plan_qty ?? item?.plan_qty, 0);
const scannedQty = this.toPositiveNumber(item?.scanned_qty ?? item?.finish_qty ?? item?.scannedQty ?? 0, 0);
const stockName = stockItem ? String(stockItem.item_name || '').trim() : '';
const stockBarcodes = stockItem ? (Array.isArray(stockItem.barcodes) ? stockItem.barcodes : []) : [];
return {
id: String(item?.id || stockItem?.stock_id || `${this.detailInfo.recordId || 'record'}-${index + 1}`),
lineNo: this.toPositiveNumber(item?.order_line_no, index + 1),
planQty,
scannedQty,
packageRequirement: String(item?.packing_requirements || item?.package_requirement || item?.packageRequirement || item?.packing_requirement || '').trim() || '--',
skuCode: String(stockItem?.item_code || item?.item_code || snapshot?.item_code || ''),
skuName: stockName || String(snapshot?.item_name || item?.item_name || '--'),
location: String(stockItem?.sku_property || snapshot?.sku_property || item?.sku_property || '--'),
barcode: stockBarcodes.length > 0 ? stockBarcodes.join(', ') : String(snapshot?.barcode || snapshot?.item_code || item?.item_code || '--'),
barcodes: stockBarcodes.length > 0 ? stockBarcodes : (snapshot?.barcode ? [snapshot.barcode] : []),
imageUrl,
images,
pickedQty: 0
};
});
},
getCurrentGoodsImageList() {
const list = Array.isArray(this.currentGoods?.images) ? this.currentGoods.images : [];
const normalizedList = list
.map(url => String(url || '').trim())
.filter(url => !!url);
const currentUrl = String(this.currentGoods?.imageUrl || '').trim();
if (!normalizedList.length && currentUrl) {
return [currentUrl];
}
return normalizedList;
},
getCurrentGoodsImageThumbList() {
return this.getCurrentGoodsImageList().slice(0, 4);
},
getCurrentGoodsImageGridList() {
const list = this.getCurrentGoodsImageList().slice(0, 4);
while (list.length < 4) {
list.push('');
}
return list.map(url => ({ url }));
},
getCurrentGoodsExtraImageCount() {
const total = this.getCurrentGoodsImageList().length;
return total > 4 ? total - 4 : 0;
},
togglePickListSection() {
this.showPickListSection = !this.showPickListSection;
},
async handleIntercept() {
const orderId = Number(this.detailInfo?.orderId || 0);
if (!orderId) {
uni.showToast({ title: '缺少订单ID', icon: 'none' });
return;
}
uni.showModal({
title: '确认拦截',
content: `⚠️确认对订单 ID ${orderId} 执行拦截操作?`,
success: async (res) => {
if (!res.confirm) return;
uni.showLoading({ title: '拦截中...' });
try {
await this.$http('order.recheckOrder.confirmIntercept', {
order_id: orderId
});
uni.hideLoading();
uni.showToast({ title: '已确认拦截', icon: 'success' });
uni.$emit('orderInterceptCompleted', { orderId });
setTimeout(() => {
uni.navigateBack({ delta: 1 });
}, 1500);
} catch (error) {
uni.hideLoading();
const message = String(error?.message || error?.msg || error?.errMsg || '拦截失败');
uni.showToast({ title: message, icon: 'none' });
}
}
});
},
handleComplete() {
if (this.isRecheckFinished) {
uni.showToast({ title: '该订单已复核完成', icon: 'none' });
return;
}
if (!this.canConfirmRecheck) {
uni.showToast({ title: '请先完成所有商品条码扫描和数量核对', icon: 'none' });
return;
}
this.confirmRecheck();
},
getApiErrorMessage(error, fallback = '确认复核失败') {
const message = error?.message || error?.msg || error?.errMsg || error?.data?.message;
return String(message || fallback);
},
async confirmRecheck() {
if (this.confirmingRecheck) {
return;
}
const listType = String(this.detailInfo?.listType || '').trim();
let params;
if (listType === 'group') {
const waveId = String(this.detailInfo?.waveId || '').trim();
if (!waveId) {
uni.showToast({
title: '缺少波次ID',
icon: 'none'
});
return;
}
params = { wave_id: waveId };
} else {
const orderId = Number(this.detailInfo?.orderId || 0);
if (!orderId) {
uni.showToast({
title: '缺少订单ID',
icon: 'none'
});
return;
}
params = { order_id: orderId };
}
this.confirmingRecheck = true;
uni.showLoading({
title: '确认复核中...'
});
console.log('[confirmRecheck] 请求参数:', JSON.stringify(params));
try {
const response = await this.$http('order.recheckOrder.confirmRecheck', params);
console.log('[confirmRecheck] 返回数据:', JSON.stringify(response));
uni.showToast({
title: '已确认复核',
icon: 'success'
});
// 通知订单复核页面更新列表状态
const reviewCompletedData = {
orderId: this.detailInfo.orderId,
waveNo: this.detailInfo.waveNo,
waveId: this.detailInfo.waveId,
listType: this.detailInfo.listType
};
uni.$emit('orderReviewCompleted', reviewCompletedData);
try {
uni.setStorageSync('pendingReviewComplete', reviewCompletedData);
} catch (e) {
console.warn('[confirmRecheck] 缓存复核完成数据失败:', e);
}
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 1500);
} catch (error) {
uni.showToast({
title: this.getApiErrorMessage(error, '确认复核失败'),
icon: 'none'
});
} finally {
this.confirmingRecheck = false;
uni.hideLoading();
}
},
buildPrintRequestCode() {
const timePart = Date.now().toString(36);
const randomPart = Math.random().toString(36).slice(2, 10);
return `PRINT_${timePart}_${randomPart}`;
},
extractPrintRecordList(response) {
const list = response?.data?.list || response?.data?.data?.list;
return Array.isArray(list) ? list : [];
},
normalizePrintStations(list) {
return list
.map(item => {
const source = item && typeof item === 'object' ? item : {};
const id = String(source.id ?? source.print_station_id ?? source.printStationId ?? '').trim();
const name = String(source.name || source.station_name || source.print_station_name || '').trim();
return { id, name };
})
.filter(item => !!item.id && !!item.name);
},
async handleReprint() {
const listType = String(this.detailInfo?.listType || '').trim();
// 根据 listType 构建 order_ids 参数
let orderIdsParam;
if (listType === 'group') {
// 团单模式:使用 data.list[X].order_ids
orderIdsParam = this.detailInfo.orderIds;
if (!Array.isArray(orderIdsParam) || orderIdsParam.length === 0) {
uni.showToast({ title: '缺少波次订单ID列表', icon: 'none' });
return;
}
} else {
// 散单/详情模式:使用 data.list[X].order_id
const orderId = Number(this.detailInfo?.orderId || 0);
if (!orderId) {
uni.showToast({ title: '缺少订单ID', icon: 'none' });
return;
}
orderIdsParam = [orderId];
}
uni.showLoading({ title: '处理打印中...' });
try {
// 1. 获取打印数据
const printDataResponse = await this.$http('order.print.getOrderPrintData', { order_ids: orderIdsParam });
const printDataPayload = printDataResponse?.data?.data || printDataResponse?.data || printDataResponse?.result || {};
const waveGroups = Array.isArray(printDataPayload?.waveGroups)
? printDataPayload.waveGroups
: (printDataPayload && typeof printDataPayload === 'object' ? [printDataPayload] : []);
if (!waveGroups.length) {
throw new Error('未获取到可打印数据');
}
// 2. 获取打印台列表,使用第一个可用打印台
const stationResponse = await this.$http('print.getList', { page: 1, pageSize: 20, where: {} });
const stationList = this.normalizePrintStations(this.extractPrintRecordList(stationResponse));
if (!stationList.length) {
throw new Error('无可用的打印台');
}
const printStation = stationList[0];
// 3. 发送打印
const requestCode = this.buildPrintRequestCode();
const sendParams = {
type: 'express',
printStationId: printStation.id,
requestCode,
data: { waveGroups }
};
const sendResponse = await this.$http('print.send', sendParams);
const success = sendResponse?.flag !== 'failure' && sendResponse?.code !== '500' && sendResponse?.code !== 500;
if (!success) {
throw new Error(sendResponse?.message || sendResponse?.msg || '打印发送失败');
}
uni.hideLoading();
uni.showToast({ title: '面单补打已发送', icon: 'success' });
} catch (error) {
uni.hideLoading();
const message = String(error?.message || error?.msg || error?.errMsg || '打印失败');
uni.showToast({ title: message, icon: 'none' });
}
},
handleWeigh() {
this.weighWeight = 0;
this.showWeighPopup = true;
},
weighIncrement() {
this.weighWeight = Math.round((this.weighWeight + 0.1) * 10) / 10;
},
weighDecrement() {
const val = Math.round((this.weighWeight - 0.1) * 10) / 10;
this.weighWeight = val < 0 ? 0 : val;
},
handleWeighInput(e) {
const raw = String(e?.detail?.value || '').trim();
if (raw === '') {
this.weighWeight = 0;
return;
}
const num = parseFloat(raw);
if (Number.isFinite(num) && num >= 0) {
this.weighWeight = Math.round(num * 1000) / 1000;
} else {
this.weighWeight = 0;
}
},
async handleWeighSave() {
if (this.weighWeight <= 0) {
uni.showToast({ title: '请输入重量', icon: 'none' });
return;
}
const listType = String(this.detailInfo?.listType || '').trim();
const weighingWeight = this.weighWeight;
uni.showLoading({ title: '提交称重中...' });
try {
if (listType === 'group') {
// 团单模式:传 order_id(值为波次ID,数值型)
const waveId = Number(this.detailInfo.waveId || 0);
if (!waveId) {
uni.hideLoading();
uni.showToast({ title: '缺少波次ID', icon: 'none' });
return;
}
await this.$http('order.recheckOrder.updateExpressWeighingWeight', {
order_id: waveId,
weighing_weight: weighingWeight
});
} else {
// 散单/详情模式:传 order_id
const orderId = Number(this.detailInfo?.orderId || 0);
if (!orderId) {
uni.hideLoading();
uni.showToast({ title: '缺少订单ID', icon: 'none' });
return;
}
await this.$http('order.recheckOrder.updateExpressWeighingWeight', {
order_id: orderId,
weighing_weight: weighingWeight
});
}
uni.hideLoading();
uni.showToast({ title: '称重完成', icon: 'success' });
this.showWeighPopup = false;
} catch (error) {
uni.hideLoading();
const message = String(error?.message || error?.msg || error?.errMsg || '称重提交失败');
uni.showToast({ title: message, icon: 'none' });
}
},
getStatusText(status) {
const map = {
pending: '待拣货',
picking: '拣货中',
done: '已完成'
};
return map[status] || '待拣货';
},
buildMockGoodsList() {
return Array.from({ length: 5 }).map((_, index) => ({
id: `${this.detailInfo.recordId || 'record'}-${index + 1}`,
lineNo: (index % 4) + 1,
planQty: (index % 6) + 2,
scannedQty: 0,
packageRequirement: '--',
skuCode: `SKU${String(index + 1).padStart(4, '0')}`,
skuName: `模拟商品${index + 1}`,
location: `A-${String(index + 1).padStart(2, '0')}`,
barcode: `6900000000${String(index + 1).padStart(3, '0')}`,
imageUrl: '',
images: [],
pickedQty: 0
}));
},
previewCurrentGoodsImage() {
const imageList = Array.isArray(this.currentGoods?.images)
? this.currentGoods.images.filter(url => String(url || '').trim())
: [];
const currentUrl = String(this.currentGoods?.imageUrl || '').trim();
const urls = imageList.length ? imageList : (currentUrl ? [currentUrl] : []);
if (!urls.length) {
uni.showToast({
title: '暂无图片可预览',
icon: 'none'
});
return;
}
uni.previewImage({
current: currentUrl || urls[0],
urls
});
},
selectGoods(index) {
const next = Number(index);
if (Number.isNaN(next) || next < 0 || next >= this.goodsList.length) {
return;
}
this.currentGoodsIndex = next;
},
showPrevGoods() {
if (!this.hasPrevGoods) {
return;
}
this.currentGoodsIndex -= 1;
},
showNextGoods() {
if (!this.hasNextGoods) {
return;
}
this.currentGoodsIndex += 1;
}
}
};
</script>
<style lang="scss" scoped>
.scatter-pick-goods-detail-page {
min-height: 100vh;
background: #f8f9fa;
}
::v-deep .nav-title .right {
width: auto;
min-width: 90rpx;
display: flex;
justify-content: flex-end;
}
.nav-right-complete {
font-size: 32rpx;
line-height: 36rpx;
color: #ffffff;
padding: 8rpx 18rpx;
border-radius: 6rpx;
background: #07c160;
}
.nav-right-complete--disabled {
background: #c0c4cc;
pointer-events: none;
}
.nav-right-complete--intercept {
background: #f56c6c;
}
.page-head {
margin: 20rpx 24rpx 0;
padding: 16rpx;
background: #fff;
border-radius: 12rpx;
}
.page-head-row {
display: flex;
align-items: center;
}
.page-head-row--top {
margin-bottom: 10rpx;
}
.page-head-row--wave {
margin-bottom: 10rpx;
}
.page-head-row--bottom {
justify-content: space-between;
}
.page-head-label {
font-size: 28rpx;
color: #909399;
flex-shrink: 0;
}
.page-head-wave {
font-size: 28rpx;
color: #303133;
font-weight: 500;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.page-head-value {
font-size: 32rpx;
font-weight: 600;
color: #303133;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.page-head-picker {
font-size: 26rpx;
color: #909399;
}
.page-head-actions {
display: flex;
gap: 12rpx;
flex-shrink: 0;
}
.page-head-actions {
gap: 20rpx;
}
.page-head-btn {
font-size: 30rpx;
color: #ffffff;
padding: 12rpx 24rpx;
border: none;
border-radius: 10rpx;
background: #fa8c16;
white-space: nowrap;
}
.page-head-btn--primary {
background: #2979ff;
}
.page-head-btn:active {
opacity: 0.7;
}
.page-head-item {
flex: 1;
display: flex;
align-items: center;
min-width: 0;
}
.page-head-value {
margin-left: 8rpx;
font-size: 36rpx;
line-height: 46rpx;
font-weight: 600;
color: #303133;
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.goods-row {
display: flex;
flex-wrap: nowrap;
width: 100%;
margin-top: 14rpx;
font-size: 32rpx;
line-height: 54rpx;
}
.goods-row--barcode-highlight {
background: #f0fff4;
border: 1rpx solid #b7eb8f;
border-radius: 8rpx;
padding: 0 10rpx;
}
.goods-row--barcode-highlight .label,
.goods-row--barcode-highlight .value {
color: #52c41a;
}
.goods-row--scanned-complete {
background: #f0fff4;
border: 1rpx solid #b7eb8f;
border-radius: 8rpx;
padding: 0 10rpx;
}
.goods-row--scanned-complete .qty-item .label,
.goods-row--scanned-complete .qty-item .value {
color: #52c41a;
}
.goods-row--scanned-complete .qty-divider {
background: #b7eb8f;
}
.goods-row:first-child {
margin-top: 0;
}
.goods-row--quantity {
align-items: center;
}
.goods-row--quantity .value {
flex: 0;
margin-right: 12rpx;
}
.goods-row--qty {
display: flex;
flex-direction: row;
align-items: center;
gap: 0;
}
.goods-row--qty .qty-item {
display: flex;
align-items: center;
flex: 1;
min-width: 0;
}
.goods-row--qty .qty-item .label {
width: auto;
min-width: auto;
flex-shrink: 0;
}
.goods-row--qty .qty-item .value {
flex: 1;
min-width: 0;
}
.qty-divider {
width: 1rpx;
height: 28rpx;
background: #dcdfe6;
margin: 0 16rpx;
flex-shrink: 0;
}
.label {
width: 110rpx;
min-width: 110rpx;
color: #909399;
display: inline-flex;
align-items: center;
white-space: nowrap !important;
word-break: keep-all;
overflow-wrap: normal;
overflow: hidden;
text-overflow: ellipsis;
flex-shrink: 0;
}
.label--package {
width: 170rpx;
min-width: 170rpx;
}
.value {
flex: 1;
color: #303133;
}
.goods-scroll {
height: calc(100vh - 350rpx - env(safe-area-inset-bottom));
padding: 0 24rpx;
box-sizing: border-box;
}
.content-layout {
display: flex;
flex-direction: column;
padding: 0 24rpx;
flex: 1;
min-height: 0;
box-sizing: border-box;
}
.top-module {
flex: 0 0 auto;
margin-top: 16rpx;
}
.top-card {
background: #fff;
border-radius: 12rpx;
padding: 16rpx;
border: 1rpx solid #ebeef5;
}
.top-main {
display: flex;
flex-direction: column;
align-items: stretch;
}
.goods-image-name-row {
display: flex;
align-items: center;
gap: 16rpx;
}
.goods-thumb {
width: 240rpx;
height: 240rpx;
flex-shrink: 0;
}
.goods-image {
width: 240rpx;
height: 240rpx;
flex-shrink: 0;
border-radius: 10rpx;
overflow: hidden;
background: #f5f7fa;
}
.goods-image-grid {
width: 240rpx;
height: 240rpx;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
}
.grid-cell {
position: relative;
width: 116rpx;
height: 116rpx;
border-radius: 10rpx;
overflow: hidden;
background: #f5f7fa;
}
.grid-cell--empty {
border: 1rpx dashed #dcdfe6;
box-sizing: border-box;
background: #fafafa;
}
.grid-image {
width: 100%;
height: 100%;
border-radius: 10rpx;
overflow: hidden;
}
.image-placeholder {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
}
.image-placeholder--large {
height: 240rpx;
}
.image-placeholder--small {
height: 116rpx;
}
.image-placeholder--empty {
background: #fafafa;
}
.more-mask {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 0, 0, 0.35);
}
.more-text {
font-size: 34rpx;
line-height: 1;
color: #ffffff;
font-weight: 600;
}
.goods-name {
flex: 1;
min-width: 0;
font-size: 38rpx;
line-height: 52rpx;
font-weight: 700;
color: #303133;
}
.top-info {
width: 100%;
margin-top: 22rpx;
}
.goods-row--pick-btn {
margin-top: 12rpx;
justify-content: flex-end;
}
.pick-list-title-btn {
margin-top: 0;
margin-left: auto;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 30rpx;
line-height: 1.2;
font-weight: 500;
color: #ffffff;
background: #2979ff;
border-radius: 10rpx;
padding: 12rpx 24rpx;
}
.pick-list-scroll {
margin-top: 8rpx;
width: 100%;
}
.pick-list {
display: flex;
align-items: center;
width: 100%;
}
.pick-item-wrap {
display: flex;
align-items: center;
width: calc((100% - 64rpx) / 5);
margin-right: 16rpx;
}
.pick-item-wrap:nth-child(5n) {
margin-right: 0;
}
.metric-card-btn {
position: relative;
display: flex;
align-items: stretch;
justify-content: center;
width: 100%;
height: 72rpx;
padding: 0;
border-radius: 10rpx;
background: #f2f3f5;
border: 2rpx solid transparent;
overflow: hidden;
}
.metric-card-btn--active {
background: #eaf2ff;
border-color: #2979ff;
}
.metric-card-btn--matched {
background: #f6ffed;
border-color: #52c41a;
}
.order-corner {
position: absolute;
left: 0;
top: 0;
width: 0;
height: 0;
border-top: 16rpx solid #19be6b;
border-right: 16rpx solid transparent;
}
.metric-diagonal {
position: absolute;
left: -10rpx;
top: 50%;
width: calc(100% + 20rpx);
height: 2rpx;
background: #dcdfe6;
transform: rotate(-28deg);
transform-origin: center;
}
.metric-order {
position: absolute;
left: 8rpx;
top: 6rpx;
font-size: 30rpx;
line-height: 38rpx;
font-weight: 600;
color: #606266;
}
.metric-product {
position: absolute;
right: 8rpx;
bottom: 4rpx;
font-size: 38rpx;
line-height: 46rpx;
font-weight: 700;
color: #2979ff;
}
.metric-scanned {
position: absolute;
left: 8rpx;
bottom: 4rpx;
font-size: 28rpx;
line-height: 36rpx;
color: #19be6b;
}
.switch-row {
margin-top: 14rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.switch-index {
font-size: 28rpx;
line-height: 38rpx;
color: #606266;
}
.bottom-module {
flex: 1;
min-height: 0;
margin-top: 12rpx;
overflow: hidden;
}
.bottom-module-title {
font-size: 32rpx;
line-height: 46rpx;
font-weight: 600;
color: #303133;
margin-bottom: 8rpx;
}
.bottom-summary {
padding: 16rpx 24rpx;
padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
background: #ffffff;
border-top: 1rpx solid #ebeef5;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: space-between;
}
.bottom-summary-text {
font-size: 28rpx;
color: #909399;
}
.bottom-summary-scan {
font-size: 28rpx;
color: #909399;
}
.bottom-summary-split {
font-size: 28rpx;
color: #909399;
margin: 0 2rpx;
}
.bottom-summary-total {
font-size: 28rpx;
color: #909399;
}
.bottom-summary-value {
font-size: 32rpx;
font-weight: 600;
color: #2979ff;
}
.empty-state {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.empty-state--content {
height: calc(100vh - 350rpx - env(safe-area-inset-bottom));
margin: 0 24rpx;
}
.empty-text {
margin-top: 18rpx;
font-size: 32rpx;
color: #909399;
}
.safe-area-bottom {
height: calc(30rpx + env(safe-area-inset-bottom));
}
.weigh-popup {
width: 560rpx;
padding: 24rpx 36rpx 36rpx;
box-sizing: border-box;
}
.weigh-popup-title {
font-size: 34rpx;
font-weight: 400;
color: #303133;
text-align: left;
line-height: 1;
padding-top: 8rpx;
margin-bottom: 28rpx;
}
.weigh-popup-body {
margin: 20rpx 0 48rpx;
}
.weigh-row {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 24rpx;
}
.weigh-label {
font-size: 30rpx;
color: #606266;
}
.weigh-required {
color: #f56c6c;
}
.weigh-control {
display: flex;
align-items: center;
gap: 0;
}
.weigh-btn {
width: 60rpx;
height: 76rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 36rpx;
font-weight: 400;
color: #606266;
background: #f5f7fa;
border: 2rpx solid #dcdfe6;
user-select: none;
box-sizing: border-box;
}
.weigh-btn--minus {
border-radius: 10rpx 0 0 10rpx;
border-right: none;
}
.weigh-btn--plus {
border-radius: 0 10rpx 10rpx 0;
border-left: none;
}
.weigh-btn:active {
background: #e8eaed;
}
.weigh-input {
width: 200rpx;
height: 76rpx;
font-size: 36rpx;
font-weight: 500;
color: #303133;
text-align: center;
background: #ffffff;
border: 2rpx solid #dcdfe6;
border-left: none;
border-right: none;
border-radius: 0;
padding: 0;
box-sizing: border-box;
}
.weigh-unit {
font-size: 30rpx;
color: #909399;
margin-left: 16rpx;
}
.weigh-popup-footer {
display: flex;
gap: 24rpx;
}
.weigh-footer-btn {
flex: 1;
height: 72rpx;
border-radius: 10rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 28rpx;
font-weight: 500;
}
.weigh-footer-btn:active {
opacity: 0.7;
}
.weigh-footer-btn--cancel {
background: #f4f4f5;
color: #909399;
}
.weigh-footer-btn--save {
background: #2979ff;
color: #ffffff;
}
</style>