feat(B2B): 备货/提货流程优化并升级版本至 1.0.145

- 备货列表(stockPreparation.vue):
  - 顶部搜索占位与查询改为按运单号精确匹配(waybill_codes eq)
  - 卡片新增发货单号、提货车牌、备货照片缩略图及点击预览
  - 接入扫码广播回调(setCallbacks/start/resume/pause/stop)

- 备货详情(stockPreparationDetail.vue):
  - 商品行名称与编码合并为 formatItemName 显示
  - 底部操作栏改用自绘按钮,新增取消/完成备货、分箱校验三个确认弹窗
  - 新增分箱校验 validatePacking:同商品箱号去重、合计数量超量/不足拦截
  - 取消/完成备货增加语音播报
  - onBackPress 拦截返回并提示,新增 navigateBackSafely 兜底重试

- 提货操作(pickupOperation.vue):
  - 新增车牌拍照识别(OCR)并回填车牌号
  - 提货成功/失败增加语音播报
  - 接入扫码广播回调

- 发版:package.json version、manifest.json versionName/versionCode 同步升至 1.0.145 / 1000145
This commit is contained in:
zm2000 2026-11-20 17:28:58 +08:00
parent 9b2d14dd12
commit 2399a2a4a0
5 changed files with 849 additions and 133 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wms-pda",
"version": "1.0.144",
"version": "1.0.145",
"private": true,
"description": "天豹云仓 WMS_PDA(uni-app Vue2 + @vue/cli 4.5)",
"scripts": {

View File

@ -2,8 +2,8 @@
"name" : "WMS_PDA",
"appid" : "__UNI__0B3DAD3",
"description" : "多平台快速开发的UI框架",
"versionName" : "1.0.144",
"versionCode" : 1000144,
"versionName" : "1.0.145",
"versionCode" : 1000145,
"transformPx" : false,
"app-plus" : {
"statusbar" : {

View File

@ -6,7 +6,7 @@
<view class="search-panel">
<SearchBar
v-model="keyword"
placeholder="扫码/输入运单号或发货单号"
placeholder="扫码/输入运单号"
:input-font-size="'34rpx'"
:search-text-font-size="'34rpx'"
@search="handleSearch"
@ -46,7 +46,7 @@
@click="handleCardClick(item)"
>
<view class="card-header">
<text class="order-code">{{ getDeliveryOrderCode(item) }}</text>
<text class="order-code">{{ getWaybillText(item) }}</text>
<text v-if="isUrgent(item)" class="badge badge--urgent">加急</text>
<text v-if="hasSn(item)" class="badge badge--sn">含SN</text>
<view class="pickup-tag">
@ -59,54 +59,60 @@
<text class="info-label">货主:</text>
<text class="info-value">{{ getStoreOwner(item) }}</text>
</view>
<view class="info-row">
<text class="info-label">发货单号:</text>
<text class="info-value">{{ getDeliveryOrderCode(item) }}</text>
</view>
<view class="info-row">
<text class="info-label">总箱数:</text>
<text class="info-value">{{ item.total_box_count || 0 }}</text>
</view>
<view class="info-row">
<text class="info-label">提货车牌号:</text>
<text class="info-value">{{ item.pickup_plate_number || '--' }}</text>
<text class="info-label">备货人:</text>
<text class="info-value">{{ getPrepOperatorName(item) }}</text>
</view>
<view class="info-row">
<text class="info-label">备货备注:</text>
<text class="info-value">{{ item.prep_remark || '--' }}</text>
</view>
<view class="info-row">
<text class="info-label">提货车牌:</text>
<text class="info-value">{{ item.pickup_plate_number || '--' }}</text>
</view>
<view v-if="getPrepImages(item).length > 0" class="photo-row">
<text class="info-label">备货照片:</text>
<view class="photo-thumbs">
<image
v-for="(img, imgIndex) in getPrepImages(item)"
:key="'prep-' + imgIndex"
:src="img.url"
class="photo-thumb"
mode="aspectFill"
@click.stop="previewImages(getPrepImages(item), imgIndex)"
></image>
</view>
</view>
<view v-if="getPickupStatus(item) === 'Y' && getPickupImages(item).length > 0" class="photo-row">
<text class="info-label">提货照片:</text>
<view class="photo-thumbs">
<image
v-for="(img, imgIndex) in getPickupImages(item)"
:key="'pick-' + imgIndex"
:src="img.url"
class="photo-thumb"
mode="aspectFill"
@click.stop="previewImages(getPickupImages(item), imgIndex)"
></image>
</view>
</view>
<view v-if="getPickupStatus(item) === 'Y'" class="info-row">
<text class="info-label">提货时间:</text>
<text class="info-value">{{ formatDateTime(item.picked_up_at) }}</text>
</view>
<template v-if="getPickupStatus(item) === 'Y'">
<view class="info-row">
<text class="info-label">备货人:</text>
<text class="info-value">{{ getPrepOperatorName(item) }}</text>
</view>
<view v-if="getPrepImages(item).length > 0" class="photo-row">
<text class="info-label">备货照片:</text>
<view class="photo-thumbs">
<image
v-for="(img, imgIndex) in getPrepImages(item)"
:key="'prep-' + imgIndex"
:src="img.url"
class="photo-thumb"
mode="aspectFill"
@click.stop="previewImages(getPrepImages(item), imgIndex)"
></image>
</view>
</view>
<view v-if="getPickupImages(item).length > 0" class="photo-row">
<text class="info-label">提货照片:</text>
<view class="photo-thumbs">
<image
v-for="(img, imgIndex) in getPickupImages(item)"
:key="'pick-' + imgIndex"
:src="img.url"
class="photo-thumb"
mode="aspectFill"
@click.stop="previewImages(getPickupImages(item), imgIndex)"
></image>
</view>
</view>
</template>
</view>
<view class="card-footer">
<text class="footer-time">创建:{{ getOrderCreateAt(item) }}</text>
<view v-else class="info-row">
<text class="info-label">备货时间:</text>
<text class="info-value">{{ formatDateTime(item.prep_at) }}</text>
</view>
</view>
</view>
@ -166,8 +172,8 @@
placeholder-class="plate-placeholder"
/>
</view>
<view class="scan-btn" @click="scanPlateNumber">
<u-icon name="scan" size="22" color="#2979ff"></u-icon>
<view class="scan-btn" @click="capturePlateNumber">
<u-icon name="camera" size="22" color="#2979ff"></u-icon>
</view>
</view>
<view class="photo-card">
@ -225,13 +231,22 @@
currentOrder: null,
plateNumber: '',
pickupPhotoList: [],
submitting: false
submitting: false,
recognizingPlate: false
}
},
onLoad() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
this.fetchList();
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
// 从详情页返回时刷新(首次进入由 onLoad 拉取,避免重复)
if (this._hasShown) {
this.currentPage = 1;
@ -239,6 +254,12 @@
}
this._hasShown = true;
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
},
computed: {
currentOrderDeliveryCode() {
return this.getDeliveryOrderCode(this.currentOrder);
@ -257,6 +278,71 @@
}
},
methods: {
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[pickupOperation] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[pickupOperation] broadcast/${action} 调用异常:`, error);
}
},
speakMessage(message, options = {}) {
const text = String(message || '').trim();
if (!text) {
return;
}
const tools = this.$tools;
if (!tools || typeof tools.speakText !== 'function') {
return;
}
try {
const task = tools.speakText(text, options);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn('[pickupOperation] 语音播报失败:', error);
});
}
} catch (error) {
console.warn('[pickupOperation] 语音播报异常:', error);
}
},
normalizeUniScanResult(scanResult) {
if (!scanResult) {
return '';
}
if (typeof scanResult === 'string') {
return scanResult.trim();
}
if (typeof scanResult.result === 'string') {
return scanResult.result.trim();
}
if (Array.isArray(scanResult.result)) {
const firstResult = scanResult.result.find(item => item);
if (typeof firstResult === 'string') {
return firstResult.trim();
}
if (firstResult && typeof firstResult.data === 'string') {
return firstResult.data.trim();
}
}
if (typeof scanResult.data === 'string') {
return scanResult.data.trim();
}
return '';
},
handleBroadcastResult(result) {
const rawCode = this.normalizeUniScanResult(result);
if (!rawCode) {
return;
}
this.keyword = rawCode;
this.currentPage = 1;
this.fetchList();
},
async fetchList() {
this.loading = true;
try {
@ -268,19 +354,20 @@
const where = {};
// 提货作业仅处理已完成备货的订单
where.prep_status = 'fin';
if (keyword) {
where.waybill_codes = {
operator: 'eq',
type: 'text',
value: keyword
};
}
// 提货状态筛选(简写结构)
if (this.pickupStatusTab) {
where.is_picked_up = this.pickupStatusTab;
}
// 已提货走配送订单列表(dispatch/m4),待提货走待处理 B2B 列表
const isPickedUp = this.pickupStatusTab === 'Y';
if (keyword) {
// 顶部搜索按运单号精确查询(与备货作业/order-review 列表一致)
where.waybill_codes = {
operator: 'eq',
type: 'text',
value: keyword
};
}
const apiName = isPickedUp ? 'order.deliveryOrder2b.list' : 'order.pendingOrder2b.list';
const sort = isPickedUp
? { sortField: 'delivery_time', sortOrder: 'DESC' }
@ -390,6 +477,20 @@
if (!item || typeof item !== 'object') return '--';
return item.store_remark || '--';
},
getWaybillCodes(item) {
const raw = item?.waybill_codes ?? item?.express_numbers;
if (Array.isArray(raw)) {
return raw.map(String).filter(Boolean);
}
if (typeof raw === 'string' && raw.trim()) {
return raw.split(/[,,]/).map(s => s.trim()).filter(Boolean);
}
return [];
},
getWaybillText(item) {
const codes = this.getWaybillCodes(item);
return codes.length > 0 ? codes.join(' / ') : '--';
},
getOrderCreateAt(item) {
return this.formatDateTime(item?.created_at ?? item?.create_at);
},
@ -481,18 +582,197 @@
this.plateNumber = '';
this.pickupPhotoList = [];
},
scanPlateNumber() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
success: (res) => {
const code = String(res?.result || '').trim();
if (!code) return;
this.plateNumber = code;
},
fail: () => {}
getPlatformInfo() {
const systemInfo = typeof uni.getSystemInfoSync === 'function' ? uni.getSystemInfoSync() : {};
return {
platform: systemInfo.platform || 'unknown',
uniPlatform: systemInfo.uniPlatform || 'unknown',
system: systemInfo.system || '',
model: systemInfo.model || '',
appVersion: systemInfo.appVersion || ''
};
},
arrayBufferToBase64(buffer) {
if (uni.arrayBufferToBase64) {
return uni.arrayBufferToBase64(buffer);
}
let binary = '';
const bytes = new Uint8Array(buffer);
const length = bytes.byteLength;
for (let i = 0; i < length; i += 1) {
binary += String.fromCharCode(bytes[i]);
}
if (typeof btoa === 'function') {
return btoa(binary);
}
throw new Error('当前环境不支持 ArrayBuffer 转 Base64');
},
readFileBase64ByPlus(filePath) {
return new Promise((resolve, reject) => {
if (typeof plus === 'undefined' || !plus.io || !plus.io.resolveLocalFileSystemURL) {
reject(new Error('PLUS 文件系统不可用'));
return;
}
plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
entry.file((file) => {
const reader = new plus.io.FileReader();
reader.onloadend = (event) => {
const result = String(event?.target?.result || event?.result || '');
resolve(result.replace(/^data:.*?;base64,/, ''));
};
reader.onerror = (error) => reject(error);
reader.readAsDataURL(file);
}, reject);
}, reject);
});
},
readFileBase64ByRequest(filePath) {
return new Promise((resolve, reject) => {
uni.request({
url: filePath,
method: 'GET',
responseType: 'arraybuffer',
success: (res) => {
try {
resolve(this.arrayBufferToBase64(res.data));
} catch (error) {
reject(error);
}
},
fail: (error) => reject(error)
});
});
},
async getImageBase64(filePath) {
const tryByFileSystemManager = () => new Promise((resolve, reject) => {
try {
const fileSystemManager = uni.getFileSystemManager && uni.getFileSystemManager();
if (!fileSystemManager || typeof fileSystemManager.readFile !== 'function') {
reject(new Error('getFileSystemManager.readFile 不可用'));
return;
}
fileSystemManager.readFile({
filePath,
encoding: 'base64',
success: ({ data }) => resolve(String(data || '')),
fail: (error) => reject(error)
});
} catch (error) {
reject(error);
}
});
return new Promise((resolve, reject) => {
if (!filePath) {
reject(new Error('图片路径无效'));
return;
}
tryByFileSystemManager()
.then(resolve)
.catch((fileSystemError) => {
console.warn('[pickupOperation] getFileSystemManager 分支失败:', fileSystemError);
this.readFileBase64ByPlus(filePath)
.then(resolve)
.catch((plusError) => {
console.warn('[pickupOperation] plus.io.FileReader 分支失败:', plusError);
this.readFileBase64ByRequest(filePath)
.then(resolve)
.catch((requestError) => {
console.error('[pickupOperation] uni.request(arraybuffer) 分支失败:', requestError);
reject(requestError);
});
});
});
});
},
extractLicensePlate(response) {
if (!response) {
return '';
}
const directFields = [
response.license_plate,
response.licensePlate,
response.plate_number,
response.plateNo,
response.plate_number_text,
response.number
];
const directMatch = directFields.find(value => typeof value === 'string' && value.trim());
if (directMatch) {
return directMatch.trim();
}
const data = response.data;
if (data && typeof data === 'object') {
return this.extractLicensePlate(data);
}
if (Array.isArray(data) && data.length) {
return this.extractLicensePlate(data[0]);
}
return '';
},
async capturePlateNumber() {
if (this.recognizingPlate) {
return;
}
try {
const chooseResult = await new Promise((resolve, reject) => {
uni.chooseImage({
count: 1,
sourceType: ['camera'],
sizeType: ['compressed'],
success: resolve,
fail: reject
});
});
const filePath = chooseResult?.tempFilePaths?.[0] || chooseResult?.tempFiles?.[0]?.path;
if (!filePath) {
throw new Error('未获取到拍照文件');
}
this.recognizingPlate = true;
uni.showLoading({ title: '识别车牌中', mask: true });
const imageBase64 = await this.getImageBase64(filePath);
if (!imageBase64) {
throw new Error('图片转换失败');
}
const result = await this.$http('common.recognizeLicensePlate', {
image_base64: imageBase64
}, '', false);
console.log('[pickupOperation] 车牌识别接口返回:', result);
const licensePlate = this.extractLicensePlate(result);
if (!licensePlate) {
throw new Error((result && result.message) || '未识别到车牌号');
}
this.plateNumber = licensePlate;
uni.showToast({ title: '识别成功', icon: 'success' });
this.speakMessage(`识别成功,车牌:${licensePlate}`);
} catch (error) {
const errMsg = String(error?.errMsg || error?.message || error || '').toLowerCase();
if (errMsg.includes('cancel')) {
return;
}
uni.showToast({ title: (error && error.message) || '车牌识别失败', icon: 'none' });
} finally {
this.recognizingPlate = false;
uni.hideLoading();
}
},
handleConfirmPickup() {
const orderId = Number(this.currentOrder?.id || 0);
if (!orderId) {
@ -542,9 +822,11 @@
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '提货失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
this.speakMessage(msg);
return;
}
uni.showToast({ title: '提货成功', icon: 'success' });
this.speakMessage('提货成功');
this.closePickupPopup();
this.currentPage = 1;
this.fetchList();
@ -714,7 +996,7 @@
margin-left: 12rpx;
padding: 4rpx 16rpx;
border-radius: 8rpx;
font-size: 26rpx;
font-size: 36rpx;
flex-shrink: 0;
}
@ -912,7 +1194,7 @@
.photo-card__title {
font-size: 36rpx;
font-weight: 600;
font-weight: bold;
color: #303133;
}
}
@ -967,7 +1249,7 @@
.confirm-title {
font-size: 36rpx;
font-weight: 600;
font-weight: bold;
color: #303133;
}

View File

@ -6,7 +6,7 @@
<view class="search-panel">
<SearchBar
v-model="keyword"
placeholder="扫码/输入发货单号"
placeholder="扫码/输入运单号"
:input-font-size="'34rpx'"
:search-text-font-size="'34rpx'"
@search="handleSearch"
@ -46,7 +46,7 @@
@click="handleViewDetail(item)"
>
<view class="card-header">
<text class="order-code">{{ getDeliveryOrderCode(item) }}</text>
<text class="order-code">{{ getWaybillText(item) }}</text>
<text v-if="isUrgent(item)" class="badge badge--urgent">加急</text>
<text v-if="hasSn(item)" class="badge badge--sn">含SN</text>
<view class="prep-tag">
@ -59,6 +59,10 @@
<text class="info-label">货主:</text>
<text class="info-value">{{ getStoreOwner(item) }}</text>
</view>
<view class="info-row">
<text class="info-label">发货单号:</text>
<text class="info-value">{{ getDeliveryOrderCode(item) }}</text>
</view>
<view class="info-row">
<text class="info-label">总箱数:</text>
<text class="info-value">{{ item.total_box_count || 0 }}</text>
@ -71,6 +75,23 @@
<text class="info-label">备注:</text>
<text class="info-value">{{ item.prep_remark || '--' }}</text>
</view>
<view class="info-row">
<text class="info-label">提货车牌:</text>
<text class="info-value">{{ item.pickup_plate_number || '--' }}</text>
</view>
<view v-if="getPrepImages(item).length > 0" class="photo-row">
<text class="info-label">备货照片:</text>
<view class="photo-thumbs">
<image
v-for="(img, imgIndex) in getPrepImages(item)"
:key="'prep-' + imgIndex"
:src="img.url"
class="photo-thumb"
mode="aspectFill"
@click.stop="previewImages(getPrepImages(item), imgIndex)"
></image>
</view>
</view>
</view>
<view class="card-footer">
@ -126,9 +147,17 @@
}
},
onLoad() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
this.fetchList();
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
// 从详情页返回时刷新备货状态(首次进入由 onLoad 拉取,避免重复)
if (this._hasShown) {
this.currentPage = 1;
@ -136,6 +165,12 @@
}
this._hasShown = true;
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
},
computed: {
// 当前登录工号:后端 prep_operator_id 取的是当前员工工号(user.employees_id),
// 必须与备货人 prep_operator_id 同口径,不能优先取账号 user.id
@ -151,6 +186,51 @@
}
},
methods: {
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[stockPreparation] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[stockPreparation] broadcast/${action} 调用异常:`, error);
}
},
normalizeUniScanResult(scanResult) {
if (!scanResult) {
return '';
}
if (typeof scanResult === 'string') {
return scanResult.trim();
}
if (typeof scanResult.result === 'string') {
return scanResult.result.trim();
}
if (Array.isArray(scanResult.result)) {
const firstResult = scanResult.result.find(item => item);
if (typeof firstResult === 'string') {
return firstResult.trim();
}
if (firstResult && typeof firstResult.data === 'string') {
return firstResult.data.trim();
}
}
if (typeof scanResult.data === 'string') {
return scanResult.data.trim();
}
return '';
},
handleBroadcastResult(result) {
const rawCode = this.normalizeUniScanResult(result);
if (!rawCode) {
return;
}
this.keyword = rawCode;
this.currentPage = 1;
this.fetchList();
},
async fetchList() {
this.loading = true;
try {
@ -161,8 +241,10 @@
const keyword = String(this.keyword || '').trim();
const where = {};
if (keyword) {
where.delivery_order_code = {
operator: 'like',
// 顶部搜索按运单号精确查询(与 order-review 列表一致)
where.waybill_codes = {
operator: 'eq',
type: 'text',
value: keyword
};
}
@ -290,9 +372,41 @@
if (!item || typeof item !== 'object') return '--';
return item.store_remark || '--';
},
getWaybillCodes(item) {
const raw = item?.waybill_codes ?? item?.express_numbers;
if (Array.isArray(raw)) {
return raw.map(String).filter(Boolean);
}
if (typeof raw === 'string' && raw.trim()) {
return raw.split(/[,,]/).map(s => s.trim()).filter(Boolean);
}
return [];
},
getWaybillText(item) {
const codes = this.getWaybillCodes(item);
return codes.length > 0 ? codes.join(' / ') : '--';
},
getOrderCreateAt(item) {
return this.formatDateTime(item?.created_at ?? item?.create_at);
},
getPrepImages(item) {
return this.normalizeImages(item?.images);
},
normalizeImages(list) {
if (!Array.isArray(list)) return [];
return list
.filter(e => e && (e.url || e.file_id || e.fileId))
.map(e => ({ url: e.url || e.path || e.image_url || '' }))
.filter(e => e.url);
},
previewImages(images, index) {
const urls = (Array.isArray(images) ? images : []).map(e => e.url).filter(Boolean);
if (!urls.length) return;
uni.previewImage({
urls,
current: urls[index] || urls[0]
});
},
formatDateTime(value) {
if (value === null || value === undefined || value === '') return '--';
const date = new Date(String(value).trim());
@ -512,7 +626,7 @@
margin-left: 12rpx;
padding: 4rpx 16rpx;
border-radius: 8rpx;
font-size: 26rpx;
font-size: 36rpx;
flex-shrink: 0;
}
@ -554,6 +668,28 @@
word-break: break-all;
}
.photo-row {
display: flex;
align-items: flex-start;
margin-bottom: 12rpx;
.photo-thumbs {
flex: 1;
min-width: 0;
display: flex;
flex-wrap: wrap;
}
.photo-thumb {
width: 120rpx;
height: 120rpx;
margin: 0 12rpx 12rpx 0;
border-radius: 8rpx;
background-color: #f5f7fa;
border: 1rpx solid #ebeef5;
}
}
.card-footer {
display: flex;
align-items: center;

View File

@ -39,7 +39,7 @@
</view>
<view v-for="(it, idx) in editItems" :key="idx" class="goods-item">
<view class="goods-item__header">
<text class="goods-item__name">{{ it.item_name }}、{{ it.item_code }}</text>
<text class="goods-item__name">{{ formatItemName(it) }}</text>
</view>
<view class="goods-item__row">
<text class="goods-item__label">应拣</text>
@ -71,8 +71,7 @@
<view v-else class="goods-list">
<view v-for="(it, idx) in items" :key="idx" class="goods-item">
<view class="goods-item__header">
<text class="goods-item__name">{{ it.item_name || it.item_code || '--' }}</text>
<text class="goods-item__code">{{ it.item_code || '' }}</text>
<text class="goods-item__name">{{ formatItemName(it) }}</text>
</view>
<view class="goods-item__row">
<text class="goods-item__label">应拣:</text>
@ -136,8 +135,60 @@
<!-- 底部操作栏 -->
<view v-if="canEdit" class="bottom-bar">
<u-button type="error" @click="handleCancelPrep">取消备货</u-button>
<u-button type="primary" :loading="submitting" @click="handleFinishPrep">完成备货</u-button>
<view class="bottom-bar-btn bottom-bar-btn--cancel" @click="handleCancelPrep">
<text class="bottom-bar-btn__text bottom-bar-btn__text--cancel">取消备货</text>
</view>
<view
class="bottom-bar-btn bottom-bar-btn--complete"
:class="{ 'bottom-bar-btn--disabled': submitting }"
@click="handleFinishPrep"
>
<text class="bottom-bar-btn__text bottom-bar-btn__text--complete">{{ submitting ? '提交中...' : '完成备货' }}</text>
</view>
</view>
<!-- 取消备货确认弹窗 -->
<view v-if="showCancelPrepConfirm" class="confirm-mask">
<view class="confirm-dialog" @click.stop>
<view class="confirm-close" @click="handleCancelPrepConfirmCancel">
<u-icon name="close" size="18" color="#909399"></u-icon>
</view>
<text class="confirm-title">取消备货</text>
<text class="confirm-content">确认取消备货,取消后可由其他工号重新开始备货?</text>
<view class="confirm-actions">
<view class="confirm-btn confirm-btn--cancel" @click="handleCancelPrepConfirmCancel">再想想</view>
<view class="confirm-btn confirm-btn--ok" @click="handleCancelPrepConfirmOk">取消备货</view>
</view>
</view>
</view>
<!-- 完成备货确认弹窗 -->
<view v-if="showFinishPrepConfirm" class="confirm-mask">
<view class="confirm-dialog" @click.stop>
<view class="confirm-close" @click="handleFinishPrepConfirmCancel">
<u-icon name="close" size="18" color="#909399"></u-icon>
</view>
<text class="confirm-title">完成备货</text>
<text class="confirm-content">提交即完成备货并同步扣减库存,不可撤回;未齐套的商品行会被后端拦截。确认提交?</text>
<view class="confirm-actions">
<view class="confirm-btn confirm-btn--cancel" @click="handleFinishPrepConfirmCancel">再想想</view>
<view class="confirm-btn confirm-btn--primary" @click="handleFinishPrepConfirmOk">完成备货</view>
</view>
</view>
</view>
<!-- 分箱校验提示弹窗 -->
<view v-if="showValidateConfirm" class="confirm-mask">
<view class="confirm-dialog" @click.stop>
<view class="confirm-close" @click="handleValidateConfirmClose">
<u-icon name="close" size="18" color="#909399"></u-icon>
</view>
<text class="confirm-title">提示</text>
<text class="confirm-content">{{ validateMessage }}</text>
<view class="confirm-actions">
<view class="confirm-btn confirm-btn--single" @click="handleValidateConfirmClose">知道了</view>
</view>
</view>
</view>
</view>
</template>
@ -157,7 +208,14 @@
prepRemark: '',
photoSyncTimer: null,
autoSaveTimer: null,
lastSavedPackingKey: ''
lastSavedPackingKey: '',
allowDirectBack: false,
showCancelPrepConfirm: false,
showFinishPrepConfirm: false,
showValidateConfirm: false,
validateMessage: '',
pendingPrepRemark: '',
pendingPrepTotalBoxCount: 0
}
},
computed: {
@ -204,7 +262,43 @@
uni.showToast({ title: '订单ID缺失', icon: 'none' });
}
},
onBackPress() {
// 提交/取消成功后放行,避免返回键再次拦截导致无法返回列表页
if (this.allowDirectBack) {
return false;
}
// 确认弹窗已显示时,拦截本次返回(不关闭弹窗)
if (this.showCancelPrepConfirm || this.showFinishPrepConfirm || this.showValidateConfirm) {
return true;
}
// 备货中返回时,提示是否取消备货;其他状态直接返回
if (this.canEdit) {
this.showCancelPrepConfirm = true;
return true;
}
return false;
},
methods: {
speakMessage(message, options = {}) {
const text = String(message || '').trim();
if (!text) {
return;
}
const tools = this.$tools;
if (!tools || typeof tools.speakText !== 'function') {
return;
}
try {
const task = tools.speakText(text, options);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn('[stockPreparationDetail] 语音播报失败:', error);
});
}
} catch (error) {
console.warn('[stockPreparationDetail] 语音播报异常:', error);
}
},
async fetchDetail() {
this.loading = true;
try {
@ -256,6 +350,12 @@
}
return [];
},
formatItemName(item) {
const name = String(item?.item_name || '').trim();
const code = String(item?.item_code || '').trim();
if (name && code) return `${name}、${code}`;
return name || code || '--';
},
getPickLocations(item) {
const locs = item?.pick_locations;
if (!Array.isArray(locs) || locs.length === 0) return '';
@ -352,6 +452,40 @@
}
return packingItems;
},
// 校验分箱:返回错误信息字符串,合法时返回空串
validatePacking(options = {}) {
const allowInsufficient = !!options.allowInsufficient;
// 同一商品行 + 箱号不能重复
for (const it of this.editItems) {
const seen = {};
for (const box of (it.boxes || [])) {
const boxNo = String(box.box_no || '').trim();
if (!boxNo) continue;
if (seen[boxNo]) {
return `商品「${this.formatItemName(it)}」箱号 ${boxNo} 重复,请修改`;
}
seen[boxNo] = true;
}
}
// 分箱数量合计需等于应拣数量(超量会被拦截)
for (const it of this.editItems) {
const plan = Number(it.plan_qty || 0);
let sum = 0;
for (const box of (it.boxes || [])) {
const quantity = Number(box.quantity);
if (Number.isFinite(quantity) && quantity > 0) {
sum += quantity;
}
}
if (sum > plan) {
return `商品「${this.formatItemName(it)}」分箱数量合计 ${sum} 超过应拣数量 ${plan},请调整`;
}
if (!allowInsufficient && sum < plan) {
return `商品「${this.formatItemName(it)}」分箱数量合计 ${sum} 小于应拣数量 ${plan},请补齐`;
}
}
return '';
},
savePacking() {
const packingItems = this.buildPackingItems();
if (packingItems.length === 0) {
@ -366,6 +500,12 @@
});
return;
}
const error = this.validatePacking();
if (error) {
this.validateMessage = error;
this.showValidateConfirm = true;
return;
}
this.doUpdatePacking(packingItems);
},
handleBoxInputBlur() {
@ -379,6 +519,9 @@
},
autoSavePacking() {
if (this.saving || this.submitting || !this.editing) return;
// 重复箱号或超量时不自动保存(允许不足,便于分箱进行中保存进度)
const error = this.validatePacking({ allowInsufficient: true });
if (error) return;
const packingItems = this.buildPackingItems();
if (packingItems.length === 0) return;
const key = JSON.stringify(packingItems);
@ -437,15 +580,27 @@
uni.showToast({ title: '总箱数无效', icon: 'none' });
return;
}
uni.showModal({
title: '提示',
content: '提交即完成备货并同步扣减库存,不可撤回;未齐套的商品行会被后端拦截。确认提交?',
success: (res) => {
if (res.confirm) {
this.doFinishPrep(remark, totalBoxCount);
}
}
});
const packingError = this.validatePacking();
if (packingError) {
this.speakMessage(packingError);
this.validateMessage = packingError;
this.showValidateConfirm = true;
return;
}
this.pendingPrepRemark = remark;
this.pendingPrepTotalBoxCount = totalBoxCount;
this.showFinishPrepConfirm = true;
},
handleFinishPrepConfirmCancel() {
this.showFinishPrepConfirm = false;
},
handleFinishPrepConfirmOk() {
this.showFinishPrepConfirm = false;
this.doFinishPrep(this.pendingPrepRemark, this.pendingPrepTotalBoxCount);
},
handleValidateConfirmClose() {
this.showValidateConfirm = false;
this.validateMessage = '';
},
async doFinishPrep(remark, totalBoxCount) {
this.submitting = true;
@ -459,11 +614,14 @@
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '提交失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
this.speakMessage(msg);
return;
}
uni.showToast({ title: '备货已完成', icon: 'success' });
this.speakMessage('备货已完成');
this.allowDirectBack = true;
setTimeout(() => {
uni.navigateBack();
this.navigateBackSafely();
}, 800);
} catch (error) {
console.error('[stockPreparationDetail] finishB2bPrep error:', error);
@ -475,29 +633,20 @@
handleBack() {
// 备货中返回时,提示是否取消备货;其他状态直接返回
if (this.canEdit) {
uni.showModal({
title: '提示',
content: '确认取消备货?',
success: (res) => {
if (res.confirm) {
this.doCancelPrep();
}
}
});
this.showCancelPrepConfirm = true;
return;
}
uni.navigateBack({ delta: 1 });
},
handleCancelPrep() {
uni.showModal({
title: '提示',
content: '确认取消备货?',
success: (res) => {
if (res.confirm) {
this.doCancelPrep();
}
}
});
this.showCancelPrepConfirm = true;
},
handleCancelPrepConfirmCancel() {
this.showCancelPrepConfirm = false;
},
handleCancelPrepConfirmOk() {
this.showCancelPrepConfirm = false;
this.doCancelPrep();
},
async doCancelPrep() {
uni.showLoading({ title: '取消备货中...' });
@ -507,11 +656,14 @@
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '取消备货失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
this.speakMessage(msg);
return;
}
uni.showToast({ title: '已取消备货', icon: 'success' });
this.speakMessage('已取消备货');
this.allowDirectBack = true;
setTimeout(() => {
uni.navigateBack();
this.navigateBackSafely();
}, 800);
} catch (error) {
console.error('[stockPreparationDetail] cancelB2bPrep error:', error);
@ -519,6 +671,35 @@
} finally {
uni.hideLoading();
}
},
navigateBackSafely() {
this.allowDirectBack = true;
let settled = false;
let retried = false;
const doBack = (label) => {
uni.navigateBack({
delta: 1,
success: () => {
settled = true;
console.log(`[stockPreparationDetail] navigateBack ${label}成功`);
},
fail: (err) => {
console.warn(`[stockPreparationDetail] navigateBack ${label}失败:`, err);
if (!retried) {
retried = true;
setTimeout(() => doBack('重试'), 300);
}
}
});
};
doBack('首次');
// 兜底:success/fail 都未触发(静默失效)时,400ms 后重试一次
setTimeout(() => {
if (!settled) {
console.warn('[stockPreparationDetail] navigateBack 静默失效,重试');
doBack('静默重试');
}
}, 400);
}
}
}
@ -574,7 +755,7 @@
.photo-card__title {
font-size: 30rpx;
font-weight: 600;
font-weight: bold;
color: #303133;
}
@ -596,7 +777,7 @@
.total-box-value {
font-size: 34rpx;
font-weight: 600;
font-weight: bold;
color: #303133;
}
@ -616,7 +797,7 @@
.remark-card__title {
font-size: 30rpx;
font-weight: 600;
font-weight: bold;
color: #303133;
}
@ -689,7 +870,7 @@
.summary-value {
flex: 1;
min-width: 0;
font-size: 34rpx;
font-size: 36rpx;
color: #303133;
word-break: break-all;
}
@ -739,18 +920,11 @@
.goods-item__name {
flex: 1;
min-width: 0;
font-size: 34rpx;
font-weight: 600;
font-size: 36rpx;
font-weight: bold;
color: #303133;
}
.goods-item__code {
flex-shrink: 0;
margin-left: 12rpx;
font-size: 26rpx;
color: #909399;
}
.goods-item__row {
display: flex;
align-items: center;
@ -764,7 +938,7 @@
}
.goods-item__value {
font-size: 34rpx;
font-size: 36rpx;
color: #303133;
margin-right: 20rpx;
}
@ -794,7 +968,7 @@
margin-right: 12rpx;
margin-bottom: 6rpx;
padding: 2rpx 12rpx;
font-size: 24rpx;
font-size: 36rpx;
color: #2979ff;
background-color: #ecf5ff;
border-radius: 6rpx;
@ -802,7 +976,7 @@
.goods-item__location {
flex: 1;
font-size: 34rpx;
font-size: 36rpx;
color: #303133;
word-break: break-all;
}
@ -818,20 +992,48 @@
padding: 16rpx 24rpx;
background-color: #ffffff;
border-top: 1rpx solid #ebeef5;
}
::v-deep .u-button {
flex: 1;
font-size: 36rpx;
}
.bottom-bar-btn {
flex: 1;
height: 88rpx;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
}
::v-deep .u-button + .u-button {
margin-left: 20rpx;
}
.bottom-bar-btn + .bottom-bar-btn {
margin-left: 20rpx;
}
::v-deep .u-button__text,
::v-deep .u-button__loading-text {
font-size: 36rpx !important;
}
.bottom-bar-btn--cancel {
background: #fff1f0;
border: 2rpx solid #ffccc7;
}
.bottom-bar-btn--complete {
background: #2979ff;
border: 2rpx solid #2979ff;
}
.bottom-bar-btn__text {
font-size: 34rpx;
font-weight: 500;
line-height: 1;
}
.bottom-bar-btn__text--cancel {
color: #f56c6c;
}
.bottom-bar-btn__text--complete {
color: #ffffff;
}
.bottom-bar-btn--disabled {
opacity: 0.6;
pointer-events: none;
}
.nav-save-btn {
@ -892,4 +1094,100 @@
font-size: 36rpx;
color: #2979ff;
}
.confirm-mask {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.48);
display: flex;
align-items: center;
justify-content: center;
z-index: 10095;
padding: 60rpx;
box-sizing: border-box;
}
.confirm-dialog {
position: relative;
width: 100%;
max-width: 620rpx;
background: #ffffff;
border-radius: 24rpx;
padding: 40rpx 36rpx 36rpx;
box-sizing: border-box;
box-shadow: 0 24rpx 80rpx rgba(0, 0, 0, 0.18);
display: flex;
flex-direction: column;
align-items: center;
}
.confirm-title {
font-size: 42rpx;
font-weight: bold;
color: #303133;
text-align: center;
}
.confirm-close {
position: absolute;
top: 20rpx;
right: 20rpx;
width: 48rpx;
height: 48rpx;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
}
.confirm-content {
margin-top: 32rpx;
font-size: 36rpx;
line-height: 1.6;
color: #606266;
text-align: center;
}
.confirm-actions {
width: 100%;
margin-top: 36rpx;
display: flex;
align-items: center;
}
.confirm-btn {
flex: 1;
height: 88rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 16rpx;
font-size: 36rpx;
font-weight: 500;
}
.confirm-btn--cancel {
background: #f5f7fa;
color: #606266;
}
.confirm-btn--ok {
margin-left: 24rpx;
background: #f56c6c;
color: #ffffff;
}
.confirm-btn--primary {
margin-left: 24rpx;
background: #2979ff;
color: #ffffff;
}
.confirm-btn--single {
background: #2979ff;
color: #ffffff;
}
</style>