diff --git a/pages/work/storage/receiving/components/ProductInfoEditor.vue b/pages/work/storage/receiving/components/ProductInfoEditor.vue index 694c5c6..7bb759c 100644 --- a/pages/work/storage/receiving/components/ProductInfoEditor.vue +++ b/pages/work/storage/receiving/components/ProductInfoEditor.vue @@ -25,7 +25,7 @@ + @blur="handleBarcodeBlur" /> 打印 随机生成 @@ -57,7 +57,7 @@ + @blur="handleBarcodeBlur" /> 打印 随机生成 @@ -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; } } diff --git a/pages/work/storage/receiving/components/detail-container.vue b/pages/work/storage/receiving/components/detail-container.vue index 9ce025d..56d41f9 100644 --- a/pages/work/storage/receiving/components/detail-container.vue +++ b/pages/work/storage/receiving/components/detail-container.vue @@ -23,7 +23,7 @@ + @change="$emit('change')" @selectDetailChange="selectDetailChange" @SpaceInput="SpaceInput" @SpaceSearch="scan" @tryGetStock="handleProductBarcodeSearch" @print="printBarcode"> @@ -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 ''; diff --git a/pages/work/storage/receiving/receivingDetail.vue b/pages/work/storage/receiving/receivingDetail.vue index de64774..144af8f 100644 --- a/pages/work/storage/receiving/receivingDetail.vue +++ b/pages/work/storage/receiving/receivingDetail.vue @@ -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) {