Showing
1 changed file
with
30 additions
and
2 deletions
1 | import * as Types from './types'; | 1 | import * as Types from './types'; |
2 | 2 | ||
3 | export default { | 3 | export default { |
4 | - fetchProductFavStatus({commit}, {productId}) { | ||
5 | - commit(Types.FETCH_PRODUCT_FAV_REQUEST, {productId}); | 4 | + fetchProductFavStatus({state, commit}, {productId}) { |
5 | + if (!state.favBatchs.length) { | ||
6 | + commit(Types.FETCH_PRODUCT_FAV_REQUEST, {productId, promise: () => { | ||
7 | + return new Promise((resolve, reject) => { | ||
8 | + setTimeout(async() => { | ||
9 | + let fetchIds; | ||
10 | + | ||
11 | + if (state.favBatchs.some(id => id === productId)) { | ||
12 | + fetchIds = state.favBatchs.map(id => id); | ||
13 | + } else { | ||
14 | + fetchIds = [productId]; | ||
15 | + } | ||
16 | + const result = await this.$api.get('/api/favorite/batchCheckIsFavorite', { | ||
17 | + favIds: fetchIds, | ||
18 | + }); | ||
19 | + | ||
20 | + if (result.code === 200) { | ||
21 | + resolve(result.data); | ||
22 | + } else { | ||
23 | + resolve([]); | ||
24 | + } | ||
25 | + }, 50); | ||
26 | + }); | ||
27 | + }}); | ||
28 | + } else { | ||
29 | + commit(Types.FETCH_PRODUCT_FAV_REQUEST, {productId}); | ||
30 | + } | ||
31 | + | ||
32 | + | ||
33 | + | ||
6 | } | 34 | } |
7 | }; | 35 | }; |
-
Please register or login to post a comment