diff --git a/core/request/apis.js b/core/request/apis.js index c8f963a..d3ae0c7 100644 --- a/core/request/apis.js +++ b/core/request/apis.js @@ -139,6 +139,18 @@ export default { } }, inventory: { + list: { + path: "storage.inventory.list", + auth: true, + method: "POST", + isSystemApi: true + }, + transferByProduct: { + path: "storage.inventory.transferByProduct", + auth: true, + method: "POST", + isSystemApi: true + }, transferLocation: { path: "storage.inventory.transferLocation", auth: true, diff --git a/pages/work/product/query.vue b/pages/work/product/query.vue index a76f5db..855a1dc 100644 --- a/pages/work/product/query.vue +++ b/pages/work/product/query.vue @@ -756,6 +756,7 @@ const values = [ item.id, + item.stock_id, item.goods_id, item.item_id, item.product_id, @@ -773,7 +774,7 @@ .filter(Boolean) )]; }, - mergeProductResultLists(searchList, detailList) { + mergeProductResultLists(searchList, warehouseList, detailList) { const mergedMap = new Map(); const upsert = (sourceItem, preferSource = false) => { if (!sourceItem || typeof sourceItem !== 'object') { @@ -792,8 +793,9 @@ }); }; - (detailList || []).forEach(item => upsert(item, false)); - (searchList || []).forEach(item => upsert(item, true)); + (searchList || []).forEach(item => upsert(item, false)); + (warehouseList || []).forEach(item => upsert(item, true)); + (detailList || []).forEach(item => upsert(item, true)); const uniqueItems = []; const seen = new Set(); @@ -850,31 +852,94 @@ is_batch: this.queryMode === 'batch' }; }, - buildListWhereParams(keyword) { - const where = {}; + buildWarehouseListWhereParams(keyword) { + const normalized = this.normalizeKeyword(keyword); + if (!normalized) { + return {}; + } - if (this.isBarcodeLike(keyword)) { - where.barcode = { - operator: 'like', - value: keyword, - type: 'string' - }; - } else if (keyword) { - where.item_name = { - operator: 'like', - value: keyword, - type: 'string' + if (this.isBarcodeLike(normalized)) { + return { + barcode: { + operator: 'like', + value: normalized, + type: 'string' + } }; } - return where; - }, - buildListQueryParams(keyword) { return { - keyword, + item_name: { + operator: 'like', + value: normalized, + type: 'string' + } + }; + }, + buildWarehouseListQueryParams(keyword) { + return { with_stock: true, is_batch: this.queryMode === 'batch', - where: this.buildListWhereParams(keyword) + where: this.buildWarehouseListWhereParams(keyword), + pagination: { + page: 1, + pageSize: 20 + } + }; + }, + buildListWhereParams(stockIdList) { + const normalizedStockIdList = this.extractStockIdList(stockIdList); + if (!normalizedStockIdList.length) { + return {}; + } + + return { + stock_id: { + field: 'stock_id', + operator: 'in', + type: 'array', + value: normalizedStockIdList + } + }; + }, + extractStockIdList(source) { + const sourceList = Array.isArray(source) ? source : []; + const idSet = new Set(); + sourceList.forEach(item => { + if (!item || typeof item !== 'object') { + return; + } + + const stockIdCandidates = [ + item.stock_id, + item.goods_id, + item.item_id, + item.product_id, + item.id + ]; + + stockIdCandidates.forEach(candidate => { + const normalized = this.normalizePositiveId(candidate); + if (normalized) { + idSet.add(normalized); + } + }); + }); + + return [...idSet]; + }, + buildListQueryParams(stockIdList) { + return { + where: this.buildListWhereParams(stockIdList), + pagination: { + page: 1, + pageSize: 20 + }, + sort: { + sortField: 'created_at', + sortOrder: 'DESC' + }, + group_by_batch: this.queryMode === 'batch' }; }, setQueryMode(nextMode) { @@ -1132,13 +1197,7 @@ const directCandidates = [ item.storage_id, - item.inventory_id, - item.stock_id, - item.storage_record_id, - item.stock_record_id, - item.warehouse_storage_id, - item.warehouse_stock_id, - item.record_id + item.id ]; for (let i = 0; i < directCandidates.length; i++) { @@ -1148,17 +1207,29 @@ } } - const fallbackId = this.normalizePositiveId(item.id); - if (!fallbackId) { + return null; + }, + getRelocationProductStockId(item) { + if (!item || typeof item !== 'object') { return null; } - const spaceId = this.normalizePositiveId(item.space_id || item.space?.id); - if (spaceId && fallbackId === spaceId) { - return null; + const directCandidates = [ + item.stock_id, + item.goods_id, + item.item_id, + item.product_id, + item.id + ]; + + for (let i = 0; i < directCandidates.length; i++) { + const normalized = this.normalizePositiveId(directCandidates[i]); + if (normalized) { + return normalized; + } } - return fallbackId; + return null; }, openRelocationPage(productItem, storageItem, quantityType = 'available') { if (!productItem || typeof productItem !== 'object' || !storageItem || typeof storageItem !== 'object') { @@ -1169,8 +1240,14 @@ return; } + const isNonBatchMode = this.queryMode === 'nonBatch'; const relocationStorageId = this.getRelocationStorageId(storageItem) || this.getRelocationStorageId(productItem); - if (!relocationStorageId) { + const relocationProductStockId = this.getRelocationProductStockId(storageItem) || this.getRelocationProductStockId(productItem); + const sourceSpaceId = this.normalizePositiveId( + storageItem.space_id || storageItem.space?.id || productItem.space_id || productItem.space?.id + ); + + if (!isNonBatchMode && !relocationStorageId) { uni.showToast({ title: '未获取到库存记录ID', icon: 'none' @@ -1178,15 +1255,25 @@ return; } + if (isNonBatchMode && (!sourceSpaceId || !relocationProductStockId)) { + uni.showToast({ + title: '未获取到库位或商品ID', + icon: 'none' + }); + return; + } + const cacheKey = `relocation_prefill_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`; uni.setStorageSync(cacheKey, { stock: { ...productItem, ...storageItem, - relocation_storage_id: relocationStorageId + relocation_storage_id: relocationStorageId, + relocation_product_stock_id: relocationProductStockId, + relocation_query_mode: this.queryMode }, sourceSpace: { - id: storageItem.space_id || storageItem.space?.id || null, + id: sourceSpaceId || null, name: this.getStorageSpaceText(storageItem), code: this.getStorageSpaceCode(storageItem) }, @@ -1247,27 +1334,36 @@ const isBarcodeKeyword = this.isBarcodeLike(keyword); const queryParams = this.buildQueryParams(keyword); - const listQueryParams = this.buildListQueryParams(keyword); + let listQueryParams = null; console.log('[ProductQuery] 搜索参数:', queryParams); - console.log('[ProductQuery] 列表参数:', listQueryParams); this.loading = true; try { - const [searchRes, listRes] = await Promise.all([ - this.$http('stock.warehouse.search', queryParams), - this.$http('stock.warehouse.list', listQueryParams).catch(error => { - console.warn('[ProductQuery] stock.warehouse.list 调用失败:', error); - return null; - }) - ]); + const searchRes = await this.$http('stock.warehouse.search', queryParams); + const warehouseRes = await this.$http('stock.warehouse.list', this.buildWarehouseListQueryParams(keyword)).catch(error => { + console.warn('[ProductQuery] stock.warehouse.list 调用失败:', error); + return null; + }); const searchOk = searchRes && searchRes.code === 200; + const warehouseOk = warehouseRes && warehouseRes.code === 200; + const nextList = searchOk ? this.extractListFromResponse(searchRes) : []; + const warehouseList = warehouseOk ? this.extractListFromResponse(warehouseRes) : []; + const stockIdList = this.extractStockIdList([].concat(nextList || [], warehouseList || [])); + listQueryParams = this.buildListQueryParams(stockIdList); + console.log('[ProductQuery] 列表参数:', listQueryParams); + + const listRes = stockIdList.length + ? await this.$http('storage.inventory.list', listQueryParams).catch(error => { + console.warn('[ProductQuery] storage.inventory.list 调用失败:', error); + return null; + }) + : null; const listOk = listRes && listRes.code === 200; - if (searchOk || listOk) { - const nextList = searchOk ? this.extractListFromResponse(searchRes) : []; + if (searchOk || warehouseOk || listOk) { const detailList = listOk ? this.extractListFromResponse(listRes) : []; - const mergedList = this.mergeProductResultLists(nextList, detailList); + const mergedList = this.mergeProductResultLists(nextList, warehouseList, detailList); this.rawList = mergedList; this.updateDisplayListByMode(mergedList, keyword, isBarcodeKeyword); @@ -1278,7 +1374,7 @@ this.list = []; console.log('[ProductQuery] 搜索失败响应:', searchRes || listRes); uni.showToast({ - title: (searchRes && searchRes.message) || (listRes && listRes.message) || '查询失败', + title: (searchRes && searchRes.message) || (warehouseRes && warehouseRes.message) || (listRes && listRes.message) || '查询失败', icon: 'none' }); } @@ -1693,15 +1789,15 @@ } .storage-table--batch .storage-col { - font-size: 28rpx; + font-size: 32rpx; } .storage-table--batch .storage-col--batch { - flex: 0.78; + flex: 0.62; } .storage-table--batch .storage-col--space { - flex: 0.82; + flex: 0.68; } .storage-table__row { @@ -1718,7 +1814,7 @@ } .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); + grid-template-columns: minmax(0, 0.62fr) minmax(0, 0.68fr) minmax(0, 0.46fr) minmax(0, 0.46fr); } .storage-table__row:last-child { @@ -1757,7 +1853,7 @@ justify-content: center; width: 100%; min-width: 0; - font-size: 33rpx; + font-size: 35rpx; color: #606266; line-height: 1.2; padding: 8rpx 4rpx; diff --git a/pages/work/storage/relocation.vue b/pages/work/storage/relocation.vue index e5595e6..66e6359 100644 --- a/pages/work/storage/relocation.vue +++ b/pages/work/storage/relocation.vue @@ -1,34 +1,35 @@