From b06e4300d0c8509680fb97d790c787273f477ebe Mon Sep 17 00:00:00 2001 From: zm2000 <18386612143@163.com> Date: Sun, 28 Jun 2026 18:52:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E3=80=81=E9=9D=A2=E5=8D=95=E8=A1=A5=E6=89=93=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 1 + pages/packing/labelReprint.vue | 57 ++++++++----- pages/work/product/query.vue | 145 +++++++++++++++++++++++++++------ 3 files changed, 154 insertions(+), 49 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index e5277bb..c835653 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -292,6 +292,7 @@ async getLatestUserInfo() { try { const latestUser = await this.$store.dispatch('getUserInfo'); + console.log('[index] user.info 返回数据:', JSON.parse(JSON.stringify(latestUser))); if (latestUser && typeof latestUser === 'object') { this.userInfo = latestUser; return latestUser; diff --git a/pages/packing/labelReprint.vue b/pages/packing/labelReprint.vue index c373a65..d14605f 100644 --- a/pages/packing/labelReprint.vue +++ b/pages/packing/labelReprint.vue @@ -4,9 +4,17 @@ - - - 返回 + + + + + + + {{ manualInputOpen ? '关闭手动输入' : '手动输入' }} + 面单补打 @@ -26,14 +34,8 @@ - - - - - - - +{{ getExtraImageCount(item) }} - - + + 1/{{ getImageCount(item) }} @@ -711,6 +686,90 @@ } }); }, + /** + * 从 index.getImages 接口获取商品图片 + * @param {Array} mergedList 合并后的商品列表 + * @param {Array} warehouseList 仓库列表(包含 id 字段) + */ + async fetchProductImages(mergedList, warehouseList) { + if (!Array.isArray(mergedList) || !mergedList.length) { + return; + } + + // 从 warehouseList 中收集有 id 的商品 + const warehouseItemMap = new Map(); + (warehouseList || []).forEach(item => { + if (item && item.id) { + warehouseItemMap.set(item.id, item); + } + }); + + if (!warehouseItemMap.size) { + return; + } + + // 找到 mergedList 中对应的商品 + const itemsToFetch = []; + mergedList.forEach(item => { + if (!item || typeof item !== 'object') { + return; + } + + const id = item.id; + if (id && warehouseItemMap.has(id)) { + itemsToFetch.push({ item, id }); + } + }); + + if (!itemsToFetch.length) { + return; + } + + console.log('[ProductQuery] 开始获取商品图片,数量:', itemsToFetch.length); + + // 并行请求图片 + const results = await Promise.allSettled( + itemsToFetch.map(({ id }) => + this.$http('common.getImages', { type: 'stock', id }) + ) + ); + + // 将图片数据关联到对应商品 + itemsToFetch.forEach(({ item }, index) => { + const result = results[index]; + if (result.status === 'rejected') { + return; + } + + const response = result.value; + if (!response || response.code !== 200) { + return; + } + + const imageData = this.extractListFromResponse(response); + if (!Array.isArray(imageData) || !imageData.length) { + return; + } + + // 提取图片 URL 列表 + const imageUrls = imageData + .map(img => { + if (!img) return ''; + if (typeof img === 'string') return img; + // 嵌套 file 对象: { file: { file_url, file_name } } + if (img.file && typeof img.file === 'object') { + return img.file.file_url || img.file.url || img.file.path || ''; + } + return img.url || img.path || img.image_url || img.fileUrl || img.successUrl || ''; + }) + .filter(Boolean); + + if (imageUrls.length > 0) { + item.images = imageUrls; + console.log(`[ProductQuery] 商品 id=${item.id} 获取到 ${imageUrls.length} 张图片`); + } + }); + }, getBarcodeText(item) { if (!item || typeof item !== 'object') { return '--'; @@ -1149,6 +1208,9 @@ getImageThumbList(item) { return this.getImageList(item).slice(0, 4); }, + getImageCount(item) { + return this.getImageList(item).length; + }, getStorageList(item) { if (!item || typeof item !== 'object') { return []; @@ -1523,6 +1585,14 @@ const detailList = listOk ? this.extractListFromResponse(listRes) : []; const mergedList = this.mergeProductResultLists(nextList, warehouseList, detailList); + // 异步获取商品图片(不阻塞主流程) + this.fetchProductImages(mergedList, warehouseList).then(() => { + // 图片加载完成后,重新触发视图更新(如列表未变则自动跳过) + this.$forceUpdate(); + }).catch(error => { + console.warn('[ProductQuery] 获取商品图片异常:', error); + }); + this.rawList = mergedList; this.updateDisplayListByMode(mergedList, keyword, isBarcodeKeyword); console.log('[ProductQuery] 搜索结果数量:', this.list.length); @@ -1767,6 +1837,7 @@ margin-right: 20rpx; margin-top: 0; flex-shrink: 0; + position: relative; } .goods-image { @@ -1811,6 +1882,26 @@ height: 68rpx; } + .image-index-badge { + position: absolute; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.5); + border-radius: 10rpx 0 10rpx 0; + padding: 2rpx 10rpx; + display: flex; + align-items: center; + justify-content: center; + z-index: 2; + pointer-events: none; + } + + .image-index-text { + font-size: 20rpx; + color: #fff; + font-weight: 500; + } + .more-mask { position: absolute; left: 0;