diff --git a/pages/work/product/query.vue b/pages/work/product/query.vue index 64f488c..00336dc 100644 --- a/pages/work/product/query.vue +++ b/pages/work/product/query.vue @@ -45,38 +45,10 @@ + - - - - - - - - - @@ -161,8 +133,8 @@ - - + + - - {{ getStorageSpaceText(storageItem) }} - {{ getStorageQuantityText(storageItem) }} - {{ getStorageAvailableText(storageItem) }} + + + 暂无库存数据 - - + + - - {{ getBatchNumberBySource(storageItem, item) }} - {{ getStorageSpaceText(storageItem) }} - {{ getStorageQuantityText(storageItem) }} - {{ getStorageAvailableText(storageItem) }} + + + 暂无库存数据 @@ -255,6 +241,7 @@ storageSectionMetas: [], storageHeaderHeight: 0, pageHeaderHeight: 0, + storageMetaRefreshTimer: null, floatingStorageHeader: { visible: false, mode: 'nonBatch', @@ -263,6 +250,33 @@ } } }, + computed: { + showGlobalStorageHeader() { + if (this.loading || !Array.isArray(this.list) || !this.list.length) { + return false; + } + + return this.list.some(item => { + const storageList = this.queryMode === 'batch' + ? this.getBatchStorageList(item) + : this.getStorageList(item); + return Array.isArray(storageList) && storageList.length > 0; + }); + }, + globalStorageHeaderTop() { + const visualOffset = 0; + const currentTop = Number(this.floatingStorageHeader.top || 0); + if (currentTop > 0) { + return currentTop; + } + const firstMeta = Array.isArray(this.storageSectionMetas) && this.storageSectionMetas.length + ? this.storageSectionMetas[0] + : null; + const summaryHeight = Number((firstMeta && firstMeta.summaryHeight) || 0); + const summaryGap = Number((firstMeta && firstMeta.summaryGap) || 0); + return this.pageHeaderHeight + summaryHeight + summaryGap + visualOffset; + } + }, onLoad() { this.safeDispatchBroadcast('setCallbacks', { onResult: this.handleBroadcastResult @@ -288,6 +302,10 @@ this.safeDispatchBroadcast('pause'); }, onUnload() { + if (this.storageMetaRefreshTimer) { + clearTimeout(this.storageMetaRefreshTimer); + this.storageMetaRefreshTimer = null; + } this.safeDispatchBroadcast('stop'); }, methods: { @@ -306,6 +324,9 @@ handleListScroll(event) { const top = event && event.detail ? Number(event.detail.scrollTop || 0) : 0; this.listScrollTopCache = top; + if ((!this.storageSectionMetas.length || !this.pageHeaderHeight) && this.list.length) { + this.scheduleRefreshStorageSectionMetas(); + } this.updateFloatingStorageHeader(top); }, getStorageSectionKey(item, index, mode = 'nonBatch') { @@ -338,6 +359,71 @@ transform: `translateX(-${scrollLeft}px)` }; }, + getLocalStorageHeadWrapStyle(sectionKey, zIndex = 1) { + const meta = (this.storageSectionMetas || []).find(item => item && item.key === sectionKey); + const top = Math.max( + Number((meta && meta.summaryHeight) || 0) + Number((meta && meta.summaryGap) || 0), + 0 + ); + return { + top: `${top}px`, + '--storage-head-offset': `${top}px`, + zIndex + }; + }, + waitForNextTick() { + return new Promise(resolve => { + this.$nextTick(resolve); + }); + }, + wait(ms = 0) { + return new Promise(resolve => { + setTimeout(resolve, ms); + }); + }, + scheduleRefreshStorageSectionMetas(delays = [0, 80, 200, 400]) { + if (!Array.isArray(delays) || !delays.length) { + return; + } + + if (this.storageMetaRefreshTimer) { + clearTimeout(this.storageMetaRefreshTimer); + this.storageMetaRefreshTimer = null; + } + + const queue = [...delays]; + const run = () => { + const delay = Number(queue.shift() || 0); + this.storageMetaRefreshTimer = setTimeout(() => { + this.refreshStorageSectionMetas(); + if (queue.length) { + run(); + } else { + this.storageMetaRefreshTimer = null; + } + }, delay); + }; + + run(); + }, + async ensureStorageSectionMetasReady() { + if (!this.list.length) { + return; + } + + const delays = [0, 60, 120, 240, 400]; + for (let i = 0; i < delays.length; i++) { + await this.wait(delays[i]); + await this.waitForNextTick(); + this.refreshStorageSectionMetas(); + await this.wait(40); + + if (this.storageSectionMetas.length && this.pageHeaderHeight) { + this.updateFloatingStorageHeader(this.listScrollTopCache); + return; + } + } + }, refreshStorageSectionMetas() { this.$nextTick(() => { const query = uni.createSelectorQuery().in(this); @@ -345,13 +431,15 @@ query.select('.list-content').boundingClientRect(); query.select('.storage-head-fixed').boundingClientRect(); query.selectAll('.item-summary').boundingClientRect(); + query.selectAll('.storage-head-fixed').boundingClientRect(); query.selectAll('.storage-section').boundingClientRect(); query.exec(result => { const pageHeaderRect = result && result[0] ? result[0] : null; const listRect = result && result[1] ? result[1] : null; const headerRect = result && result[2] ? result[2] : null; const summaryRects = (result && result[3]) || []; - const sectionRects = (result && result[4]) || []; + const storageHeadRects = (result && result[4]) || []; + const sectionRects = (result && result[5]) || []; this.pageHeaderHeight = pageHeaderRect && pageHeaderRect.height ? Number(pageHeaderRect.height) : 0; if (!listRect || !Array.isArray(sectionRects) || !sectionRects.length) { this.storageSectionMetas = []; @@ -364,17 +452,12 @@ let sectionCursor = 0; const metas = []; (this.list || []).forEach((item, index) => { - const hasStorage = this.queryMode === 'batch' - ? this.getBatchStorageList(item).length - : this.getStorageList(item).length; - if (!hasStorage) { - return; - } - const rect = sectionRects[sectionCursor++]; + const storageHeadRect = storageHeadRects[sectionCursor - 1]; if (!rect) { return; } + const summaryRect = summaryRects[index] || null; metas.push({ key: this.getStorageSectionKey(item, index, this.queryMode), @@ -382,7 +465,14 @@ top: this.listScrollTopCache + Number(rect.top || 0) - Number(listRect.top || 0), height: Number(rect.height || 0), headerHeight, - summaryHeight: Number((summaryRects[index] && summaryRects[index].height) || 0) + summaryHeight: Number((summaryRect && summaryRect.height) || 0), + summaryGap: Math.max( + Number((storageHeadRect && storageHeadRect.top) || rect.top || 0) - ( + Number((summaryRect && summaryRect.top) || 0) + + Number((summaryRect && summaryRect.height) || 0) + ), + 0 + ) }); }); @@ -394,8 +484,9 @@ }, updateFloatingStorageHeader(scrollTop = 0) { const passedMetas = this.storageSectionMetas.filter(meta => { - const summaryHeight = Number(meta.summaryHeight || 0); - const startTop = meta.top - summaryHeight; + const startTop = meta.top + - Math.max(Number(meta.summaryHeight || 0), 0) + - Math.max(Number(meta.summaryGap || 0), 0); return scrollTop >= startTop; }); const activeMeta = passedMetas.length ? passedMetas[passedMetas.length - 1] : null; @@ -414,7 +505,19 @@ visible: true, mode: activeMeta.mode, sectionKey: activeMeta.key, - top: this.pageHeaderHeight + Math.max(Number(activeMeta.summaryHeight || 0), 0) + top: this.pageHeaderHeight + Math.max( + Math.max(Number(activeMeta.summaryHeight || 0), 0) + + Math.max(Number(activeMeta.summaryGap || 0), 0) + - Math.max( + scrollTop - ( + activeMeta.top + - Math.max(Number(activeMeta.summaryHeight || 0), 0) + - Math.max(Number(activeMeta.summaryGap || 0), 0) + ), + 0 + ), + 0 + ) }; }, normalizeKeyword(value) { @@ -581,12 +684,16 @@ values = values.concat(item.barcodes.split(/[;,,\s]+/)); } - if (item.barcode) { - values.push(item.barcode); - } - if (item.code) { - values.push(item.code); - } + values = values.concat([ + item.barcode, + item.code, + item.item_barcode, + item.goods_barcode, + item.product_barcode, + item.sku_barcode, + item.bar_code, + item.qr_code + ]); return [...new Set(values .map(code => this.normalizeKeyword(code)) @@ -601,6 +708,80 @@ return (list || []).filter(item => this.extractBarcodeList(item).includes(target)); }, + extractListFromResponse(response) { + const responseData = response && response.data; + if (Array.isArray(responseData)) { + return responseData; + } + if (responseData && Array.isArray(responseData.list)) { + return responseData.list; + } + if (responseData && Array.isArray(responseData.rows)) { + return responseData.rows; + } + if (responseData && Array.isArray(responseData.data)) { + return responseData.data; + } + return []; + }, + getProductMatchKeys(item) { + if (!item || typeof item !== 'object') { + return []; + } + + const values = [ + item.id, + item.goods_id, + item.item_id, + item.product_id, + item.goods_code, + item.item_code, + item.product_code, + item.barcode, + item.code + ]; + + const barcodeList = this.extractBarcodeList(item); + return [...new Set(values + .concat(barcodeList) + .map(value => this.normalizeKeyword(value)) + .filter(Boolean) + )]; + }, + mergeProductResultLists(searchList, detailList) { + const mergedMap = new Map(); + const upsert = (sourceItem, preferSource = false) => { + if (!sourceItem || typeof sourceItem !== 'object') { + return; + } + + const keys = this.getProductMatchKeys(sourceItem); + const matchedKey = keys.find(key => mergedMap.has(key)); + const baseItem = matchedKey ? mergedMap.get(matchedKey) : null; + const mergedItem = baseItem + ? (preferSource ? { ...baseItem, ...sourceItem } : { ...sourceItem, ...baseItem }) + : { ...sourceItem }; + + keys.forEach(key => { + mergedMap.set(key, mergedItem); + }); + }; + + (detailList || []).forEach(item => upsert(item, false)); + (searchList || []).forEach(item => upsert(item, true)); + + const uniqueItems = []; + const seen = new Set(); + mergedMap.forEach(item => { + if (seen.has(item)) { + return; + } + seen.add(item); + uniqueItems.push(item); + }); + + return uniqueItems; + }, getProductName(item) { if (!item || typeof item !== 'object') { return ''; @@ -635,7 +816,7 @@ : this.filterByNameContains(sourceList, keyword); this.list = this.applyQueryModeFilter(filteredByKeyword); - this.refreshStorageSectionMetas(); + this.scheduleRefreshStorageSectionMetas(); }, buildQueryParams(keyword) { return { @@ -653,7 +834,7 @@ const keyword = this.normalizeKeyword(this.keyword); if (!keyword) { this.list = this.applyQueryModeFilter(this.rawList); - this.refreshStorageSectionMetas(); + this.scheduleRefreshStorageSectionMetas(); return; } @@ -736,6 +917,60 @@ return []; }, + hasDirectStorageData(item) { + if (!item || typeof item !== 'object') { + return false; + } + + return [ + item.space_code, + item.space_name, + item.space_barcode, + item.location_name, + item.position_name, + item.quantity, + item.actual_quantity, + item.stock, + item.total_quantity, + item.qty, + item.available_quantity, + item.movable_quantity, + item.moveable_quantity, + item.can_move_quantity, + item.free_quantity, + item.usable_quantity + ].some(value => value !== null && value !== undefined && value !== ''); + }, + getBatchStorageDisplayList(item) { + const storageList = this.getStorageList(item); + if (storageList.length) { + return storageList; + } + + return this.hasDirectStorageData(item) ? [item] : []; + }, + getStorageDisplayList(item, mode = 'nonBatch') { + return mode === 'batch' ? this.getBatchStorageDisplayList(item) : this.getStorageList(item); + }, + getStorageRowCount(item, mode = 'nonBatch') { + const list = this.getStorageDisplayList(item, mode); + return Math.max(Array.isArray(list) ? list.length : 0, 1); + }, + shouldEnableStorageVerticalScroll(item, mode = 'nonBatch') { + return this.getStorageRowCount(item, mode) > 4; + }, + getStorageBodyStyle(item, mode = 'nonBatch') { + const minRows = 1; + const maxRows = 4; + const rowHeight = 56; + const rowCount = this.getStorageRowCount(item, mode); + const visibleRows = Math.min(Math.max(rowCount, minRows), maxRows); + return { + minHeight: `${minRows * rowHeight}rpx`, + maxHeight: `${maxRows * rowHeight}rpx`, + height: `${visibleRows * rowHeight}rpx` + }; + }, getStorageItemKey(item, index) { if (!item || typeof item !== 'object') { return index; @@ -858,31 +1093,32 @@ this.loading = true; try { - const res = await this.$http('stock.warehouse.search', queryParams); + const [searchRes, listRes] = await Promise.all([ + this.$http('stock.warehouse.search', queryParams), + this.$http('stock.warehouse.list', queryParams).catch(error => { + console.warn('[ProductQuery] stock.warehouse.list 调用失败:', error); + return null; + }) + ]); - 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; - } + const searchOk = searchRes && searchRes.code === 200; + const listOk = listRes && listRes.code === 200; - this.rawList = nextList; - this.updateDisplayListByMode(nextList, keyword, isBarcodeKeyword); + if (searchOk || listOk) { + const nextList = searchOk ? this.extractListFromResponse(searchRes) : []; + const detailList = listOk ? this.extractListFromResponse(listRes) : []; + const mergedList = this.mergeProductResultLists(nextList, detailList); + + this.rawList = mergedList; + this.updateDisplayListByMode(mergedList, keyword, isBarcodeKeyword); console.log('[ProductQuery] 搜索结果数量:', this.list.length); console.log('[ProductQuery] 搜索结果列表:', this.list); } else { this.rawList = []; this.list = []; - console.log('[ProductQuery] 搜索失败响应:', res); + console.log('[ProductQuery] 搜索失败响应:', searchRes || listRes); uni.showToast({ - title: (res && res.message) || '查询失败', + title: (searchRes && searchRes.message) || (listRes && listRes.message) || '查询失败', icon: 'none' }); } @@ -896,6 +1132,13 @@ }); } finally { this.loading = false; + if (this.list.length) { + await this.waitForNextTick(); + await this.ensureStorageSectionMetasReady(); + this.refreshStorageSectionMetas(); + this.updateFloatingStorageHeader(this.listScrollTopCache); + this.scheduleRefreshStorageSectionMetas([30, 120, 260, 520]); + } } } } @@ -1069,20 +1312,6 @@ z-index: 0; } - .floating-storage-head { - position: fixed; - left: 24rpx; - right: 24rpx; - overflow: hidden; - border: 1rpx solid #dfe7f5; - border-bottom: 0; - border-radius: 10rpx 10rpx 0 0; - background: #edf4ff; - box-sizing: border-box; - z-index: 40; - pointer-events: none; - } - .list-wrap { padding: 20rpx 8rpx; } @@ -1227,20 +1456,36 @@ } .storage-section { - margin-top: 10rpx; - padding-top: 10rpx; - border-top: 1rpx solid #eef1f6; + margin-top: 20rpx; + padding-top: 0; + border-top: 0; position: relative; } .storage-head-fixed { - position: relative; - overflow: hidden; + position: sticky; + left: 0; + overflow: visible; + margin-bottom: 0; border: 1rpx solid #dfe7f5; border-bottom: 0; border-radius: 10rpx 10rpx 0 0; background: #edf4ff; box-sizing: border-box; + z-index: 20; + isolation: isolate; + + &::before { + content: ''; + position: absolute; + left: -2rpx; + right: -2rpx; + top: calc(var(--storage-head-offset, 0px) * -1); + height: calc(var(--storage-head-offset, 0px) + 2rpx); + background: #fff; + pointer-events: none; + z-index: 19; + } } .storage-scroll { @@ -1250,9 +1495,17 @@ border: 1rpx solid #dfe7f5; background: #f8faff; box-sizing: border-box; + overflow: hidden; + + ::v-deep .uni-scroll-view-content, + ::v-deep .uni-scroll-view { + padding-top: 0 !important; + margin-top: 0 !important; + } } .storage-scroll--body { + margin-top: -1rpx; border-top: 0; border-radius: 0 0 10rpx 10rpx; } @@ -1261,8 +1514,9 @@ background: #f8faff; overflow: visible; border: 0; - display: inline-block; - vertical-align: top; + display: block; + width: 100%; + box-sizing: border-box; } .storage-table--head-table { @@ -1275,15 +1529,36 @@ } .storage-table--batch { - min-width: 860rpx; + min-width: 680rpx; + } + + .storage-table--batch .storage-col { + font-size: 28rpx; + } + + .storage-table--batch .storage-col--batch { + flex: 0.78; + } + + .storage-table--batch .storage-col--space { + flex: 0.82; } .storage-table__row { - display: flex; + display: grid; align-items: center; min-height: 48rpx; - padding: 0 8rpx; + padding: 0; border-bottom: 1rpx solid #e8eef7; + box-sizing: border-box; + } + + .storage-table--non-batch .storage-table__row { + grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.72fr) minmax(0, 0.72fr); + } + + .storage-table--batch .storage-table__row { + grid-template-columns: minmax(0, 0.78fr) minmax(0, 0.82fr) minmax(0, 0.42fr) minmax(0, 0.42fr); } .storage-table__row:last-child { @@ -1294,20 +1569,44 @@ background: #edf4ff; border-bottom: 1rpx solid #dbe6f7; position: relative; - z-index: 1; - box-shadow: 0 2rpx 6rpx rgba(219, 230, 247, 0.65); + z-index: 21; + box-shadow: none; + margin-bottom: -1rpx; + border-bottom-color: #e8eef7; + opacity: 1; + } + + .storage-table__head.storage-table__row { + min-height: 48rpx; + padding: 0; + background: #edf4ff; + } + + .storage-table__row--empty { + grid-template-columns: minmax(0, 1fr) !important; + } + + .storage-head-fixed + .storage-table__row { + border-top: 1rpx solid #e8eef7; + margin-top: -1rpx; } .storage-col { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + min-width: 0; font-size: 33rpx; color: #606266; - line-height: 1.4; - padding: 10rpx 0; + line-height: 1.2; + padding: 8rpx 4rpx; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; border-right: 1rpx solid #e8eef7; + box-sizing: border-box; } .storage-table__row .storage-col:last-child { @@ -1315,21 +1614,20 @@ } .storage-col--space { - flex: 1.1; + flex: none; } .storage-col--batch { - flex: 1; + flex: none; } .storage-col--qty { - flex: 0.72; + flex: none; } .storage-table--batch .storage-col--qty { - flex: 0.62; - padding-left: 2rpx; - padding-right: 2rpx; + padding-left: 1rpx; + padding-right: 1rpx; } .storage-col--highlight { @@ -1337,6 +1635,16 @@ font-weight: 600; } + .storage-empty-text { + grid-column: 1 / -1; + border-right: 0 !important; + color: #909399; + font-size: 28rpx; + min-height: 56rpx; + padding-top: 4rpx; + padding-bottom: 4rpx; + } + .label { width: auto; margin-right: 6rpx; diff --git a/pages/work/storage/receiving/receiving.vue b/pages/work/storage/receiving/receiving.vue index 0f88b71..e950d0f 100644 --- a/pages/work/storage/receiving/receiving.vue +++ b/pages/work/storage/receiving/receiving.vue @@ -130,9 +130,24 @@ - 今日 - 本周 - 本月 + + 今日 + + + 昨日 + + + 前日 + + + 3天内 + + + 本周 + + + 本月 + @@ -153,7 +168,7 @@ @change="handleStoreChange" @close="showStore=false"> - + @@ -228,6 +243,13 @@ stores: [], } }, + computed: { + calendarMonthNum() { + const min = new Date(this.minDate); + const max = new Date(this.maxDate); + return (max.getFullYear() - min.getFullYear()) * 12 + (max.getMonth() - min.getMonth()) + 1; + } + }, onLoad() { this.$store.dispatch('broadcast/setCallbacks', { onResult: this.scan @@ -278,6 +300,21 @@ case 'today': startDate = endDate = now; break; + case 'yesterday': + startDate = new Date(now); + startDate.setDate(now.getDate() - 1); + endDate = new Date(startDate); + break; + case 'beforeYesterday': + startDate = new Date(now); + startDate.setDate(now.getDate() - 2); + endDate = new Date(startDate); + break; + case 'last3days': + startDate = new Date(now); + startDate.setDate(now.getDate() - 2); + endDate = now; + break; case 'week': // 本周一 const monday = new Date(now); @@ -894,11 +931,63 @@ } .quick-date-buttons { - display: flex; - gap: 20rpx; + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 24rpx 12rpx; + width: 100%; + padding: 0 12rpx; + box-sizing: border-box; + align-items: stretch; + justify-content: center; + margin: 0 auto; + + &__item { + width: 100%; + display: flex; + + &:not(.is-active) { + ::v-deep .u-btn, + ::v-deep .u-button { + background: #f3f4f6 !important; + border-color: #e5e7eb !important; + box-shadow: none !important; + } + + ::v-deep .u-btn-text, + ::v-deep .u-button__text { + color: #666 !important; + } + } + } ::v-deep .u-btn { - flex: 1; + width: 100%; + min-width: 100%; + height: 76rpx; + padding: 0 12rpx; + margin: 0; + box-sizing: border-box; + font-size: 32rpx; + } + + ::v-deep .u-btn-text { + font-size: 32rpx !important; + font-weight: 500; + } + + ::v-deep .u-button { + width: 100%; + min-width: 100%; + height: 76rpx; + padding: 0 12rpx; + margin: 0; + box-sizing: border-box; + font-size: 32rpx; + } + + ::v-deep .u-button__text { + font-size: 32rpx !important; + font-weight: 500; } } }