diff --git a/src/views/PickupLocationModal.vue b/src/views/PickupLocationModal.vue index 5a667656..f7cbec28 100644 --- a/src/views/PickupLocationModal.vue +++ b/src/views/PickupLocationModal.vue @@ -163,21 +163,34 @@ export default defineComponent({ } }, - async checkInventory(facilityIds: Array) { - const productIds = this.shipGroup.items.map((item: any) => item.productId) + async checkInventory(facilityIds: Array, productIds: Array) { + let isScrollable = true, viewSize = 250, viewIndex = 0, total = 0; + let productInventoryResp = [] as any; + try { - const productInventoryResp = await StockService.checkInventory({ - "filters": { - "productId": productIds, - "facilityId": facilityIds - }, - "fieldsToSelect": ["productId", "atp", "facilityName", "facilityId"], - }); + while(isScrollable) { + const resp = await StockService.checkInventory({ + "filters": { + "productId": productIds, + "facilityId": facilityIds + }, + "fieldsToSelect": ["productId", "atp", "facilityName", "facilityId"], + viewSize, + viewIndex + }); - if (hasError(productInventoryResp) || !productInventoryResp.data.count) { - return []; + if(!hasError(resp) && resp.data.count) { + if(!productInventoryResp.length) { + productInventoryResp = resp.data.docs + total = resp.data.count; + } else { + productInventoryResp = productInventoryResp.concat(resp.data.docs) + } + if(productInventoryResp.length >= total) isScrollable = false; + viewIndex++; + } } - return productInventoryResp.data.docs.filter((store: any) => store.atp > 0) + return productInventoryResp.filter((store: any) => store.atp > 0) } catch (error) { console.error(error) } @@ -199,10 +212,10 @@ export default defineComponent({ if (!stores?.length) return; const facilityIds = stores.map((store: any) => store.storeCode) - const storesWithInventory = await this.checkInventory(facilityIds) + const productIds = [...new Set(this.shipGroup.items.map((item: any) => item.productId))] as any; + const storesWithInventory = await this.checkInventory(facilityIds, productIds) if (!storesWithInventory?.length) return; - const productIds = this.shipGroup.items.map((item: any) => item.productId) stores.map((storeData: any) => { const inventoryDetails = storesWithInventory.filter((store: any) => store.facilityId === storeData.storeCode);