fix(receiving): 修复收货商品信息同步与展示问题

This commit is contained in:
zm2000 2026-04-22 14:36:41 +08:00
parent 3fbd27c72c
commit af356d2ba2
3 changed files with 105 additions and 26 deletions

View File

@ -25,7 +25,7 @@
<view class="barcode-input-container">
<view class="barcode-input-row">
<u-input class="barcode-input" v-model="formData.barcode" placeholder="扫描或输入商品条码" clearable
@blur="emitFormData" />
@blur="handleBarcodeBlur" />
<u-button class="print-btn" type="primary" @click="print">打印</u-button>
</view>
<u-button class="random-barcode-btn" type="success" @click="randomBarcode">随机生成</u-button>
@ -57,7 +57,7 @@
<view class="barcode-input-container">
<view class="barcode-input-row">
<u-input class="barcode-input" v-model="formData.barcode" placeholder="扫描或输入商品条码" clearable
@blur="emitFormData" />
@blur="handleBarcodeBlur" />
<u-button class="print-btn" type="primary" @click="print">打印</u-button>
</view>
<u-button class="random-barcode-btn" type="success" @click="randomBarcode">随机生成</u-button>
@ -579,6 +579,13 @@
handleWeightBlur() {
this.emitFormData();
},
handleBarcodeBlur() {
const barcode = String(this.formData.barcode || '').trim();
if (barcode) {
this.$emit('tryGetStock', barcode);
}
this.emitFormData();
},
// 初始化库位选择器数据
initSpaceColumns(spaceList) {
if (!spaceList || spaceList.length === 0) return;
@ -800,10 +807,11 @@
margin-bottom: 15rpx;
.detail-item-label {
width: 160rpx;
color: #666;
font-size: 28rpx;
width: 220rpx;
color: #333;
font-size: 15px !important;
flex-shrink: 0;
white-space: nowrap;
}
.barcode-input-row{
display: flex;
@ -817,7 +825,7 @@
.detail-item-value {
flex: 1;
color: #333;
font-size: 28rpx;
font-size: 15px !important;
}
}

View File

@ -23,7 +23,7 @@
<!-- 商品详细信息展示 -->
<scroll-view scroll-y class="detail-content">
<product-info-editor ref="productEditor" :detail-data="selectedDetail" @update="handleDetailUpdate"
@change="$emit('change')" @selectDetailChange="selectDetailChange" @SpaceInput="SpaceInput" @SpaceSearch="scan" @print="printBarcode"></product-info-editor>
@change="$emit('change')" @selectDetailChange="selectDetailChange" @SpaceInput="SpaceInput" @SpaceSearch="scan" @tryGetStock="handleProductBarcodeSearch" @print="printBarcode"></product-info-editor>
</scroll-view>
</view>
<!-- 空状态 -->
@ -249,6 +249,14 @@
printBarcode(data){
this.$emit('print',data);
},
handleProductBarcodeSearch(keyword) {
const barcode = String(keyword || '').trim();
if (!barcode) {
return;
}
this.$emit('tryGetStock', barcode);
},
normalizeUniScanResult(scanResult) {
if (!scanResult) {
return '';

View File

@ -352,6 +352,8 @@
async handleDeleteDetail(id) {
// 先查找要删除的明细信息,用于提示
const detailToDelete = this.details.find(item => item.id === id);
const deletedIndex = this.details.findIndex(item => item.id === id);
const selectedIdBeforeDelete = this.selectedDetail && this.selectedDetail.id;
if (!detailToDelete) {
uni.showToast({
title: '要删除的明细不存在',
@ -377,22 +379,25 @@
icon: 'success'
});
// 更新明细列表
if (result.data.details) {
this.details = result.data.details;
// 删除后统一以服务端最新数据重建列表与选中态,避免残留旧引用
await this.loadReceivingInfo();
if (!Array.isArray(this.details) || this.details.length === 0) {
this.selectedDetail = null;
return;
}
// 处理选中状态
if (this.selectedDetail && this.selectedDetail.id === id) {
// 如果删除的是当前选中的明细,需要重新选择一个
if (this.details.length > 0) {
// 选择第一个明细
this.selectedDetail = this.details[0];
} else {
// 如果没有明细了,清空选中
this.selectedDetail = null;
}
if (selectedIdBeforeDelete && selectedIdBeforeDelete !== id) {
const reboundDetail = this.details.find(item => item.id === selectedIdBeforeDelete);
this.selectedDetail = reboundDetail || this.details[0];
return;
}
const nextIndex = Math.min(
Math.max(deletedIndex, 0),
this.details.length - 1
);
this.selectedDetail = this.details[nextIndex] || this.details[0];
} else {
uni.showToast({
title: result.message || '删除失败',
@ -690,11 +695,72 @@
});
}
},
async selectStock(stock) {
getStockName(stock) {
if (!stock || typeof stock !== 'object') {
return '新商品';
}
return stock.item_name || stock.product_name || stock.name || stock.goods_name || '新商品';
},
getStockBarcode(stock, fallbackBarcode = '') {
if (fallbackBarcode) {
return fallbackBarcode;
}
if (Array.isArray(stock?.barcodes) && stock.barcodes.length) {
return stock.barcodes.filter(Boolean).join(';');
}
return stock?.barcode || stock?.goods_code || stock?.item_code || '';
},
normalizeWeightValue(value) {
if (value === undefined || value === null) {
return '';
}
const text = String(value).trim();
if (!text) {
return '';
}
const numericValue = Number(text);
return Number.isFinite(numericValue) ? String(numericValue) : text;
},
getStockWeight(stock) {
if (!stock || typeof stock !== 'object') {
return '';
}
const candidates = [
stock.gross_weight,
stock.product && stock.product.gross_weight,
stock.product_snapshot && stock.product_snapshot.gross_weight,
stock.store_stock && stock.store_stock.gross_weight,
];
for (const item of candidates) {
const normalized = this.normalizeWeightValue(item);
if (normalized !== '') {
return normalized;
}
}
return '';
},
buildStockUpdateData(stock, scannedBarcode = '') {
const updateData = {
...this.selectedDetail, // 保留原有的所有属性
...this.selectedDetail,
system_product_id: stock.id,
product_name: this.getStockName(stock),
barcode: this.getStockBarcode(stock, scannedBarcode)
};
const weight = this.getStockWeight(stock);
updateData.weight = weight;
return updateData;
},
async selectStock(stock) {
const updateData = this.buildStockUpdateData(stock);
this.tmp_storeName = stock.store_stock.store_remask;
await this.handleSelectDetailChange(updateData);
},
@ -716,10 +782,7 @@
if (stocks.code == 200) {
if (stocks.total == 1) {
const updateData = {
...this.selectedDetail, // 保留原有的所有属性
system_product_id: stocks.data[0].id,
};
const updateData = this.buildStockUpdateData(stocks.data[0], data);
this.tmp_storeName = stocks.data[0].store_stock.store_remask;
await this.handleSelectDetailChange(updateData);
} else if (stocks.total > 1) {