修改商品查询、面单补打页面

This commit is contained in:
zm2000 2026-06-28 18:52:48 +08:00
parent 5a509540c3
commit b06e4300d0
3 changed files with 154 additions and 49 deletions

View File

@ -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;

View File

@ -4,9 +4,17 @@
<view class="top-bar">
<view class="status-bar"></view>
<view class="header">
<view class="header-left" @click="handleBack">
<u-icon name="arrow-left" size="36rpx" color="#303133"></u-icon>
<text class="header-back-text">返回</text>
<view class="header-left">
<view class="header-left__back" @click="handleBack">
<u-icon name="arrow-left" size="36rpx" color="#303133"></u-icon>
</view>
<view class="header-left__divider"></view>
<view class="manual-toggle-btn"
:class="{ 'manual-toggle-btn--active': manualInputOpen }"
@click="toggleManualInput"
>
<text class="manual-toggle-btn__text">{{ manualInputOpen ? '关闭手动输入' : '手动输入' }}</text>
</view>
</view>
<text class="header-title">面单补打</text>
<view class="header-right" @click="handlePrinterSettings">
@ -26,14 +34,8 @@
<!-- 有权限:中部操作区 + 底部消息区 -->
<template v-else>
<view class="content-box">
<!-- 手动输入开关按钮 + 输入框(默认隐藏) -->
<!-- 手动输入输入框(默认隐藏) -->
<view class="broadcast-input-area">
<view class="manual-toggle-btn"
:class="{ 'manual-toggle-btn--active': manualInputOpen }"
@click="toggleManualInput"
>
<text class="manual-toggle-btn__text">{{ manualInputOpen ? '关闭手动输入' : '手动输入' }}</text>
</view>
<view v-if="manualInputOpen" class="scan-section">
<view class="scan-row">
<input
@ -88,7 +90,7 @@
</view>
<!-- 打印台设置弹窗 -->
<u-popup :show="showPopup" mode="bottom" :closeable="true" border-radius="20" :z-index="10090" @close="showPopup = false">
<u-popup :show="showPopup" mode="bottom" :closeable="true" border-radius="20" :z-index="10090" @close="showPopup = false" style="flex: none">
<view class="print-popup">
<scroll-view scroll-y class="print-popup-scroll">
<view class="print-popup-title">打印台绑定</view>
@ -605,13 +607,22 @@ import voice from '@/core/utils/voice';
.header-left {
display: flex;
align-items: center;
gap: 8rpx;
gap: 12rpx;
min-width: 100rpx;
}
.header-back-text {
font-size: 30rpx;
color: #303133;
.header-left__back {
display: flex;
align-items: center;
justify-content: center;
width: 56rpx;
height: 56rpx;
}
.header-left__divider {
width: 1rpx;
height: 32rpx;
background: #dcdfe6;
}
.header-title {
@ -657,16 +668,15 @@ import voice from '@/core/utils/voice';
color: #909399;
}
/* ===== 手动输入开关按钮(内联) ===== */
/* ===== 手动输入开关按钮(头部) ===== */
.manual-toggle-btn {
display: flex;
align-items: center;
justify-content: center;
width: 160rpx;
height: 64rpx;
margin: 0 auto 20rpx;
width: 175rpx;
height: 52rpx;
background: #2979ff;
border-radius: 10rpx;
border-radius: 8rpx;
}
.manual-toggle-btn--active {
@ -674,7 +684,7 @@ import voice from '@/core/utils/voice';
}
.manual-toggle-btn__text {
font-size: 26rpx;
font-size: 28rpx;
color: #ffffff;
white-space: nowrap;
}
@ -762,10 +772,13 @@ import voice from '@/core/utils/voice';
background: #1a1a1a;
border-radius: 12rpx;
overflow: hidden;
display: flex;
flex-direction: column;
}
.message-scroll {
height: 100%;
flex: 1;
min-height: 0;
padding: 16rpx 20rpx;
box-sizing: border-box;
}

View File

@ -65,7 +65,6 @@
<view class="item-main-row">
<view class="item-thumb" @click.stop="previewProductImage(item)">
<u-image
v-if="getImageList(item).length <= 1"
class="goods-image"
:src="getImageUrl(item)"
mode="aspectFill"
@ -78,32 +77,8 @@
</view>
</template>
</u-image>
<view
v-else
class="goods-image-grid"
>
<view
class="grid-cell"
v-for="(img, imgIndex) in getImageThumbList(item)"
:key="img + '-' + imgIndex"
>
<u-image
class="grid-image"
:src="img"
mode="aspectFill"
width="68rpx"
height="68rpx"
>
<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 && getExtraImageCount(item) > 0" class="more-mask">
<text class="more-text">+{{ getExtraImageCount(item) }}</text>
</view>
</view>
<view v-if="getImageCount(item) > 1" class="image-index-badge">
<text class="image-index-text">1/{{ getImageCount(item) }}</text>
</view>
</view>
<view class="item-info">
@ -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;