fix(product-query): 修复多商品列表滚动到底部时抬头被遮挡问题,改为 flex 布局并优化滚动容器高度计算,增加商品查询页面实现,支持关键字与扫商品条码触发查询;展示商品名称,商品编码/条码/SKU/库存信息,补充空状态与异常提示,扫描或者输入的条码去空格处理。
This commit is contained in:
parent
fb1573b2a5
commit
34adbce776
259
pages/work/product/query.vue
Normal file
259
pages/work/product/query.vue
Normal file
@ -0,0 +1,259 @@
|
||||
<template>
|
||||
<view class="goods-query-page">
|
||||
<view class="normar_container">
|
||||
<page-nav :title="title"></page-nav>
|
||||
|
||||
<view class="search-panel">
|
||||
<u-search
|
||||
v-model="keyword"
|
||||
placeholder="请输入商品条码或名称"
|
||||
:bg-color="'#f5f5f5'"
|
||||
shape="round"
|
||||
:show-action="false"
|
||||
@search="handleSearch"
|
||||
@clear="handleSearch"
|
||||
></u-search>
|
||||
</view>
|
||||
|
||||
<scroll-view class="list-content" scroll-y>
|
||||
<view v-if="!loading && list.length === 0" class="empty-state">
|
||||
<u-icon name="search" size="88" color="#c0c4cc"></u-icon>
|
||||
<text class="empty-text">暂无商品数据</text>
|
||||
<text class="empty-hint">请输入关键字进行查询</text>
|
||||
</view>
|
||||
|
||||
<view v-else class="list-wrap">
|
||||
<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-row">
|
||||
<text class="label">商品编码:</text>
|
||||
<text class="value">{{ item.goods_code || item.item_code || '--' }}</text>
|
||||
</view>
|
||||
<view class="item-row">
|
||||
<text class="label">条码:</text>
|
||||
<text class="value">{{ getBarcodeText(item) }}</text>
|
||||
</view>
|
||||
<view class="item-row">
|
||||
<text class="label">SKU规格:</text>
|
||||
<text class="value">{{ item.sku_property || '--' }}</text>
|
||||
</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>
|
||||
|
||||
<view class="safe-area-bottom"></view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<u-loading-page :loading="loading" bg-color="rgba(255,255,255,0.9)"></u-loading-page>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
title: '商品查询',
|
||||
keyword: '',
|
||||
loading: false,
|
||||
list: []
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.$store.dispatch('broadcast/setCallbacks', {
|
||||
onResult: this.handleBroadcastResult
|
||||
});
|
||||
this.$store.dispatch('broadcast/start');
|
||||
this.list = [];
|
||||
},
|
||||
onShow() {
|
||||
this.$store.dispatch('broadcast/setCallbacks', {
|
||||
onResult: this.handleBroadcastResult
|
||||
});
|
||||
this.$store.dispatch('broadcast/resume');
|
||||
},
|
||||
onHide() {
|
||||
this.$store.dispatch('broadcast/pause');
|
||||
},
|
||||
onUnload() {
|
||||
this.$store.dispatch('broadcast/stop');
|
||||
},
|
||||
methods: {
|
||||
normalizeKeyword(value) {
|
||||
return String(value || '').replace(/\s+/g, '');
|
||||
},
|
||||
handleBroadcastResult(result) {
|
||||
const scanResult = this.normalizeKeyword((result && result.data) || '');
|
||||
if (!scanResult) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.keyword = scanResult;
|
||||
this.handleSearch();
|
||||
},
|
||||
getBarcodeText(item) {
|
||||
if (!item || typeof item !== 'object') {
|
||||
return '--';
|
||||
}
|
||||
|
||||
if (Array.isArray(item.barcodes) && item.barcodes.length > 0) {
|
||||
return item.barcodes.join(';');
|
||||
}
|
||||
|
||||
return item.barcode || item.code || '--';
|
||||
},
|
||||
getValueOrDash(value) {
|
||||
return value === null || value === undefined || value === '' ? '--' : value;
|
||||
},
|
||||
async handleSearch() {
|
||||
const keyword = this.normalizeKeyword(this.keyword);
|
||||
this.keyword = keyword;
|
||||
if (!keyword) {
|
||||
this.list = [];
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
try {
|
||||
const res = await this.$http('stock.warehouse.search', {
|
||||
keyword
|
||||
});
|
||||
|
||||
if (res && res.code === 200) {
|
||||
this.list = Array.isArray(res.data) ? res.data : [];
|
||||
} else {
|
||||
this.list = [];
|
||||
uni.showToast({
|
||||
title: (res && res.message) || '查询失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.list = [];
|
||||
uni.showToast({
|
||||
title: (error && error.message) || '查询失败',
|
||||
icon: 'none'
|
||||
});
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.goods-query-page {
|
||||
background: #f7f8fa;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.normar_container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.search-panel {
|
||||
padding: 20rpx;
|
||||
background: #fff;
|
||||
border-bottom: 1rpx solid #f2f2f2;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.list-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.list-wrap {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.goods-item {
|
||||
background: #fff;
|
||||
border-radius: 12rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.item-title-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 18rpx;
|
||||
}
|
||||
|
||||
.goods-name {
|
||||
font-size: 30rpx;
|
||||
color: #303133;
|
||||
font-weight: 600;
|
||||
flex: 1;
|
||||
padding-right: 20rpx;
|
||||
}
|
||||
|
||||
.item-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: nowrap;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.label {
|
||||
width: 140rpx;
|
||||
font-size: 24rpx;
|
||||
color: #909399;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.value {
|
||||
flex: 1;
|
||||
font-size: 24rpx;
|
||||
color: #606266;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 160rpx 0 100rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 30rpx;
|
||||
color: #909399;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
font-size: 24rpx;
|
||||
color: #c0c4cc;
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
</style>
|
||||
Loading…
x
Reference in New Issue
Block a user