Authored by TaoHuang

fix fav request

... ... @@ -54,9 +54,10 @@ export default {
}
});
},
...mapActions(['getDetail']),
...mapActions(['getDetail', 'fetchProductFav']),
...mapMutations({
fetchArticleDetail: 'FETCH_GUANG_SUCCESS'
fetchArticleDetail: 'FETCH_GUANG_SUCCESS',
fetchArticleProductList: 'GUANG_DETAIL_PRODUCT_LIST'
}),
fetch(params) {
this.articleId = params.articleId;
... ... @@ -65,6 +66,12 @@ export default {
return this.getDetail({
article_id: params.articleId,
grass_id: params.grassId
}).then(() => {
this.$sdk.getUser().then(user => {
if (user && user.uid) {
this.fetchProductFav();
}
});
});
},
onClose() {
... ... @@ -74,6 +81,7 @@ export default {
async reset() {
await sleep.sleep(200);
this.fetchArticleDetail({});
this.fetchArticleProductList([]);
}
},
computed: {
... ...
... ... @@ -2,7 +2,6 @@ import * as Types from './types';
import { get } from 'lodash';
import * as guangProcess from './guangProcess';
import * as sleep from '../../utils/sleep';
import sdk from 'common/sdk';
export default {
async fetchArticleList({ commit }, { articleId, authorUid, authorType, limit = 5, page = 1, thumb = false }) {
... ... @@ -171,39 +170,28 @@ export default {
await sleep.sleep(200);
commit(Types.GUANG_ARTICLE_CONTENT, processContents.finalDetail);
commit(Types.GUANG_DETAIL_PRODUCT_LIST, processContents.allgoods);
//再处理其他信息
const [goodsList, favsList, zan, article] = await Promise.all([
const [goodsList, zan, article] = await Promise.all([
this.$api.post('/api/guang/article/queryGoods', {
query: processContents.allgoods.skn.join(','),
order: 's_t_desc',
limit: processContents.allgoods.skn.length || 1
}),
sdk.getUser().then((u) => {
if (u && u.uid) {
return this.$api.post('/api/favorite/batchCheckIsFavorite', {
favIds: processContents.allgoods.id.join(','),
type: 'product'
});
} else {
return {};
}
}),
this.$api.post('/api/guang/article/zan', { articleId: grass_id }),
this.$api.get('/api/guang/article/detail', { article_id })
]).then(([res1, res2, res3, res4]) => {
]).then(([res1, res2, res3]) => {
return [
get(res1, 'data.product_list', []),
get(res2, 'data', []),
get(res3, 'data', false),
get(res4, 'data', false)
get(res2, 'data', false),
get(res3, 'data', false)
];
});
result.getArticleContent = guangProcess.pushGoodsInfo(
processContents.finalDetail,
goodsList,
favsList
goodsList
);
result.getRecommendProducts = processContents.recommends;
... ... @@ -229,8 +217,21 @@ export default {
}
// 等待动画完成后,提交数据
commit(Types.FETCH_GUANG_SUCCESS, result);
},
async fetchProductFav({ commit, state }) {
if (!state.articleProductList.id.length) {
return;
}
commit(Types.FETCH_GUANG_SUCCESS, result);
const favsList = await this.$api.post('/api/favorite/batchCheckIsFavorite', {
favIds: state.articleProductList.id.join(','),
type: 'product'
}).then(result => {
return get(result, 'data', []);
});
commit(Types.GUANG_CHANGE_PRODUCT_FAV, favsList);
}
};
... ...
... ... @@ -237,8 +237,8 @@ export function processArticleDetail(articleContent) {
/**
* 商品搜索商品数据处理
*/
function processProductList(list, favsList) {
const pruductList = [];
function processProductList(list) {
const productList = [];
forEach(list, (product) => {
if (!product) {
... ... @@ -269,7 +269,7 @@ function processProductList(list, favsList) {
product.data.shopUrl = '//m.yohobuy.com/product/shop?domain=' + product.data.shop_domain;
}
pruductList.push(product);
productList.push(product);
}
return;
... ... @@ -294,12 +294,9 @@ function processProductList(list, favsList) {
product.cn_alphabet = productNameProcess(product.cn_alphabet);
}
// fav
const fav = favsList.find(i => `${i.id}` === `${product.product_id}`);
product.id = product.product_id;
product.productType = 1;
product.favorite = get(fav, 'favorite', false);
product.favorite = false;
/**
* 全球购商品标记
... ... @@ -321,10 +318,10 @@ function processProductList(list, favsList) {
product.url = productUrl(product.product_skn);
}
pruductList.push(product);
productList.push(product);
});
return pruductList;
return productList;
}
const _goodsArrayToObj = (goodsArray) => {
... ... @@ -336,8 +333,8 @@ const _goodsArrayToObj = (goodsArray) => {
/**
* 重新获取商品数据
*/
export function pushGoodsInfo(finalDetail, goodsList, favsList) {
let goodsObj = _goodsArrayToObj(processProductList(goodsList, favsList));
export function pushGoodsInfo(finalDetail, goodsList) {
let goodsObj = _goodsArrayToObj(processProductList(goodsList));
finalDetail = cloneDeep(finalDetail);
... ...
... ... @@ -15,6 +15,7 @@ export default function() {
articleUserThumbList: [],
fetchArticleDetail: false,
articleDetail: {},
articleProductList: [],
articleLastedTimeByTopic: 0,
articleStates: {}
},
... ...
... ... @@ -194,5 +194,19 @@ export default {
[Types.FETCH_GUANG_SUCCESS](state, data) {
state.fetchArticleDetail = false;
state.articleDetail = data;
},
[Types.GUANG_DETAIL_PRODUCT_LIST](state, data) {
state.articleProductList = data;
},
[Types.GUANG_CHANGE_PRODUCT_FAV](state, favsList) {
get(state.articleDetail, 'getArticleContent', []).forEach(c => {
const products = get(c, 'relatedReco.goods', []);
products.forEach(p => {
const fav = favsList.find(i => `${i.id}` === `${p.product_id}`);
p.favorite = get(fav, 'favorite', false);
});
});
}
};
... ...
... ... @@ -18,6 +18,8 @@ export const FETCH_GUANG_SUCCESS = 'FETCH_GUANG_SUCCESS';
export const FETCH_FAV_SUCCESS = 'FETCH_FAV_SUCCESS';
export const FETCH_ZAN_SUCCESS = 'FETCH_ZAN_SUCCESS';
export const GUANG_ARTICLE_CONTENT = 'GUANG_ARTICLE_CONTENT';
export const GUANG_CHANGE_PRODUCT_FAV = 'GUANG_CHANGE_PRODUCT_FAV';
export const GUANG_DETAIL_PRODUCT_LIST = 'GUANG_DETAIL_PRODUCT_LIST';
export const CHANGE_AUTHOR_FOLLOW = 'CHANGE_AUTHOR_FOLLOW';
export const CHANGE_ARTICLE_LIST_SLIDE = 'CHANGE_ARTICLE_LIST_SLIDE';
... ...