feat(商品/复核): 条码超3个默认收起并支持展开收起

- 商品查询/商品详情/订单复核列表:商品条码超过 3 个时默认收起,仅显示前 3 个,右侧显示「展开/收起」
- 订单复核详情:展开/收起按钮移至条码文本前固定位置,避免条码过多时按钮被推到末尾;字号调整为 36rpx
- 商品详情:展开后条码区域限制最大高度并支持内部滚动,同时动态测量固定头部高度撑开占位,避免溢出遮挡
- 商品查询:切换展开后刷新库存区定位,保证悬浮表头位置正确;字号调整为 36rpx
This commit is contained in:
zm2000 2026-11-15 18:15:10 +08:00
parent 1a429a5261
commit d8437120bc
3 changed files with 287 additions and 9 deletions

View File

@ -122,8 +122,8 @@
<view class="list-card-row__bottom">
<text class="list-card-name">{{ item.skuName || '--' }}</text>
<text class="list-card-space">{{'、'}}</text>
<text class="list-card-tag">{{ displayBarcode(item) }}</text>
<text v-if="hasMoreBarcodes(item)" class="barcode-toggle" @click.stop="toggleBarcodeExpand(item)">{{ isBarcodeExpanded(item) ? '收起' : '展开' }}</text>
<text class="list-card-tag">{{ displayBarcode(item) }}</text>
<text class="list-card-space">{{'、'}}</text>
<text class="list-card-tag">{{ item.location || '--' }}</text>
</view>
@ -1726,10 +1726,10 @@ import voice from '@/core/utils/voice';
}
.barcode-toggle {
font-size: 32rpx;
font-size: 36rpx;
color: #2979ff;
line-height: 1.5;
margin-left: 12rpx;
margin-right: 12rpx;
padding: 0 10rpx;
}

View File

