13
13
</ion-toolbar >
14
14
</ion-header >
15
15
<ion-content >
16
- <div v-if =" !queryString.length" class =" ion-text-center" >
17
- <p >{{ searchPriority == 'zipCode' ? $t("Enter zip code to search stores nearby") : $t('Enter keyword to search stores') }}</p >
18
- </div >
16
+ <div v-if =" isloading" class =" empty-state" >
17
+ <ion-spinner name =" crescent" />
18
+ <p >{{ $t("Fetching stores") }}</p >
19
+ </div >
19
20
20
21
<div v-else-if =" !nearbyStores.length" class =" ion-text-center" >
21
22
<p >{{ searchPriority == 'zipCode' ? $t("No stores found. Please search another zip code.") : $t("No stores found. Please search another store.") }}</p >
22
23
</div >
23
24
24
- <ion-list v-else >
25
+ <ion-list v-else >
25
26
<ion-list-header v-if =" searchPriority == 'zipCode'" lines =" full" color =" light" >
26
27
<ion-label >{{ $t("Nearby stores") }}</ion-label >
27
28
</ion-list-header >
28
29
<ion-radio-group v-model =" selectedFacility" >
29
30
<ion-item v-for =" store of nearbyStores" :key =" store.facilityId" >
30
- <ion-radio :value =" store" slot =" start" />
31
+ <ion-radio :disabled = " !store.atp " : value =" store" slot =" start" />
31
32
<ion-label >
32
- <h2 >{{ store.facilityName }}</h2 >
33
- <p >{{ store.atp }} {{ $t("in stock") }}</p >
33
+ <h2 >{{ store.facilityName || store.storeName }}</h2 >
34
+ <p v-if =" store.atp" >{{ store.atp }} {{ $t("in stock") }}</p >
35
+ <p v-else >{{ $t("No inventory") }}</p >
34
36
</ion-label >
35
37
<ion-label v-if =" store.distance" slot =" end" >{{ store.distance }} {{ $t("mi") }}</ion-label >
36
38
</ion-item >
@@ -57,6 +59,7 @@ import {
57
59
IonRadio ,
58
60
IonRadioGroup ,
59
61
IonSearchbar ,
62
+ IonSpinner ,
60
63
IonTitle ,
61
64
IonToolbar ,
62
65
loadingController ,
@@ -86,6 +89,7 @@ export default defineComponent({
86
89
IonRadio ,
87
90
IonRadioGroup ,
88
91
IonSearchbar ,
92
+ IonSpinner ,
89
93
IonTitle ,
90
94
IonToolbar
91
95
},
@@ -96,7 +100,8 @@ export default defineComponent({
96
100
nearbyStores: [] as any ,
97
101
selectedFacility: {} as any ,
98
102
searchPriority: ' zipCode' ,
99
- filters: process .env .VUE_APP_DEFAULT_STORETYPE
103
+ filters: process .env .VUE_APP_DEFAULT_STORETYPE ,
104
+ isloading: false
100
105
}
101
106
},
102
107
props: [" item" , " facilityId" ],
@@ -106,20 +111,43 @@ export default defineComponent({
106
111
shop: ' shop/getShop'
107
112
})
108
113
},
109
- mounted() {
114
+ async mounted() {
115
+ this .isloading = true
110
116
const shopifyShops = JSON .parse (process .env .VUE_APP_DEFAULT_SHOP_CONFIG )
111
117
const shopConfiguration = shopifyShops [this .shop ]
112
118
113
119
if (shopConfiguration ) {
114
120
this .searchPriority = shopConfiguration .search
115
121
this .filters = shopConfiguration .filters
116
122
}
123
+
124
+ try {
125
+ const stores = await this .getStores (" " )
126
+ if (! stores ?.length ) return ;
127
+
128
+ const facilityIds = stores .map ((store : any ) => store .storeCode )
129
+ const storesWithInventory = await this .checkInventory (facilityIds )
130
+
131
+ stores .map ((storeData : any ) => {
132
+ const inventoryDetails = storesWithInventory .find ((store : any ) => store .facilityId === storeData .storeCode );
133
+ // only add stores information in array when having inventory for that store
134
+ if (inventoryDetails ) {
135
+ this .nearbyStores .push ({ ... storeData , ... inventoryDetails , distance: storeData .dist });
136
+ } else {
137
+ this .nearbyStores .push ({ ... storeData , atp: 0 });
138
+ }
139
+ });
140
+ } catch (err ) {
141
+ console .error (err )
142
+ } finally {
143
+ this .isloading = false
144
+ }
117
145
},
118
146
methods: {
119
147
async presentLoader() {
120
148
this .loader = await loadingController
121
149
.create ({
122
- message: this .$t (" Fetching stores. " ),
150
+ message: this .$t (" Fetching stores" ),
123
151
translucent: true ,
124
152
});
125
153
await this .loader .present ();
@@ -134,7 +162,7 @@ export default defineComponent({
134
162
135
163
async getStores(location : string ) {
136
164
const payload = {
137
- " viewSize" : 50 ,
165
+ " viewSize" : 10 ,
138
166
" filters" : this .filters ,
139
167
" keyword" : this .queryString
140
168
} as any
@@ -180,7 +208,7 @@ export default defineComponent({
180
208
});
181
209
182
210
if (hasError (productInventoryResp ) || ! productInventoryResp .data .count ) return [];
183
- return productInventoryResp .data .docs . filter (( store : any ) => store . atp > 0 )
211
+ return productInventoryResp .data .docs ;
184
212
} catch (error ) {
185
213
console .error (error )
186
214
}
@@ -190,7 +218,7 @@ export default defineComponent({
190
218
this .queryString = event .target .value .trim ();
191
219
if (! this .queryString ) return
192
220
this .nearbyStores = [];
193
- await this .presentLoader ()
221
+ this .isloading = true ;
194
222
try {
195
223
let location = ' '
196
224
@@ -205,19 +233,20 @@ export default defineComponent({
205
233
206
234
const facilityIds = stores .map ((store : any ) => store .storeCode )
207
235
const storesWithInventory = await this .checkInventory (facilityIds )
208
- if (! storesWithInventory ?.length ) return ;
209
236
210
237
stores .map ((storeData : any ) => {
211
238
const inventoryDetails = storesWithInventory .find ((store : any ) => store .facilityId === storeData .storeCode );
212
239
// only add stores information in array when having inventory for that store
213
240
if (inventoryDetails ) {
214
241
this .nearbyStores .push ({ ... storeData , ... inventoryDetails , distance: storeData .dist });
215
- }
242
+ } else {
243
+ this .nearbyStores .push ({ ... storeData , atp: 0 });
244
+ }
216
245
});
217
246
} catch (error ) {
218
247
console .error (error )
219
248
} finally {
220
- this .dismissLoader ()
249
+ this .isloading = false
221
250
}
222
251
},
223
252
0 commit comments