...
|
...
|
@@ -33,6 +33,10 @@ const { |
|
|
GET_WEIXIN_PUBLIC_SUCCESS,
|
|
|
GET_WEIXIN_PUBLIC_FAILURE,
|
|
|
|
|
|
PRODUCT_BY_SKNS_REQUEST,
|
|
|
PRODUCT_BY_SKNS_SUCCESS,
|
|
|
PRODUCT_BY_SKNS_FAILURE,
|
|
|
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function setArticleId(id) {
|
...
|
...
|
@@ -181,6 +185,14 @@ export function getArticleContent(reload = false) { |
|
|
.then(json => {
|
|
|
let payload = parseArticleContent(json);
|
|
|
|
|
|
payload.map((item, i) => {
|
|
|
if (item.template_name == 'goods') {
|
|
|
dispatch(goodsProductBySkns(item, i));
|
|
|
} else if (item.template_name == 'goods_group') {
|
|
|
dispatch(goodsGroupProductBySkns(item, i));
|
|
|
}
|
|
|
});
|
|
|
|
|
|
dispatch(getArticleContentSuccess(payload));
|
|
|
// dispatch(dataExposure(payload.logFloors));
|
|
|
})
|
...
|
...
|
@@ -192,6 +204,8 @@ export function getArticleContent(reload = false) { |
|
|
|
|
|
function parseArticleContent(json) {
|
|
|
let contents = [];
|
|
|
let goodsSkns = [];
|
|
|
let groupGoodsSkns = [];
|
|
|
|
|
|
json && json.map((item, i) => {
|
|
|
for (let i in item) {
|
...
|
...
|
@@ -230,6 +244,152 @@ function parseArticleContent(json) { |
|
|
return contents;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* [获取商品的ICON]
|
|
|
* @param {[int]} type [类型]
|
|
|
* @return {[type]}
|
|
|
*/
|
|
|
function getProductIcon(type) {
|
|
|
const icons = {
|
|
|
1: 'cloth',
|
|
|
3: 'pants',
|
|
|
4: 'dress',
|
|
|
6: 'shoe',
|
|
|
7: 'bag',
|
|
|
10: 'lamp',
|
|
|
241: 'headset',
|
|
|
8: 'watch',
|
|
|
360: 'swim-suit',
|
|
|
308: 'under'
|
|
|
};
|
|
|
|
|
|
return icons[type] || '';
|
|
|
}
|
|
|
|
|
|
function productBySknsRequest() {
|
|
|
return {
|
|
|
type: PRODUCT_BY_SKNS_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function productBySknsSuccess(json) {
|
|
|
return {
|
|
|
type: PRODUCT_BY_SKNS_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function productBySknsFailure(error) {
|
|
|
return {
|
|
|
type: PRODUCT_BY_SKNS_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function goodsProductBySkns(item, contentIndex) {
|
|
|
return (dispatch, getState) => {
|
|
|
let skns = [];
|
|
|
let productImages = {};
|
|
|
// 遍历取得SKN
|
|
|
item.data.map((item2) => {
|
|
|
skns.push(item2.id);
|
|
|
productImages[item2.id] = item2.src;
|
|
|
});
|
|
|
|
|
|
if (!skns) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let {app, detail} = getState();
|
|
|
|
|
|
dispatch(productBySknsRequest());
|
|
|
return new DetailService(app.host).productInfoBySkns(skns)
|
|
|
.then(json => {
|
|
|
let productList = [];
|
|
|
let result = json.product_list.slice(0, 3);
|
|
|
result.map((item3, i3) => {
|
|
|
let src = productImages[item3.product_skn];
|
|
|
if (src) {
|
|
|
item3.tags = [];
|
|
|
item3.default_images = helper.image(src, 235, 314);
|
|
|
productList.push(item3);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
dispatch(productBySknsSuccess({
|
|
|
productList,
|
|
|
contentIndex,
|
|
|
}));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(productBySknsFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function goodsGroupProductBySkns(item, contentIndex) {
|
|
|
return (dispatch, getState) => {
|
|
|
let skns = [];
|
|
|
let productImages = {};
|
|
|
|
|
|
// 遍历取得SKN
|
|
|
item.data.map((item2) => {
|
|
|
item2.list.map((item3) => {
|
|
|
skns.push(item3.id);
|
|
|
productImages[item3.id] = item3.src;
|
|
|
});
|
|
|
});
|
|
|
|
|
|
if (!skns) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let {app, detail} = getState();
|
|
|
|
|
|
dispatch(productBySknsRequest());
|
|
|
return new DetailService(app.host).productInfoBySkns(skns)
|
|
|
.then(json => {
|
|
|
let products = {};
|
|
|
let result = json.product_list;
|
|
|
result.map((item4) => {
|
|
|
let src = productImages[item4.product_skn];
|
|
|
if (src) {
|
|
|
item4.tags = [];
|
|
|
item4.default_images = helper.image(src, 235, 314);
|
|
|
products[item4.product_skn] = item4;
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
let productList = []
|
|
|
item.data.map((item5) => {
|
|
|
let good = {
|
|
|
thumb: item5.cover ? helper.image(item5.cover.cover, 235, 314) : '',
|
|
|
type: item5.cover ? getProductIcon(item5.cover.maxSortId) : '',
|
|
|
list: [],
|
|
|
};
|
|
|
|
|
|
item5.list.map((item6) => {
|
|
|
let product = products[item6.id];
|
|
|
if (product) {
|
|
|
good.list.push(product);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
productList.push(good);
|
|
|
});
|
|
|
|
|
|
dispatch(productBySknsSuccess({
|
|
|
productList,
|
|
|
contentIndex,
|
|
|
}));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(productBySknsFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function getBrandRequest() {
|
|
|
return {
|
|
|
type: GET_BRAND_REQUEST,
|
...
|
...
|
|