@ -67,16 +67,30 @@
<text class="compact-label">商品编码:</text>
<text class="compact-value">{{ item.item_code || item.goods_code || '--' }}</text>
</view>
<view class="compact-row">
<view class="compact-row compact-row--barcode">
<text class="compact-label">条码:</text>
<text class="compact-value">{{ getBarcodeText(item) }}</text>
<view class="compact-value barcode-value">
<scroll-view
v-if="hasMoreBarcodes(item) && isBarcodeExpanded(item)"
class="barcode-scroll"
scroll-y
>
<text class="barcode-text">{{ getBarcodeDisplayText(item) }}</text>
</scroll-view>
<text v-else class="barcode-text">{{ getBarcodeDisplayText(item) }}</text>
<text
v-if="hasMoreBarcodes(item)"
class="barcode-toggle"
@click.stop="toggleBarcodeExpand(item)"
>{{ isBarcodeExpanded(item) ? '收起' : '展开' }}</text>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<view v-if="item" class="detail-fixed-placeholder"></view>
<view v-if="item" class="detail-fixed-placeholder" :style="headerPlaceholderHeight > 0 ? { height: headerPlaceholderHeight + 'px' } : {}"></view>
<scroll-view class="detail-content" scroll-y>
<view class="detail-card detail-card--body" v-if="item">
@ -276,7 +290,11 @@ export default {
title: '商品详情',
item: null,
cacheKey: '',
onProductUpdated: null
onProductUpdated: null,
// 条码展开状态(按商品 id 记录),条码超过 3 个时默认收起
barcodeExpandMap: {},
// 固定头部实际高度(px),用于撑开占位,避免条码展开后遮挡下方内容
headerPlaceholderHeight: 0
};
},
onLoad(options) {
@ -305,8 +323,13 @@ export default {
const cached = uni.getStorageSync(this.cacheKey);
if (cached && typeof cached === 'object') {
this.item = cached;
this.refreshHeaderPlaceholderHeight();
}
},
onReady() {
// 页面首次渲染完成后测量固定头部高度,撑开占位
this.refreshHeaderPlaceholderHeight();
},
onShow() {
// 从编辑页返回时,重新读取缓存,确保展示最新数据(含商品条码)
if (this.cacheKey) {
@ -318,6 +341,7 @@ export default {
};
}
}
this.refreshHeaderPlaceholderHeight();
},
onUnload() {
if (this.onProductUpdated) {
@ -404,6 +428,100 @@ export default {
return String(val);
},
getBarcodeList(item) {
if (!item || typeof item !== 'object') {
return [];
}
const barcodes = item.barcodes;
if (Array.isArray(barcodes)) {
return barcodes
.filter(code => code !== null && code !== undefined && code !== '')
.map(code => String(code).trim())
.filter(Boolean);
}
if (typeof barcodes === 'string' && barcodes.trim()) {
return barcodes
.split(/[;;,,\s]+/)
.map(code => code.trim())
.filter(Boolean);
}
const fallback = item.barcode || item.code;
if (Array.isArray(fallback)) {
return fallback
.filter(code => code !== null && code !== undefined && code !== '')
.map(code => String(code).trim())
.filter(Boolean);
}
if (typeof fallback === 'string' && fallback.trim()) {
return [fallback.trim()];
}
return [];
},
getBarcodeCount(item) {
return this.getBarcodeList(item).length;
},
hasMoreBarcodes(item) {
return this.getBarcodeCount(item) > 3;
},
getBarcodeExpandKey(item) {
if (!item || typeof item !== 'object') {
return 'unknown';
}
return String(
item.id
|| item.stock_id
|| item.goods_id
|| item.item_id
|| item.item_code
|| item.goods_code
|| item.barcode
|| item.code
|| 'unknown'
);
},
isBarcodeExpanded(item) {
return !!this.barcodeExpandMap[this.getBarcodeExpandKey(item)];
},
toggleBarcodeExpand(item) {
const key = this.getBarcodeExpandKey(item);
this.$set(this.barcodeExpandMap, key, !this.barcodeExpandMap[key]);
// 展开/收起会改变固定头部高度,重新测量并撑开占位,避免遮挡下方内容
this.refreshHeaderPlaceholderHeight();
},
refreshHeaderPlaceholderHeight() {
this.$nextTick(() => {
uni.createSelectorQuery().in(this).select('.detail-fixed-header').boundingClientRect(rect => {
if (rect && rect.height) {
this.headerPlaceholderHeight = Number(rect.height);
}
}).exec();
});
},
getBarcodeDisplayList(item) {
const list = this.getBarcodeList(item);
if (list.length > 3 && !this.isBarcodeExpanded(item)) {
return list.slice(0, 3);
}
return list;
},
getBarcodeDisplayText(item) {
const list = this.getBarcodeDisplayList(item);
if (list.length > 0) {
return list.join(';');
}
if (!item || typeof item !== 'object') {
return '--';
}
return item.barcode || item.code || '--';
},
getBarcodeText(item) {
if (!item || typeof item !== 'object') {
return '--';
@ -754,6 +872,42 @@ export default {
word-break: break-all;
}
.compact-row--barcode {
align-items: flex-start;
}
.barcode-value {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
}
.barcode-text {
flex: 1;
min-width: 0;
font-size: 40rpx;
color: #000;
word-break: break-all;
}
.barcode-scroll {
flex: 1;
min-width: 0;
max-height: 280rpx;
}
.barcode-toggle {
flex-shrink: 0;
margin-left: 12rpx;
font-size: 36rpx;
color: #2979ff;
line-height: 1.4;
&:active {
opacity: 0.7;
}
}
.detail-section-title {
padding: 24rpx 0 12rpx;
font-size: 35rpx;

View File

@ -99,9 +99,16 @@
<text class="label">编码:</text>
<text class="value">{{ item.item_code || item.goods_code || '--' }}</text>
</view>
<view class="item-row">
<view class="item-row item-row--barcode">
<text class="label">条码:</text>
<text class="value">{{ getBarcodeText(item) }}</text>
<view class="value barcode-value">
<text class="barcode-text">{{ getBarcodeDisplayText(item) }}</text>
<text
v-if="hasMoreBarcodes(item)"
class="barcode-toggle"
@click.stop="toggleBarcodeExpand(item)"
>{{ isBarcodeExpanded(item) ? '收起' : '展开' }}</text>
</view>
</view>
<view class="item-row">
<text class="label">SKU规格:</text>
@ -336,6 +343,8 @@
productImageCache: {},
productBarcodeCache: {},
CACHE_TTL: 5 * 60 * 1000,
// 条码展开状态(按商品 id 记录),条码超过 3 个时默认收起
barcodeExpandMap: {},
// 明细/库位切换时复用:避免重新搜索导致整页 loading 闪烁
searchListCache: [],
warehouseListCache: [],
@ -1051,6 +1060,91 @@
}
return [];
},
getBarcodeList(item) {
if (!item || typeof item !== 'object') {
return [];
}
const barcodes = item.barcodes;
if (Array.isArray(barcodes)) {
return barcodes
.filter(code => code !== null && code !== undefined && code !== '')
.map(code => String(code).trim())
.filter(Boolean);
}
if (typeof barcodes === 'string' && barcodes.trim()) {
return barcodes
.split(/[;;,,\s]+/)
.map(code => code.trim())
.filter(Boolean);
}
const fallback = item.barcode || item.code;
if (Array.isArray(fallback)) {
return fallback
.filter(code => code !== null && code !== undefined && code !== '')
.map(code => String(code).trim())
.filter(Boolean);
}
if (typeof fallback === 'string' && fallback.trim()) {
return [fallback.trim()];
}
return [];
},
getBarcodeCount(item) {
return this.getBarcodeList(item).length;
},
hasMoreBarcodes(item) {
return this.getBarcodeCount(item) > 3;
},
getBarcodeExpandKey(item) {
if (!item || typeof item !== 'object') {
return 'unknown';
}
return String(
item.id
|| item.stock_id
|| item.goods_id
|| item.item_id
|| item.item_code
|| item.goods_code
|| item.barcode
|| item.code
|| 'unknown'
);
},
isBarcodeExpanded(item) {
return !!this.barcodeExpandMap[this.getBarcodeExpandKey(item)];
},
toggleBarcodeExpand(item) {
const key = this.getBarcodeExpandKey(item);
this.$set(this.barcodeExpandMap, key, !this.barcodeExpandMap[key]);
// 展开/收起会改变商品摘要高度,刷新库存区定位信息,保证悬浮表头位置正确
this.scheduleRefreshStorageSectionMetas();
},
getBarcodeDisplayList(item) {
const list = this.getBarcodeList(item);
if (list.length > 3 && !this.isBarcodeExpanded(item)) {
return list.slice(0, 3);
}
return list;
},
getBarcodeDisplayText(item) {
const list = this.getBarcodeDisplayList(item);
if (list.length > 0) {
return list.join(';');
}
if (!item || typeof item !== 'object') {
return '--';
}
return item.barcode || item.code || '--';
},
getBarcodeText(item) {
if (!item || typeof item !== 'object') {
return '--';
@ -3028,6 +3122,36 @@
margin-bottom: 0;
}
.item-row--barcode {
align-items: flex-start;
}
.barcode-value {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
}
.barcode-text {
flex: 1;
min-width: 0;
font-size: 40rpx;
color: #000;
word-break: break-all;
}
.barcode-toggle {
flex-shrink: 0;
margin-left: 12rpx;
font-size: 36rpx;
color: #2979ff;
line-height: 1.4;
&:active {
opacity: 0.7;
}
}
.storage-section {
margin-top: 20rpx;
padding-top: 0;