feat: optimize product query and detail pages
This commit is contained in:
parent
6d7a1bd28d
commit
3762a36433
@ -80,7 +80,7 @@ const actions = {
|
|||||||
commit,
|
commit,
|
||||||
state
|
state
|
||||||
}) {
|
}) {
|
||||||
if (!state.initialized) {
|
if (!state || !state.initialized) {
|
||||||
console.error('[Broadcast] 请先初始化模块');
|
console.error('[Broadcast] 请先初始化模块');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ const actions = {
|
|||||||
commit,
|
commit,
|
||||||
state
|
state
|
||||||
}) {
|
}) {
|
||||||
if (!state.enabled) {
|
if (!state || !state.enabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,10 +124,12 @@ const actions = {
|
|||||||
* 暂停监听
|
* 暂停监听
|
||||||
*/
|
*/
|
||||||
pause({
|
pause({
|
||||||
commit
|
commit,
|
||||||
|
state
|
||||||
}) {
|
}) {
|
||||||
return actions.stop({
|
return actions.stop({
|
||||||
commit
|
commit,
|
||||||
|
state: state || {}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -155,7 +157,7 @@ const actions = {
|
|||||||
throw new Error('配置必须包含broadcastAction');
|
throw new Error('配置必须包含broadcastAction');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.enabled) {
|
if (!state || !state.enabled) {
|
||||||
console.warn('[Broadcast] 广播功能已禁用,配置更新无效');
|
console.warn('[Broadcast] 广播功能已禁用,配置更新无效');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -199,7 +201,7 @@ const actions = {
|
|||||||
throw new Error('Action不能为空');
|
throw new Error('Action不能为空');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.enabled) {
|
if (!state || !state.enabled) {
|
||||||
console.warn('[Broadcast] 广播功能已禁用,Action更新无效');
|
console.warn('[Broadcast] 广播功能已禁用,Action更新无效');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -222,11 +224,12 @@ const actions = {
|
|||||||
state
|
state
|
||||||
}) {
|
}) {
|
||||||
const scannerStatus = scanner.getStatus();
|
const scannerStatus = scanner.getStatus();
|
||||||
|
const safeState = state || {};
|
||||||
return {
|
return {
|
||||||
...scannerStatus,
|
...scannerStatus,
|
||||||
moduleEnabled: state.enabled,
|
moduleEnabled: !!safeState.enabled,
|
||||||
moduleInitialized: state.initialized,
|
moduleInitialized: !!safeState.initialized,
|
||||||
moduleActive: state.active
|
moduleActive: !!safeState.active
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -5,47 +5,89 @@
|
|||||||
|
|
||||||
<scroll-view class="detail-content" scroll-y>
|
<scroll-view class="detail-content" scroll-y>
|
||||||
<view class="detail-card" v-if="item">
|
<view class="detail-card" v-if="item">
|
||||||
<view class="image-section">
|
<view class="detail-header">
|
||||||
|
<view class="item-title-row">
|
||||||
|
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="item-main-row">
|
||||||
|
<view class="item-thumb" @click="previewProductImage(item)">
|
||||||
<u-image
|
<u-image
|
||||||
class="main-image"
|
v-if="getImageList(item).length <= 1"
|
||||||
|
class="goods-image"
|
||||||
:src="getImageUrl(item)"
|
:src="getImageUrl(item)"
|
||||||
mode="aspectFit"
|
mode="aspectFill"
|
||||||
width="100%"
|
width="90rpx"
|
||||||
height="360rpx"
|
height="90rpx"
|
||||||
@click="previewProductImage(item)"
|
|
||||||
>
|
>
|
||||||
<template #error>
|
<template #error>
|
||||||
<view class="image-placeholder">
|
<view class="image-placeholder">
|
||||||
<u-icon name="photo" size="42" color="#c0c4cc"></u-icon>
|
<u-icon name="photo" size="24" color="#c0c4cc"></u-icon>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
</u-image>
|
</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="44rpx"
|
||||||
|
height="44rpx"
|
||||||
|
>
|
||||||
|
<template #error>
|
||||||
|
<view class="image-placeholder image-placeholder-small">
|
||||||
|
<u-icon name="photo" size="18" 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>
|
||||||
|
</view>
|
||||||
|
<view class="item-info">
|
||||||
|
<view class="compact-row">
|
||||||
|
<text class="compact-label">商品编码:</text>
|
||||||
|
<text class="compact-value">{{ item.goods_code || item.item_code || '--' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="compact-row">
|
||||||
|
<text class="compact-label">条码:</text>
|
||||||
|
<text class="compact-value">{{ getBarcodeText(item) }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="info-section">
|
<view class="info-section">
|
||||||
<view class="name-row">
|
<view class="info-row">
|
||||||
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
|
<text class="label">名称:</text>
|
||||||
|
<text class="value">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="info-row">
|
<view class="info-row">
|
||||||
<text class="label">货主:</text>
|
<text class="label">货主:</text>
|
||||||
<text class="value">{{ getStoreOwnerText(item) }}</text>
|
<text class="value">{{ getStoreOwnerText(item) }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="info-row">
|
<view class="info-row">
|
||||||
<text class="label">商品编码:</text>
|
<text class="label">毛重:</text>
|
||||||
<text class="value">{{ item.goods_code || item.item_code || '--' }}</text>
|
<text class="value">{{ item.gross_weight || '--' }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="info-row">
|
<view class="info-row">
|
||||||
<text class="label">条码:</text>
|
<text class="label">品牌:</text>
|
||||||
<text class="value">{{ getBarcodeText(item) }}</text>
|
<text class="value">{{ item.brand_name || '--' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">违禁品类型:</text>
|
||||||
|
<text class="value">{{ (item.prohibited && item.prohibited.type_name) || '--' }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="info-row">
|
<view class="info-row">
|
||||||
<text class="label">SKU规格:</text>
|
<text class="label">SKU规格:</text>
|
||||||
<text class="value">{{ item.sku_property || '--' }}</text>
|
<text class="value">{{ item.sku_property || '--' }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="info-row">
|
|
||||||
<text class="label">库存单位:</text>
|
|
||||||
<text class="value">{{ item.stock_unit || '--' }}</text>
|
|
||||||
</view>
|
|
||||||
<view class="info-row">
|
<view class="info-row">
|
||||||
<text class="label">库存数量:</text>
|
<text class="label">库存数量:</text>
|
||||||
<text class="value">{{ getValueOrDash(item.quantity) }}</text>
|
<text class="value">{{ getValueOrDash(item.quantity) }}</text>
|
||||||
@ -54,6 +96,46 @@
|
|||||||
<text class="label">锁定量:</text>
|
<text class="label">锁定量:</text>
|
||||||
<text class="value">{{ getValueOrDash(item.locked_quantity) }}</text>
|
<text class="value">{{ getValueOrDash(item.locked_quantity) }}</text>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">可用库存:</text>
|
||||||
|
<text class="value">{{ item.available_quantity || '--' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">锁定率:</text>
|
||||||
|
<text class="value">{{ item.lock_rate_display || '--' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">库存单位:</text>
|
||||||
|
<text class="value">{{ item.stock_unit || '--' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">标价:</text>
|
||||||
|
<text class="value">
|
||||||
|
<text v-if="item.tag_price !== null && item.tag_price !== undefined && item.tag_price !== ''">¥</text>{{ item.tag_price || '--' }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">零售价:</text>
|
||||||
|
<text class="value">
|
||||||
|
<text v-if="item.retail_price !== null && item.retail_price !== undefined && item.retail_price !== ''">¥</text>{{ item.retail_price || '--' }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">ABC分类:</text>
|
||||||
|
<text class="value">{{ item.level || '--' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">体积:</text>
|
||||||
|
<text class="value">{{ item.box_volume || '--' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">创建时间:</text>
|
||||||
|
<text class="value">{{ item.create_at_display || '--' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="info-row">
|
||||||
|
<text class="label">更新时间:</text>
|
||||||
|
<text class="value">{{ item.update_at_display || '--' }}</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -147,6 +229,13 @@ export default {
|
|||||||
const single = this.getImageUrl(item);
|
const single = this.getImageUrl(item);
|
||||||
return single ? [single] : [];
|
return single ? [single] : [];
|
||||||
},
|
},
|
||||||
|
getImageThumbList(item) {
|
||||||
|
return this.getImageList(item).slice(0, 4);
|
||||||
|
},
|
||||||
|
getExtraImageCount(item) {
|
||||||
|
const total = this.getImageList(item).length;
|
||||||
|
return total > 4 ? total - 4 : 0;
|
||||||
|
},
|
||||||
previewProductImage(item) {
|
previewProductImage(item) {
|
||||||
const urls = this.getImageList(item);
|
const urls = this.getImageList(item);
|
||||||
if (!urls.length) {
|
if (!urls.length) {
|
||||||
@ -215,26 +304,16 @@ export default {
|
|||||||
padding: 20rpx;
|
padding: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-section {
|
.detail-header {
|
||||||
margin-bottom: 16rpx;
|
padding-bottom: 18rpx;
|
||||||
|
border-bottom: 2rpx solid #e5e7eb;
|
||||||
}
|
}
|
||||||
|
|
||||||
.main-image {
|
.info-section {
|
||||||
border-radius: 10rpx;
|
padding-top: 16rpx;
|
||||||
overflow: hidden;
|
|
||||||
background: #f5f7fa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-placeholder {
|
.item-title-row {
|
||||||
width: 100%;
|
|
||||||
height: 360rpx;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
background: #f5f7fa;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-row {
|
|
||||||
margin-bottom: 10rpx;
|
margin-bottom: 10rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,6 +323,112 @@ export default {
|
|||||||
color: #303133;
|
color: #303133;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item-main-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-thumb {
|
||||||
|
width: 90rpx;
|
||||||
|
margin-right: 20rpx;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-image {
|
||||||
|
border-radius: 10rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #f5f7fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-image-grid {
|
||||||
|
width: 90rpx;
|
||||||
|
height: 90rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-cell {
|
||||||
|
position: relative;
|
||||||
|
width: 44rpx;
|
||||||
|
height: 44rpx;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #f5f7fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-image {
|
||||||
|
border-radius: 8rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-placeholder {
|
||||||
|
width: 90rpx;
|
||||||
|
height: 90rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #f5f7fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-placeholder-small {
|
||||||
|
width: 44rpx;
|
||||||
|
height: 44rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.more-mask {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: rgba(0, 0, 0, 0.45);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.more-text {
|
||||||
|
font-size: 18rpx;
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
line-height: 1.4;
|
||||||
|
margin-bottom: 2rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-row:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-label {
|
||||||
|
width: auto;
|
||||||
|
margin-right: 6rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #909399;
|
||||||
|
white-space: nowrap;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-value {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #000;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
.info-row {
|
.info-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -256,7 +441,8 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
width: 120rpx;
|
width: auto;
|
||||||
|
margin-right: 6rpx;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #909399;
|
color: #909399;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
@ -265,7 +451,7 @@ export default {
|
|||||||
.value {
|
.value {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #606266;
|
color: #000;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
></u-search>
|
></u-search>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<scroll-view class="list-content" scroll-y :scroll-top="listScrollTop" @scroll="handleListScroll">
|
<scroll-view class="list-content" scroll-y :scroll-top="restoreScrollTop" @scroll="handleListScroll">
|
||||||
<view v-if="!loading && list.length === 0" class="empty-state">
|
<view v-if="!loading && list.length === 0" class="empty-state">
|
||||||
<u-icon name="search" size="88" color="#c0c4cc"></u-icon>
|
<u-icon name="search" size="88" color="#c0c4cc"></u-icon>
|
||||||
<text class="empty-text">暂无商品数据</text>
|
<text class="empty-text">暂无商品数据</text>
|
||||||
@ -23,17 +23,19 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view v-else class="list-wrap">
|
<view v-else class="list-wrap">
|
||||||
<view class="goods-item" v-for="(item, index) in list" :key="item.id || index" @click="goProductDetail(item)">
|
<view class="goods-item" v-for="(item, index) in list" :key="item.id || index">
|
||||||
|
<view class="item-title-row">
|
||||||
|
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
|
||||||
|
</view>
|
||||||
<view class="item-main-row">
|
<view class="item-main-row">
|
||||||
<view class="item-thumb">
|
<view class="item-thumb" @click.stop="previewProductImage(item)">
|
||||||
<u-image
|
<u-image
|
||||||
v-if="getImageList(item).length <= 1"
|
v-if="getImageList(item).length <= 1"
|
||||||
class="goods-image"
|
class="goods-image"
|
||||||
:src="getImageUrl(item)"
|
:src="getImageUrl(item)"
|
||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
width="180rpx"
|
width="90rpx"
|
||||||
height="180rpx"
|
height="90rpx"
|
||||||
@click.stop="previewProductImage(item)"
|
|
||||||
>
|
>
|
||||||
<template #error>
|
<template #error>
|
||||||
<view class="image-placeholder">
|
<view class="image-placeholder">
|
||||||
@ -44,7 +46,6 @@
|
|||||||
<view
|
<view
|
||||||
v-else
|
v-else
|
||||||
class="goods-image-grid"
|
class="goods-image-grid"
|
||||||
@click.stop="previewProductImage(item)"
|
|
||||||
>
|
>
|
||||||
<view
|
<view
|
||||||
class="grid-cell"
|
class="grid-cell"
|
||||||
@ -55,8 +56,8 @@
|
|||||||
class="grid-image"
|
class="grid-image"
|
||||||
:src="img"
|
:src="img"
|
||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
width="88rpx"
|
width="44rpx"
|
||||||
height="88rpx"
|
height="44rpx"
|
||||||
>
|
>
|
||||||
<template #error>
|
<template #error>
|
||||||
<view class="image-placeholder image-placeholder-small">
|
<view class="image-placeholder image-placeholder-small">
|
||||||
@ -71,9 +72,6 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="item-info">
|
<view class="item-info">
|
||||||
<view class="item-title-row">
|
|
||||||
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
|
|
||||||
</view>
|
|
||||||
<view class="item-row">
|
<view class="item-row">
|
||||||
<text class="label">货主:</text>
|
<text class="label">货主:</text>
|
||||||
<text class="value">{{ getStoreOwnerText(item) }}</text>
|
<text class="value">{{ getStoreOwnerText(item) }}</text>
|
||||||
@ -90,23 +88,16 @@
|
|||||||
<text class="label">SKU规格:</text>
|
<text class="label">SKU规格:</text>
|
||||||
<text class="value">{{ item.sku_property || '--' }}</text>
|
<text class="value">{{ item.sku_property || '--' }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="item-row">
|
|
||||||
<text class="label">库存单位:</text>
|
|
||||||
<text class="value">{{ item.stock_unit || '--' }}</text>
|
|
||||||
</view>
|
|
||||||
<view class="item-row">
|
|
||||||
<text class="label">库存数量:</text>
|
|
||||||
<text class="value">{{ getValueOrDash(item.quantity) }}</text>
|
|
||||||
</view>
|
|
||||||
<view class="item-row">
|
|
||||||
<text class="label">锁定量:</text>
|
|
||||||
<text class="value">{{ getValueOrDash(item.locked_quantity) }}</text>
|
|
||||||
</view>
|
</view>
|
||||||
|
<view class="item-arrow" @click.stop="goProductDetail(item)">
|
||||||
|
<u-icon name="arrow-right" size="18" color="#c0c4cc" :custom-style="{ pointerEvents: 'none' }"></u-icon>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<view v-if="!loading && list.length > 0" class="end-tip">没有更多了</view>
|
||||||
|
|
||||||
<view class="safe-area-bottom"></view>
|
<view class="safe-area-bottom"></view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
@ -123,37 +114,52 @@
|
|||||||
keyword: '',
|
keyword: '',
|
||||||
loading: false,
|
loading: false,
|
||||||
list: [],
|
list: [],
|
||||||
listScrollTop: 0
|
restoreScrollTop: 0,
|
||||||
|
listScrollTopCache: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.$store.dispatch('broadcast/setCallbacks', {
|
this.safeDispatchBroadcast('setCallbacks', {
|
||||||
onResult: this.handleBroadcastResult
|
onResult: this.handleBroadcastResult
|
||||||
});
|
});
|
||||||
this.$store.dispatch('broadcast/start');
|
this.safeDispatchBroadcast('start');
|
||||||
this.list = [];
|
this.list = [];
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.$store.dispatch('broadcast/setCallbacks', {
|
this.safeDispatchBroadcast('setCallbacks', {
|
||||||
onResult: this.handleBroadcastResult
|
onResult: this.handleBroadcastResult
|
||||||
});
|
});
|
||||||
this.$store.dispatch('broadcast/resume');
|
this.safeDispatchBroadcast('resume');
|
||||||
const cachedTop = Number(uni.getStorageSync('product_query_scroll_top') || 0);
|
const cachedTop = Number(uni.getStorageSync('product_query_scroll_top') || 0);
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.listScrollTop = cachedTop > 0 ? cachedTop : 0;
|
const top = cachedTop > 0 ? cachedTop : 0;
|
||||||
|
this.restoreScrollTop = top;
|
||||||
|
this.listScrollTopCache = top;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onHide() {
|
onHide() {
|
||||||
uni.setStorageSync('product_query_scroll_top', this.listScrollTop || 0);
|
uni.setStorageSync('product_query_scroll_top', this.listScrollTopCache || 0);
|
||||||
this.$store.dispatch('broadcast/pause');
|
this.safeDispatchBroadcast('pause');
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
this.$store.dispatch('broadcast/stop');
|
this.safeDispatchBroadcast('stop');
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
safeDispatchBroadcast(action, payload) {
|
||||||
|
try {
|
||||||
|
const task = this.$store.dispatch(`broadcast/${action}`, payload);
|
||||||
|
if (task && typeof task.catch === 'function') {
|
||||||
|
task.catch(error => {
|
||||||
|
console.warn(`[ProductQuery] broadcast/${action} 调用失败:`, error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`[ProductQuery] broadcast/${action} 调用异常:`, error);
|
||||||
|
}
|
||||||
|
},
|
||||||
handleListScroll(event) {
|
handleListScroll(event) {
|
||||||
const top = event && event.detail ? Number(event.detail.scrollTop || 0) : 0;
|
const top = event && event.detail ? Number(event.detail.scrollTop || 0) : 0;
|
||||||
this.listScrollTop = top;
|
this.listScrollTopCache = top;
|
||||||
},
|
},
|
||||||
normalizeKeyword(value) {
|
normalizeKeyword(value) {
|
||||||
return String(value || '').replace(/\s+/g, '');
|
return String(value || '').replace(/\s+/g, '');
|
||||||
@ -280,6 +286,24 @@
|
|||||||
|
|
||||||
return (list || []).filter(item => this.extractBarcodeList(item).includes(target));
|
return (list || []).filter(item => this.extractBarcodeList(item).includes(target));
|
||||||
},
|
},
|
||||||
|
getProductName(item) {
|
||||||
|
if (!item || typeof item !== 'object') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(item.item_name || item.product_name || item.name || '').trim();
|
||||||
|
},
|
||||||
|
filterByNameContains(list, keyword) {
|
||||||
|
const target = String(keyword || '').trim().toLowerCase();
|
||||||
|
if (!target) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (list || []).filter(item => {
|
||||||
|
const nameText = this.getProductName(item).toLowerCase();
|
||||||
|
return nameText.includes(target);
|
||||||
|
});
|
||||||
|
},
|
||||||
getImageUrl(item) {
|
getImageUrl(item) {
|
||||||
if (!item || typeof item !== 'object') {
|
if (!item || typeof item !== 'object') {
|
||||||
return '';
|
return '';
|
||||||
@ -357,17 +381,23 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = true;
|
const isBarcodeKeyword = this.isBarcodeLike(keyword);
|
||||||
try {
|
const queryParams = {
|
||||||
const res = await this.$http('stock.warehouse.list', {
|
|
||||||
pagination: {
|
pagination: {
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 100
|
pageSize: 100
|
||||||
},
|
},
|
||||||
keyword,
|
keyword
|
||||||
barcode: keyword,
|
};
|
||||||
barcodes: [keyword]
|
|
||||||
});
|
if (isBarcodeKeyword) {
|
||||||
|
queryParams.barcode = keyword;
|
||||||
|
queryParams.barcodes = [keyword];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loading = true;
|
||||||
|
try {
|
||||||
|
const res = await this.$http('stock.warehouse.list', queryParams);
|
||||||
|
|
||||||
if (res && res.code === 200) {
|
if (res && res.code === 200) {
|
||||||
const responseData = res.data;
|
const responseData = res.data;
|
||||||
@ -380,9 +410,9 @@
|
|||||||
nextList = responseData.rows;
|
nextList = responseData.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.list = this.isBarcodeLike(keyword)
|
this.list = isBarcodeKeyword
|
||||||
? this.filterByBarcodeExact(nextList, keyword)
|
? this.filterByBarcodeExact(nextList, keyword)
|
||||||
: nextList;
|
: this.filterByNameContains(nextList, keyword);
|
||||||
} else {
|
} else {
|
||||||
this.list = [];
|
this.list = [];
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -437,38 +467,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.list-wrap {
|
.list-wrap {
|
||||||
padding: 20rpx;
|
padding: 20rpx 8rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.goods-item {
|
.goods-item {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-radius: 12rpx;
|
border-radius: 12rpx;
|
||||||
padding: 10rpx 20rpx;
|
padding: 10rpx 16rpx;
|
||||||
margin-bottom: 20rpx;
|
margin-bottom: 20rpx;
|
||||||
border: 1rpx solid #e9edf3;
|
border: 1rpx solid #e9edf3;
|
||||||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
|
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
&::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
top: 18rpx;
|
|
||||||
bottom: 18rpx;
|
|
||||||
width: 6rpx;
|
|
||||||
background: #2979ff;
|
|
||||||
border-radius: 0 6rpx 6rpx 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-main-row {
|
.item-main-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
padding-right: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-thumb {
|
.item-thumb {
|
||||||
width: 180rpx;
|
width: 90rpx;
|
||||||
margin-right: 20rpx;
|
margin-right: 20rpx;
|
||||||
|
margin-top: 0;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,8 +501,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.goods-image-grid {
|
.goods-image-grid {
|
||||||
width: 180rpx;
|
width: 90rpx;
|
||||||
height: 180rpx;
|
height: 90rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@ -489,8 +511,8 @@
|
|||||||
|
|
||||||
.grid-cell {
|
.grid-cell {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 88rpx;
|
width: 44rpx;
|
||||||
height: 88rpx;
|
height: 44rpx;
|
||||||
border-radius: 8rpx;
|
border-radius: 8rpx;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: #f5f7fa;
|
background: #f5f7fa;
|
||||||
@ -503,7 +525,7 @@
|
|||||||
|
|
||||||
.image-placeholder {
|
.image-placeholder {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 180rpx;
|
height: 90rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@ -511,7 +533,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.image-placeholder-small {
|
.image-placeholder-small {
|
||||||
height: 88rpx;
|
height: 44rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.more-mask {
|
.more-mask {
|
||||||
@ -537,11 +559,24 @@
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item-arrow {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 44rpx;
|
||||||
|
height: 44rpx;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.item-title-row {
|
.item-title-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-bottom: 6rpx;
|
margin-bottom: 10rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.goods-name {
|
.goods-name {
|
||||||
@ -565,7 +600,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
width: 116rpx;
|
width: auto;
|
||||||
|
margin-right: 6rpx;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #909399;
|
color: #909399;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@ -575,7 +611,7 @@
|
|||||||
.value {
|
.value {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #606266;
|
color: #000;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@ -599,4 +635,11 @@
|
|||||||
color: #c0c4cc;
|
color: #c0c4cc;
|
||||||
margin-top: 10rpx;
|
margin-top: 10rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.end-tip {
|
||||||
|
padding: 8rpx 0 20rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 22rpx;
|
||||||
|
color: #c0c4cc;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user