Showing
6 changed files
with
55 additions
and
32 deletions
@@ -54,9 +54,10 @@ export default { | @@ -54,9 +54,10 @@ export default { | ||
54 | } | 54 | } |
55 | }); | 55 | }); |
56 | }, | 56 | }, |
57 | - ...mapActions(['getDetail']), | 57 | + ...mapActions(['getDetail', 'fetchProductFav']), |
58 | ...mapMutations({ | 58 | ...mapMutations({ |
59 | - fetchArticleDetail: 'FETCH_GUANG_SUCCESS' | 59 | + fetchArticleDetail: 'FETCH_GUANG_SUCCESS', |
60 | + fetchArticleProductList: 'GUANG_DETAIL_PRODUCT_LIST' | ||
60 | }), | 61 | }), |
61 | fetch(params) { | 62 | fetch(params) { |
62 | this.articleId = params.articleId; | 63 | this.articleId = params.articleId; |
@@ -65,6 +66,12 @@ export default { | @@ -65,6 +66,12 @@ export default { | ||
65 | return this.getDetail({ | 66 | return this.getDetail({ |
66 | article_id: params.articleId, | 67 | article_id: params.articleId, |
67 | grass_id: params.grassId | 68 | grass_id: params.grassId |
69 | + }).then(() => { | ||
70 | + this.$sdk.getUser().then(user => { | ||
71 | + if (user && user.uid) { | ||
72 | + this.fetchProductFav(); | ||
73 | + } | ||
74 | + }); | ||
68 | }); | 75 | }); |
69 | }, | 76 | }, |
70 | onClose() { | 77 | onClose() { |
@@ -74,6 +81,7 @@ export default { | @@ -74,6 +81,7 @@ export default { | ||
74 | async reset() { | 81 | async reset() { |
75 | await sleep.sleep(200); | 82 | await sleep.sleep(200); |
76 | this.fetchArticleDetail({}); | 83 | this.fetchArticleDetail({}); |
84 | + this.fetchArticleProductList([]); | ||
77 | } | 85 | } |
78 | }, | 86 | }, |
79 | computed: { | 87 | computed: { |
@@ -2,7 +2,6 @@ import * as Types from './types'; | @@ -2,7 +2,6 @@ import * as Types from './types'; | ||
2 | import { get } from 'lodash'; | 2 | import { get } from 'lodash'; |
3 | import * as guangProcess from './guangProcess'; | 3 | import * as guangProcess from './guangProcess'; |
4 | import * as sleep from '../../utils/sleep'; | 4 | import * as sleep from '../../utils/sleep'; |
5 | -import sdk from 'common/sdk'; | ||
6 | 5 | ||
7 | export default { | 6 | export default { |
8 | async fetchArticleList({ commit }, { articleId, authorUid, authorType, limit = 5, page = 1, thumb = false }) { | 7 | async fetchArticleList({ commit }, { articleId, authorUid, authorType, limit = 5, page = 1, thumb = false }) { |
@@ -171,39 +170,28 @@ export default { | @@ -171,39 +170,28 @@ export default { | ||
171 | 170 | ||
172 | await sleep.sleep(200); | 171 | await sleep.sleep(200); |
173 | commit(Types.GUANG_ARTICLE_CONTENT, processContents.finalDetail); | 172 | commit(Types.GUANG_ARTICLE_CONTENT, processContents.finalDetail); |
173 | + commit(Types.GUANG_DETAIL_PRODUCT_LIST, processContents.allgoods); | ||
174 | 174 | ||
175 | //再处理其他信息 | 175 | //再处理其他信息 |
176 | - const [goodsList, favsList, zan, article] = await Promise.all([ | 176 | + const [goodsList, zan, article] = await Promise.all([ |
177 | this.$api.post('/api/guang/article/queryGoods', { | 177 | this.$api.post('/api/guang/article/queryGoods', { |
178 | query: processContents.allgoods.skn.join(','), | 178 | query: processContents.allgoods.skn.join(','), |
179 | order: 's_t_desc', | 179 | order: 's_t_desc', |
180 | limit: processContents.allgoods.skn.length || 1 | 180 | limit: processContents.allgoods.skn.length || 1 |
181 | }), | 181 | }), |
182 | - sdk.getUser().then((u) => { | ||
183 | - if (u && u.uid) { | ||
184 | - return this.$api.post('/api/favorite/batchCheckIsFavorite', { | ||
185 | - favIds: processContents.allgoods.id.join(','), | ||
186 | - type: 'product' | ||
187 | - }); | ||
188 | - } else { | ||
189 | - return {}; | ||
190 | - } | ||
191 | - }), | ||
192 | this.$api.post('/api/guang/article/zan', { articleId: grass_id }), | 182 | this.$api.post('/api/guang/article/zan', { articleId: grass_id }), |
193 | this.$api.get('/api/guang/article/detail', { article_id }) | 183 | this.$api.get('/api/guang/article/detail', { article_id }) |
194 | - ]).then(([res1, res2, res3, res4]) => { | 184 | + ]).then(([res1, res2, res3]) => { |
195 | return [ | 185 | return [ |
196 | get(res1, 'data.product_list', []), | 186 | get(res1, 'data.product_list', []), |
197 | - get(res2, 'data', []), | ||
198 | - get(res3, 'data', false), | ||
199 | - get(res4, 'data', false) | 187 | + get(res2, 'data', false), |
188 | + get(res3, 'data', false) | ||
200 | ]; | 189 | ]; |
201 | }); | 190 | }); |
202 | 191 | ||
203 | result.getArticleContent = guangProcess.pushGoodsInfo( | 192 | result.getArticleContent = guangProcess.pushGoodsInfo( |
204 | processContents.finalDetail, | 193 | processContents.finalDetail, |
205 | - goodsList, | ||
206 | - favsList | 194 | + goodsList |
207 | ); | 195 | ); |
208 | 196 | ||
209 | result.getRecommendProducts = processContents.recommends; | 197 | result.getRecommendProducts = processContents.recommends; |
@@ -229,8 +217,21 @@ export default { | @@ -229,8 +217,21 @@ export default { | ||
229 | } | 217 | } |
230 | 218 | ||
231 | // 等待动画完成后,提交数据 | 219 | // 等待动画完成后,提交数据 |
220 | + commit(Types.FETCH_GUANG_SUCCESS, result); | ||
221 | + }, | ||
232 | 222 | ||
223 | + async fetchProductFav({ commit, state }) { | ||
224 | + if (!state.articleProductList.id.length) { | ||
225 | + return; | ||
226 | + } | ||
233 | 227 | ||
234 | - commit(Types.FETCH_GUANG_SUCCESS, result); | 228 | + const favsList = await this.$api.post('/api/favorite/batchCheckIsFavorite', { |
229 | + favIds: state.articleProductList.id.join(','), | ||
230 | + type: 'product' | ||
231 | + }).then(result => { | ||
232 | + return get(result, 'data', []); | ||
233 | + }); | ||
234 | + | ||
235 | + commit(Types.GUANG_CHANGE_PRODUCT_FAV, favsList); | ||
235 | } | 236 | } |
236 | }; | 237 | }; |
@@ -237,8 +237,8 @@ export function processArticleDetail(articleContent) { | @@ -237,8 +237,8 @@ export function processArticleDetail(articleContent) { | ||
237 | /** | 237 | /** |
238 | * 商品搜索商品数据处理 | 238 | * 商品搜索商品数据处理 |
239 | */ | 239 | */ |
240 | -function processProductList(list, favsList) { | ||
241 | - const pruductList = []; | 240 | +function processProductList(list) { |
241 | + const productList = []; | ||
242 | 242 | ||
243 | forEach(list, (product) => { | 243 | forEach(list, (product) => { |
244 | if (!product) { | 244 | if (!product) { |
@@ -269,7 +269,7 @@ function processProductList(list, favsList) { | @@ -269,7 +269,7 @@ function processProductList(list, favsList) { | ||
269 | product.data.shopUrl = '//m.yohobuy.com/product/shop?domain=' + product.data.shop_domain; | 269 | product.data.shopUrl = '//m.yohobuy.com/product/shop?domain=' + product.data.shop_domain; |
270 | } | 270 | } |
271 | 271 | ||
272 | - pruductList.push(product); | 272 | + productList.push(product); |
273 | } | 273 | } |
274 | 274 | ||
275 | return; | 275 | return; |
@@ -294,12 +294,9 @@ function processProductList(list, favsList) { | @@ -294,12 +294,9 @@ function processProductList(list, favsList) { | ||
294 | product.cn_alphabet = productNameProcess(product.cn_alphabet); | 294 | product.cn_alphabet = productNameProcess(product.cn_alphabet); |
295 | } | 295 | } |
296 | 296 | ||
297 | - // fav | ||
298 | - const fav = favsList.find(i => `${i.id}` === `${product.product_id}`); | ||
299 | - | ||
300 | product.id = product.product_id; | 297 | product.id = product.product_id; |
301 | product.productType = 1; | 298 | product.productType = 1; |
302 | - product.favorite = get(fav, 'favorite', false); | 299 | + product.favorite = false; |
303 | 300 | ||
304 | /** | 301 | /** |
305 | * 全球购商品标记 | 302 | * 全球购商品标记 |
@@ -321,10 +318,10 @@ function processProductList(list, favsList) { | @@ -321,10 +318,10 @@ function processProductList(list, favsList) { | ||
321 | product.url = productUrl(product.product_skn); | 318 | product.url = productUrl(product.product_skn); |
322 | } | 319 | } |
323 | 320 | ||
324 | - pruductList.push(product); | 321 | + productList.push(product); |
325 | }); | 322 | }); |
326 | 323 | ||
327 | - return pruductList; | 324 | + return productList; |
328 | } | 325 | } |
329 | 326 | ||
330 | const _goodsArrayToObj = (goodsArray) => { | 327 | const _goodsArrayToObj = (goodsArray) => { |
@@ -336,8 +333,8 @@ const _goodsArrayToObj = (goodsArray) => { | @@ -336,8 +333,8 @@ const _goodsArrayToObj = (goodsArray) => { | ||
336 | /** | 333 | /** |
337 | * 重新获取商品数据 | 334 | * 重新获取商品数据 |
338 | */ | 335 | */ |
339 | -export function pushGoodsInfo(finalDetail, goodsList, favsList) { | ||
340 | - let goodsObj = _goodsArrayToObj(processProductList(goodsList, favsList)); | 336 | +export function pushGoodsInfo(finalDetail, goodsList) { |
337 | + let goodsObj = _goodsArrayToObj(processProductList(goodsList)); | ||
341 | 338 | ||
342 | finalDetail = cloneDeep(finalDetail); | 339 | finalDetail = cloneDeep(finalDetail); |
343 | 340 |
@@ -15,6 +15,7 @@ export default function() { | @@ -15,6 +15,7 @@ export default function() { | ||
15 | articleUserThumbList: [], | 15 | articleUserThumbList: [], |
16 | fetchArticleDetail: false, | 16 | fetchArticleDetail: false, |
17 | articleDetail: {}, | 17 | articleDetail: {}, |
18 | + articleProductList: [], | ||
18 | articleLastedTimeByTopic: 0, | 19 | articleLastedTimeByTopic: 0, |
19 | articleStates: {} | 20 | articleStates: {} |
20 | }, | 21 | }, |
@@ -194,5 +194,19 @@ export default { | @@ -194,5 +194,19 @@ export default { | ||
194 | [Types.FETCH_GUANG_SUCCESS](state, data) { | 194 | [Types.FETCH_GUANG_SUCCESS](state, data) { |
195 | state.fetchArticleDetail = false; | 195 | state.fetchArticleDetail = false; |
196 | state.articleDetail = data; | 196 | state.articleDetail = data; |
197 | + }, | ||
198 | + [Types.GUANG_DETAIL_PRODUCT_LIST](state, data) { | ||
199 | + state.articleProductList = data; | ||
200 | + }, | ||
201 | + [Types.GUANG_CHANGE_PRODUCT_FAV](state, favsList) { | ||
202 | + get(state.articleDetail, 'getArticleContent', []).forEach(c => { | ||
203 | + const products = get(c, 'relatedReco.goods', []); | ||
204 | + | ||
205 | + products.forEach(p => { | ||
206 | + const fav = favsList.find(i => `${i.id}` === `${p.product_id}`); | ||
207 | + | ||
208 | + p.favorite = get(fav, 'favorite', false); | ||
209 | + }); | ||
210 | + }); | ||
197 | } | 211 | } |
198 | }; | 212 | }; |
@@ -18,6 +18,8 @@ export const FETCH_GUANG_SUCCESS = 'FETCH_GUANG_SUCCESS'; | @@ -18,6 +18,8 @@ export const FETCH_GUANG_SUCCESS = 'FETCH_GUANG_SUCCESS'; | ||
18 | export const FETCH_FAV_SUCCESS = 'FETCH_FAV_SUCCESS'; | 18 | export const FETCH_FAV_SUCCESS = 'FETCH_FAV_SUCCESS'; |
19 | export const FETCH_ZAN_SUCCESS = 'FETCH_ZAN_SUCCESS'; | 19 | export const FETCH_ZAN_SUCCESS = 'FETCH_ZAN_SUCCESS'; |
20 | export const GUANG_ARTICLE_CONTENT = 'GUANG_ARTICLE_CONTENT'; | 20 | export const GUANG_ARTICLE_CONTENT = 'GUANG_ARTICLE_CONTENT'; |
21 | +export const GUANG_CHANGE_PRODUCT_FAV = 'GUANG_CHANGE_PRODUCT_FAV'; | ||
22 | +export const GUANG_DETAIL_PRODUCT_LIST = 'GUANG_DETAIL_PRODUCT_LIST'; | ||
21 | 23 | ||
22 | export const CHANGE_AUTHOR_FOLLOW = 'CHANGE_AUTHOR_FOLLOW'; | 24 | export const CHANGE_AUTHOR_FOLLOW = 'CHANGE_AUTHOR_FOLLOW'; |
23 | export const CHANGE_ARTICLE_LIST_SLIDE = 'CHANGE_ARTICLE_LIST_SLIDE'; | 25 | export const CHANGE_ARTICLE_LIST_SLIDE = 'CHANGE_ARTICLE_LIST_SLIDE'; |
-
Please register or login to post a comment