1146 lines
27 KiB
Vue
1146 lines
27 KiB
Vue
<template>
|
||
<view class="goods-query-page">
|
||
<view class="normar_container">
|
||
<view class="page-header">
|
||
<page-nav :title="title">
|
||
<template #right>
|
||
<view class="nav-mode-switch-group">
|
||
<view
|
||
class="nav-mode-switch-btn"
|
||
:class="{ 'nav-mode-switch-btn--active': queryMode === 'batch' }"
|
||
@click="setQueryMode('batch')"
|
||
>
|
||
<text class="nav-mode-switch-btn__text">批次</text>
|
||
</view>
|
||
<view
|
||
class="nav-mode-switch-btn"
|
||
:class="{ 'nav-mode-switch-btn--active': queryMode === 'nonBatch' }"
|
||
@click="setQueryMode('nonBatch')"
|
||
>
|
||
<text class="nav-mode-switch-btn__text">非批次</text>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
</page-nav>
|
||
|
||
<view class="search-panel">
|
||
<view class="search-input-wrap">
|
||
<u-search
|
||
v-model="keyword"
|
||
placeholder="请输入商品条码或名称"
|
||
:bg-color="'#f5f5f5'"
|
||
shape="round"
|
||
:show-action="false"
|
||
@search="handleSearch"
|
||
@clear="handleSearch"
|
||
></u-search>
|
||
<view class="search-actions">
|
||
<view class="scan-btn" @click="handleCameraScan">
|
||
<u-icon name="scan" size="38rpx" color="#2979ff"></u-icon>
|
||
</view>
|
||
<view class="search-divider"></view>
|
||
<view class="search-btn" @click="handleSearch">
|
||
<text class="search-btn__text">搜索</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<scroll-view class="list-content" scroll-y :scroll-top="restoreScrollTop" @scroll="handleListScroll">
|
||
<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-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"
|
||
width="140rpx"
|
||
height="140rpx"
|
||
>
|
||
<template #error>
|
||
<view class="image-placeholder">
|
||
<u-icon name="photo" size="32" color="#c0c4cc"></u-icon>
|
||
</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>
|
||
</view>
|
||
<view class="item-info">
|
||
<view class="item-row">
|
||
<text class="label">货主:</text>
|
||
<text class="value">{{ getStoreOwnerText(item) }}</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 v-if="hasBatchNumber(item)" class="item-row">
|
||
<text class="label">批次号:</text>
|
||
<text class="value">{{ getBatchNumberText(item) }}</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 v-if="queryMode === 'nonBatch' && getStorageList(item).length" class="storage-section">
|
||
<scroll-view class="storage-scroll" scroll-x>
|
||
<view class="storage-table storage-table--non-batch">
|
||
<view class="storage-table__head storage-table__row">
|
||
<text class="storage-col storage-col--space">库位</text>
|
||
<text class="storage-col storage-col--qty">库存</text>
|
||
<text class="storage-col storage-col--qty">可移库存</text>
|
||
</view>
|
||
<view
|
||
v-for="(storageItem, storageIndex) in getStorageList(item)"
|
||
:key="getStorageItemKey(storageItem, storageIndex)"
|
||
class="storage-table__row"
|
||
>
|
||
<text class="storage-col storage-col--space">{{ getStorageSpaceText(storageItem) }}</text>
|
||
<text class="storage-col storage-col--qty">{{ getStorageQuantityText(storageItem) }}</text>
|
||
<text class="storage-col storage-col--qty storage-col--highlight">{{ getStorageAvailableText(storageItem) }}</text>
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
<view v-if="queryMode === 'batch' && getBatchStorageList(item).length" class="storage-section">
|
||
<scroll-view class="storage-scroll" scroll-x>
|
||
<view class="storage-table storage-table--batch">
|
||
<view class="storage-table__head storage-table__row">
|
||
<text class="storage-col storage-col--batch">批次号</text>
|
||
<text class="storage-col storage-col--space">库位</text>
|
||
<text class="storage-col storage-col--qty">库存</text>
|
||
<text class="storage-col storage-col--qty">可移库存</text>
|
||
</view>
|
||
<view
|
||
v-for="(storageItem, storageIndex) in getBatchStorageList(item)"
|
||
:key="getBatchStorageItemKey(item, storageItem, storageIndex)"
|
||
class="storage-table__row"
|
||
>
|
||
<text class="storage-col storage-col--batch">{{ getBatchNumberBySource(storageItem, item) }}</text>
|
||
<text class="storage-col storage-col--space">{{ getStorageSpaceText(storageItem) }}</text>
|
||
<text class="storage-col storage-col--qty">{{ getStorageQuantityText(storageItem) }}</text>
|
||
<text class="storage-col storage-col--qty storage-col--highlight">{{ getStorageAvailableText(storageItem) }}</text>
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view v-if="!loading && list.length > 0" class="end-tip">没有更多了</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: '',
|
||
queryMode: 'nonBatch',
|
||
loading: false,
|
||
list: [],
|
||
rawList: [],
|
||
restoreScrollTop: 0,
|
||
listScrollTopCache: 0
|
||
}
|
||
},
|
||
onLoad() {
|
||
this.safeDispatchBroadcast('setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.safeDispatchBroadcast('start');
|
||
this.list = [];
|
||
},
|
||
onShow() {
|
||
this.safeDispatchBroadcast('setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.safeDispatchBroadcast('resume');
|
||
const cachedTop = Number(uni.getStorageSync('product_query_scroll_top') || 0);
|
||
this.$nextTick(() => {
|
||
const top = cachedTop > 0 ? cachedTop : 0;
|
||
this.restoreScrollTop = top;
|
||
this.listScrollTopCache = top;
|
||
});
|
||
},
|
||
onHide() {
|
||
uni.setStorageSync('product_query_scroll_top', this.listScrollTopCache || 0);
|
||
this.safeDispatchBroadcast('pause');
|
||
},
|
||
onUnload() {
|
||
this.safeDispatchBroadcast('stop');
|
||
},
|
||
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) {
|
||
const top = event && event.detail ? Number(event.detail.scrollTop || 0) : 0;
|
||
this.listScrollTopCache = top;
|
||
},
|
||
normalizeKeyword(value) {
|
||
return String(value || '').replace(/\s+/g, '');
|
||
},
|
||
normalizeScanResult(scanResult) {
|
||
if (!scanResult) {
|
||
return '';
|
||
}
|
||
|
||
if (typeof scanResult === 'string') {
|
||
return this.normalizeKeyword(scanResult);
|
||
}
|
||
|
||
if (typeof scanResult.result === 'string') {
|
||
return this.normalizeKeyword(scanResult.result);
|
||
}
|
||
|
||
if (Array.isArray(scanResult.result)) {
|
||
const firstResult = scanResult.result.find(item => item);
|
||
if (typeof firstResult === 'string') {
|
||
return this.normalizeKeyword(firstResult);
|
||
}
|
||
if (firstResult && typeof firstResult.data === 'string') {
|
||
return this.normalizeKeyword(firstResult.data);
|
||
}
|
||
}
|
||
|
||
if (typeof scanResult.data === 'string') {
|
||
return this.normalizeKeyword(scanResult.data);
|
||
}
|
||
|
||
return '';
|
||
},
|
||
handleBroadcastResult(result) {
|
||
const scanResult = this.normalizeScanResult(result);
|
||
if (!scanResult) {
|
||
return;
|
||
}
|
||
|
||
this.keyword = scanResult;
|
||
this.handleSearch();
|
||
},
|
||
handleCameraScan() {
|
||
uni.scanCode({
|
||
onlyFromCamera: true,
|
||
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
|
||
success: (res) => {
|
||
const scanResult = this.normalizeScanResult(res);
|
||
if (!scanResult) {
|
||
uni.showToast({
|
||
title: '未识别到有效条码',
|
||
icon: 'none'
|
||
});
|
||
return;
|
||
}
|
||
|
||
this.keyword = scanResult;
|
||
this.handleSearch();
|
||
},
|
||
fail: (error) => {
|
||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||
if (errMsg.includes('cancel')) {
|
||
return;
|
||
}
|
||
|
||
uni.showToast({
|
||
title: '扫码失败,请重试',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
});
|
||
},
|
||
getBarcodeText(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '--';
|
||
}
|
||
|
||
const barcodes = item.barcodes;
|
||
if (Array.isArray(barcodes) && barcodes.length > 0) {
|
||
return barcodes.filter(code => code !== null && code !== undefined && code !== '').join(';');
|
||
}
|
||
|
||
if (typeof barcodes === 'string' && barcodes.trim()) {
|
||
return barcodes;
|
||
}
|
||
|
||
return item.barcode || item.code || '--';
|
||
},
|
||
getValueOrDash(value) {
|
||
return value === null || value === undefined || value === '' ? '--' : value;
|
||
},
|
||
getStoreOwnerText(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '--';
|
||
}
|
||
|
||
const directValue = item['store.store_remask'] || item['store_stock.store_remask'] || item.store_remask;
|
||
if (directValue !== null && directValue !== undefined && directValue !== '') {
|
||
return directValue;
|
||
}
|
||
|
||
if (item.store_stock && typeof item.store_stock === 'object' && item.store_stock.store_remask) {
|
||
return item.store_stock.store_remask;
|
||
}
|
||
|
||
if (item.store && typeof item.store === 'object' && item.store.store_remask) {
|
||
return item.store.store_remask;
|
||
}
|
||
|
||
const nestedValue = this.findStoreRemaskValue(item);
|
||
if (nestedValue) {
|
||
return nestedValue;
|
||
}
|
||
|
||
return '--';
|
||
},
|
||
findStoreRemaskValue(source, visited = new Set()) {
|
||
if (!source || typeof source !== 'object') {
|
||
return '';
|
||
}
|
||
|
||
if (visited.has(source)) {
|
||
return '';
|
||
}
|
||
visited.add(source);
|
||
|
||
if (typeof source.store_remask === 'string' && source.store_remask.trim()) {
|
||
return source.store_remask.trim();
|
||
}
|
||
|
||
const keys = Object.keys(source);
|
||
for (let i = 0; i < keys.length; i++) {
|
||
const key = keys[i];
|
||
const value = source[key];
|
||
|
||
if (key === 'store_remask' && value) {
|
||
return String(value).trim();
|
||
}
|
||
|
||
if (value && typeof value === 'object') {
|
||
const nested = this.findStoreRemaskValue(value, visited);
|
||
if (nested) {
|
||
return nested;
|
||
}
|
||
}
|
||
}
|
||
|
||
return '';
|
||
},
|
||
isBarcodeLike(value) {
|
||
const text = this.normalizeKeyword(value);
|
||
return text.length >= 6 && /^[A-Za-z0-9._-]+$/.test(text);
|
||
},
|
||
extractBarcodeList(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return [];
|
||
}
|
||
|
||
let values = [];
|
||
if (Array.isArray(item.barcodes)) {
|
||
values = values.concat(item.barcodes);
|
||
} else if (typeof item.barcodes === 'string' && item.barcodes.trim()) {
|
||
values = values.concat(item.barcodes.split(/[;,,\s]+/));
|
||
}
|
||
|
||
if (item.barcode) {
|
||
values.push(item.barcode);
|
||
}
|
||
if (item.code) {
|
||
values.push(item.code);
|
||
}
|
||
|
||
return [...new Set(values
|
||
.map(code => this.normalizeKeyword(code))
|
||
.filter(Boolean)
|
||
)];
|
||
},
|
||
filterByBarcodeExact(list, keyword) {
|
||
const target = this.normalizeKeyword(keyword);
|
||
if (!target) {
|
||
return list;
|
||
}
|
||
|
||
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();
|
||
},
|
||
getBatchNumberText(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '--';
|
||
}
|
||
|
||
return item.batch_number || item.batch_no || item.lot_number || item.lot_no || '--';
|
||
},
|
||
hasBatchNumber(item) {
|
||
return this.getBatchNumberText(item) !== '--';
|
||
},
|
||
applyQueryModeFilter(list) {
|
||
if (!Array.isArray(list) || !list.length) {
|
||
return [];
|
||
}
|
||
|
||
if (this.queryMode === 'batch') {
|
||
return list;
|
||
}
|
||
|
||
return list.filter(item => !this.hasBatchNumber(item));
|
||
},
|
||
updateDisplayListByMode(sourceList, keyword, isBarcodeKeyword) {
|
||
const filteredByKeyword = isBarcodeKeyword
|
||
? this.filterByBarcodeExact(sourceList, keyword)
|
||
: this.filterByNameContains(sourceList, keyword);
|
||
|
||
this.list = this.applyQueryModeFilter(filteredByKeyword);
|
||
},
|
||
buildQueryParams(keyword) {
|
||
return {
|
||
keyword,
|
||
with_stock: true,
|
||
is_batch: this.queryMode === 'batch'
|
||
};
|
||
},
|
||
setQueryMode(nextMode) {
|
||
if (!nextMode || nextMode === this.queryMode) {
|
||
return;
|
||
}
|
||
|
||
this.queryMode = nextMode;
|
||
const keyword = this.normalizeKeyword(this.keyword);
|
||
if (!keyword) {
|
||
this.list = this.applyQueryModeFilter(this.rawList);
|
||
return;
|
||
}
|
||
|
||
this.handleSearch();
|
||
},
|
||
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) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '';
|
||
}
|
||
|
||
const candidate = item.image || item.image_url || item.img || item.pic || item.photo || item.cover || item.cover_url;
|
||
if (candidate) {
|
||
return String(candidate);
|
||
}
|
||
|
||
if (Array.isArray(item.images) && item.images.length > 0) {
|
||
return String(item.images[0]);
|
||
}
|
||
|
||
if (Array.isArray(item.pics) && item.pics.length > 0) {
|
||
return String(item.pics[0]);
|
||
}
|
||
|
||
return '';
|
||
},
|
||
getImageList(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return [];
|
||
}
|
||
|
||
if (Array.isArray(item.images) && item.images.length > 0) {
|
||
return item.images.map(url => String(url)).filter(Boolean);
|
||
}
|
||
|
||
if (Array.isArray(item.pics) && item.pics.length > 0) {
|
||
return item.pics.map(url => String(url)).filter(Boolean);
|
||
}
|
||
|
||
const single = this.getImageUrl(item);
|
||
return single ? [single] : [];
|
||
},
|
||
getImageThumbList(item) {
|
||
return this.getImageList(item).slice(0, 4);
|
||
},
|
||
getStorageList(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return [];
|
||
}
|
||
|
||
if (Array.isArray(item.storage)) {
|
||
return item.storage.filter(entry => entry && typeof entry === 'object');
|
||
}
|
||
|
||
if (Array.isArray(item.wms_storage)) {
|
||
return item.wms_storage.filter(entry => entry && typeof entry === 'object');
|
||
}
|
||
|
||
return [];
|
||
},
|
||
getBatchStorageList(item) {
|
||
const storageList = this.getStorageList(item);
|
||
if (storageList.length) {
|
||
return storageList;
|
||
}
|
||
|
||
if (item && typeof item === 'object') {
|
||
return [item];
|
||
}
|
||
|
||
return [];
|
||
},
|
||
getStorageItemKey(item, index) {
|
||
if (!item || typeof item !== 'object') {
|
||
return index;
|
||
}
|
||
|
||
return item.id || item.space_id || item.storage_id || item.space_barcode || item.space_name || index;
|
||
},
|
||
getBatchStorageItemKey(sourceItem, storageItem, index) {
|
||
if (!storageItem || typeof storageItem !== 'object') {
|
||
return this.getStorageItemKey(sourceItem, index);
|
||
}
|
||
|
||
return storageItem.id
|
||
|| storageItem.batch_id
|
||
|| storageItem.space_id
|
||
|| `${this.getBatchNumberBySource(storageItem, sourceItem)}_${this.getStorageSpaceText(storageItem)}_${index}`;
|
||
},
|
||
getBatchNumberBySource(item, fallbackItem) {
|
||
const currentBatch = this.getBatchNumberText(item);
|
||
if (currentBatch !== '--') {
|
||
return currentBatch;
|
||
}
|
||
|
||
return this.getBatchNumberText(fallbackItem);
|
||
},
|
||
getStorageSpaceText(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '--';
|
||
}
|
||
|
||
return item.space_code
|
||
|| item.space?.code
|
||
|| item.space?.space_code
|
||
|| item.space?.name
|
||
|| item.space_name
|
||
|| item.space_barcode
|
||
|| item.location_name
|
||
|| item.position_name
|
||
|| item.name
|
||
|| '--';
|
||
},
|
||
getStorageQuantityText(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '--';
|
||
}
|
||
|
||
return this.getValueOrDash(
|
||
item.quantity
|
||
?? item.actual_quantity
|
||
?? item.stock
|
||
?? item.total_quantity
|
||
?? item.qty
|
||
);
|
||
},
|
||
getStorageAvailableText(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return '--';
|
||
}
|
||
|
||
return this.getValueOrDash(
|
||
item.available_quantity
|
||
?? item.movable_quantity
|
||
?? item.moveable_quantity
|
||
?? item.can_move_quantity
|
||
?? item.free_quantity
|
||
?? item.usable_quantity
|
||
);
|
||
},
|
||
getExtraImageCount(item) {
|
||
const total = this.getImageList(item).length;
|
||
return total > 4 ? total - 4 : 0;
|
||
},
|
||
previewProductImage(item) {
|
||
const urls = this.getImageList(item);
|
||
if (!urls.length) {
|
||
uni.showToast({
|
||
title: '暂无可预览图片',
|
||
icon: 'none'
|
||
});
|
||
return;
|
||
}
|
||
|
||
uni.previewImage({
|
||
current: urls[0],
|
||
urls
|
||
});
|
||
},
|
||
goProductDetail(item) {
|
||
if (!item || typeof item !== 'object') {
|
||
return;
|
||
}
|
||
|
||
const cacheKey = `product_detail_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||
uni.setStorageSync(cacheKey, item);
|
||
uni.navigateTo({
|
||
url: `/pages/work/product/detail?cacheKey=${cacheKey}`
|
||
});
|
||
},
|
||
async handleSearch() {
|
||
const keyword = this.normalizeKeyword(this.keyword);
|
||
this.keyword = keyword;
|
||
console.log('[ProductQuery] 搜索内容:', keyword, '模式:', this.queryMode);
|
||
if (!keyword) {
|
||
this.rawList = [];
|
||
this.list = [];
|
||
console.log('[ProductQuery] 搜索内容为空,结果已清空');
|
||
return;
|
||
}
|
||
|
||
const isBarcodeKeyword = this.isBarcodeLike(keyword);
|
||
const queryParams = this.buildQueryParams(keyword);
|
||
console.log('[ProductQuery] 搜索参数:', queryParams);
|
||
|
||
this.loading = true;
|
||
try {
|
||
const res = await this.$http('stock.warehouse.search', queryParams);
|
||
|
||
if (res && res.code === 200) {
|
||
const responseData = res.data;
|
||
let nextList = [];
|
||
if (Array.isArray(responseData)) {
|
||
nextList = responseData;
|
||
} else if (responseData && Array.isArray(responseData.list)) {
|
||
nextList = responseData.list;
|
||
} else if (responseData && Array.isArray(responseData.rows)) {
|
||
nextList = responseData.rows;
|
||
} else if (responseData && Array.isArray(responseData.data)) {
|
||
nextList = responseData.data;
|
||
}
|
||
|
||
this.rawList = nextList;
|
||
this.updateDisplayListByMode(nextList, keyword, isBarcodeKeyword);
|
||
console.log('[ProductQuery] 搜索结果数量:', this.list.length);
|
||
console.log('[ProductQuery] 搜索结果列表:', this.list);
|
||
} else {
|
||
this.rawList = [];
|
||
this.list = [];
|
||
console.log('[ProductQuery] 搜索失败响应:', res);
|
||
uni.showToast({
|
||
title: (res && res.message) || '查询失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
} catch (error) {
|
||
this.rawList = [];
|
||
this.list = [];
|
||
console.error('[ProductQuery] 搜索异常:', error);
|
||
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;
|
||
}
|
||
|
||
.page-header {
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 20;
|
||
background: #fff;
|
||
flex-shrink: 0;
|
||
box-shadow: 0 2rpx 10rpx rgba(15, 23, 42, 0.04);
|
||
}
|
||
|
||
.search-panel {
|
||
padding: 20rpx;
|
||
background: #fff;
|
||
border-bottom: 1rpx solid #f2f2f2;
|
||
flex-shrink: 0;
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
|
||
::v-deep .nav-title .right {
|
||
width: auto;
|
||
min-width: 182rpx;
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.nav-mode-switch-group {
|
||
height: 50rpx;
|
||
padding: 3rpx;
|
||
border-radius: 26rpx;
|
||
background: #edf2ff;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
box-sizing: border-box;
|
||
border: 1rpx solid #dbe7ff;
|
||
}
|
||
|
||
.nav-mode-switch-btn {
|
||
min-width: 76rpx;
|
||
height: 42rpx;
|
||
padding: 0 14rpx;
|
||
border-radius: 21rpx;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
transition: all 0.2s ease;
|
||
|
||
&__text {
|
||
font-size: 20rpx;
|
||
font-weight: 600;
|
||
color: #5f6b7a;
|
||
line-height: 1;
|
||
}
|
||
|
||
&:active {
|
||
opacity: 0.88;
|
||
}
|
||
}
|
||
|
||
.nav-mode-switch-btn--active {
|
||
background: #2979ff;
|
||
box-shadow: 0 3rpx 8rpx rgba(41, 121, 255, 0.18);
|
||
|
||
.nav-mode-switch-btn__text {
|
||
color: #fff;
|
||
}
|
||
}
|
||
|
||
.search-input-wrap {
|
||
position: relative;
|
||
|
||
::v-deep .u-search {
|
||
width: 100%;
|
||
}
|
||
|
||
::v-deep .u-search__content {
|
||
padding-right: 200rpx;
|
||
}
|
||
|
||
::v-deep .u-search__content__close {
|
||
margin-right: 12rpx;
|
||
}
|
||
}
|
||
|
||
.search-actions {
|
||
position: absolute;
|
||
right: 24rpx;
|
||
top: 50%;
|
||
transform: translateY(-50%);
|
||
height: 68rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.scan-btn {
|
||
height: 68rpx;
|
||
padding: 0 8rpx 0 4rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
|
||
&:active {
|
||
opacity: 0.88;
|
||
}
|
||
}
|
||
|
||
.search-divider {
|
||
width: 1rpx;
|
||
height: 28rpx;
|
||
background: #dcdfe6;
|
||
margin: 0 16rpx 0 10rpx;
|
||
}
|
||
|
||
.search-btn {
|
||
height: 68rpx;
|
||
padding: 0 8rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
|
||
&__text {
|
||
font-size: 30rpx;
|
||
font-weight: 500;
|
||
color: #2979ff;
|
||
line-height: 1;
|
||
}
|
||
|
||
&:active {
|
||
opacity: 0.88;
|
||
}
|
||
}
|
||
|
||
.list-content {
|
||
flex: 1;
|
||
min-height: 0;
|
||
height: auto;
|
||
position: relative;
|
||
z-index: 0;
|
||
}
|
||
|
||
.list-wrap {
|
||
padding: 20rpx 8rpx;
|
||
}
|
||
|
||
.goods-item {
|
||
background: #fff;
|
||
border-radius: 12rpx;
|
||
padding: 10rpx 16rpx;
|
||
margin-bottom: 20rpx;
|
||
border: 1rpx solid #e9edf3;
|
||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
|
||
position: relative;
|
||
}
|
||
|
||
.item-main-row {
|
||
display: flex;
|
||
align-items: center;
|
||
position: relative;
|
||
padding-right: 92rpx;
|
||
}
|
||
|
||
.item-thumb {
|
||
width: 140rpx;
|
||
margin-right: 20rpx;
|
||
margin-top: 0;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.goods-image {
|
||
border-radius: 10rpx;
|
||
overflow: hidden;
|
||
background: #f5f7fa;
|
||
}
|
||
|
||
.goods-image-grid {
|
||
width: 140rpx;
|
||
height: 140rpx;
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
justify-content: space-between;
|
||
align-content: space-between;
|
||
}
|
||
|
||
.grid-cell {
|
||
position: relative;
|
||
width: 68rpx;
|
||
height: 68rpx;
|
||
border-radius: 8rpx;
|
||
overflow: hidden;
|
||
background: #f5f7fa;
|
||
}
|
||
|
||
.grid-image {
|
||
border-radius: 8rpx;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.image-placeholder {
|
||
width: 100%;
|
||
height: 140rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #f5f7fa;
|
||
}
|
||
|
||
.image-placeholder-small {
|
||
height: 68rpx;
|
||
}
|
||
|
||
.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: 22rpx;
|
||
color: #fff;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.item-info {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.item-arrow {
|
||
position: absolute;
|
||
right: -16rpx;
|
||
top: 50%;
|
||
transform: translateY(-50%);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 112rpx;
|
||
height: 112rpx;
|
||
z-index: 1;
|
||
}
|
||
|
||
.item-title-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 10rpx;
|
||
}
|
||
|
||
.goods-name {
|
||
font-size: 42rpx;
|
||
color: #303133;
|
||
font-weight: 600;
|
||
flex: 1;
|
||
padding-right: 20rpx;
|
||
}
|
||
|
||
.item-row {
|
||
display: flex;
|
||
align-items: center;
|
||
flex-wrap: nowrap;
|
||
line-height: 1.4;
|
||
margin-bottom: 2rpx;
|
||
}
|
||
|
||
.item-row:last-child {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
.storage-section {
|
||
margin-top: 10rpx;
|
||
padding-top: 10rpx;
|
||
border-top: 1rpx solid #eef1f6;
|
||
}
|
||
|
||
.storage-scroll {
|
||
width: 100%;
|
||
white-space: nowrap;
|
||
border-radius: 10rpx;
|
||
border: 1rpx solid #dfe7f5;
|
||
background: #f8faff;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.storage-table {
|
||
background: #f8faff;
|
||
overflow: visible;
|
||
border: 0;
|
||
display: inline-block;
|
||
vertical-align: top;
|
||
}
|
||
|
||
.storage-table--non-batch {
|
||
min-width: 680rpx;
|
||
}
|
||
|
||
.storage-table--batch {
|
||
min-width: 860rpx;
|
||
}
|
||
|
||
.storage-table__row {
|
||
display: flex;
|
||
align-items: center;
|
||
min-height: 48rpx;
|
||
padding: 0 8rpx;
|
||
border-bottom: 1rpx solid #e8eef7;
|
||
}
|
||
|
||
.storage-table__row:last-child {
|
||
border-bottom: 0;
|
||
}
|
||
|
||
.storage-table__head {
|
||
background: #edf4ff;
|
||
border-bottom: 1rpx solid #dbe6f7;
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 8;
|
||
box-shadow: 0 2rpx 6rpx rgba(219, 230, 247, 0.65);
|
||
}
|
||
|
||
.storage-col {
|
||
font-size: 33rpx;
|
||
color: #606266;
|
||
line-height: 1.4;
|
||
padding: 10rpx 0;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
text-align: center;
|
||
border-right: 1rpx solid #e8eef7;
|
||
}
|
||
|
||
.storage-table__row .storage-col:last-child {
|
||
border-right: 0;
|
||
}
|
||
|
||
.storage-col--space {
|
||
flex: 1.1;
|
||
}
|
||
|
||
.storage-col--batch {
|
||
flex: 1;
|
||
}
|
||
|
||
.storage-col--qty {
|
||
flex: 0.72;
|
||
}
|
||
|
||
.storage-table--batch .storage-col--qty {
|
||
flex: 0.62;
|
||
padding-left: 2rpx;
|
||
padding-right: 2rpx;
|
||
}
|
||
|
||
.storage-col--highlight {
|
||
color: #2979ff;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.label {
|
||
width: auto;
|
||
margin-right: 6rpx;
|
||
font-size: 35rpx;
|
||
color: #909399;
|
||
white-space: nowrap;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.value {
|
||
flex: 1;
|
||
font-size: 35rpx;
|
||
color: #000;
|
||
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;
|
||
}
|
||
|
||
.end-tip {
|
||
padding: 8rpx 0 20rpx;
|
||
text-align: center;
|
||
font-size: 22rpx;
|
||
color: #c0c4cc;
|
||
}
|
||
</style>
|