...
|
...
|
@@ -5,7 +5,319 @@ import NewArrivalService from '../../services/NewArrivalService'; |
|
|
|
|
|
const {
|
|
|
SET_CHANNEL,
|
|
|
|
|
|
|
|
|
RECOMMEND_SHOP_REQUEST,
|
|
|
RECOMMEND_SHOP_SUCCESS,
|
|
|
RECOMMEND_SHOP_FAILURE,
|
|
|
|
|
|
RECOMMEND_BRAND_REQUEST,
|
|
|
RECOMMEND_BRAND_SUCCESS,
|
|
|
RECOMMEND_BRAND_FAILURE,
|
|
|
|
|
|
PRODUCT_LIST_REQUEST,
|
|
|
PRODUCT_LIST_SUCCESS,
|
|
|
PRODUCT_LIST_FAILURE,
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
|
|
|
export function getTopInfo() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app} = getState();
|
|
|
dispatch(topInfoRequest());
|
|
|
return new NewArrivalService(app.host).fetchRecommendShop(channel)
|
|
|
.then(json => {
|
|
|
dispatch(topInfoSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(topInfoFailure(error));
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function topInfoRequest() {
|
|
|
return {
|
|
|
type: RECOMMEND_SHOP_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function topInfoSuccess(json) {
|
|
|
return {
|
|
|
type: RECOMMEND_SHOP_SUCCESS,
|
|
|
payload: json
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function topInfoFailure(error) {
|
|
|
return {
|
|
|
type: RECOMMEND_SHOP_FAILURE,
|
|
|
payload: error
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 底部产品列表
|
|
|
*/
|
|
|
export function getProductList(reload=false) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, newArrival} = getState();
|
|
|
let { productList, filterFactors} = newArrival;
|
|
|
|
|
|
|
|
|
if (reload) {
|
|
|
|
|
|
} else {
|
|
|
if (productList.isFetching || productList.endReached || productList.error) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
let order = productList.order;
|
|
|
let page = productList.currentPage + 1;
|
|
|
let pageSize = productList.pageSize;
|
|
|
let channel = app.channel;
|
|
|
|
|
|
let bSelectedFilterFactor,allFilterFactors;
|
|
|
allFilterFactors = filterFactors.toJS();
|
|
|
|
|
|
for (let prop in allFilterFactors) {
|
|
|
if (allFilterFactors.hasOwnProperty(prop)) {
|
|
|
if (allFilterFactors[prop] === '') {
|
|
|
delete allFilterFactors[prop];
|
|
|
}
|
|
|
if (prop == 'sizeKey') {
|
|
|
allFilterFactors['size'] = allFilterFactors[prop];
|
|
|
delete allFilterFactors[prop];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
dispatch(productListRequest());
|
|
|
return new NewArrivalService(app.host).productList(channel, order, page, pageSize, allFilterFactors)
|
|
|
.then(json => {
|
|
|
let payload = parseProductList(json);
|
|
|
payload.endReached = payload.currentPage == payload.pageCount || payload.list.length < pageSize;
|
|
|
|
|
|
if (payload.currentPage > 1) {
|
|
|
let oldList = productList.list.toJS();
|
|
|
let list = [...oldList, ...payload.list];
|
|
|
payload.list = list;
|
|
|
}
|
|
|
dispatch(productListSuccess(payload));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(productListFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function productListRequest() {
|
|
|
return {
|
|
|
type: PRODUCT_LIST_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function productListSuccess(json) {
|
|
|
return {
|
|
|
type: PRODUCT_LIST_SUCCESS,
|
|
|
payload: json
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function productListFailure(error) {
|
|
|
return {
|
|
|
type: PRODUCT_LIST_FAILURE,
|
|
|
payload: error
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function parseProductList(json) {
|
|
|
let currentPage = json && json.page ? json.page : 1;
|
|
|
let pageCount = json && json.page_total ? json.page_total : 0;
|
|
|
let total = json && json.total ? json.total : 0;
|
|
|
|
|
|
let filter = json && json.filter ? json.filter : {};
|
|
|
let list = json && json.product_list ? json.product_list : [];
|
|
|
let filterCategoryDetailFilterList = {};
|
|
|
let categoryFilterList = [];
|
|
|
|
|
|
if (filter['gender']) {
|
|
|
categoryFilterList.push({
|
|
|
key: 'gender',
|
|
|
name: '性别',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
let genderList = filter['gender'];
|
|
|
let newGenderList =[];
|
|
|
newGenderList.push({
|
|
|
key:'1,2,3',
|
|
|
name: '所有性别',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
for (let gender in genderList) {
|
|
|
if (genderList.hasOwnProperty(gender)) {
|
|
|
newGenderList.push({
|
|
|
key: gender,
|
|
|
name: genderList[gender],
|
|
|
isSelect: false,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
filterCategoryDetailFilterList.gender;
|
|
|
filterCategoryDetailFilterList.gender = newGenderList;
|
|
|
}
|
|
|
|
|
|
if (filter['group_sort']) {
|
|
|
categoryFilterList.push({
|
|
|
key: 'sort',
|
|
|
name: '品类',
|
|
|
isSelect: false,
|
|
|
});
|
|
|
let sortList = filter['group_sort'];
|
|
|
let newSortList = [];
|
|
|
newSortList.push({
|
|
|
key: '',
|
|
|
name: '所有品类',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
sortList.map((item, i) => {
|
|
|
newSortList.push({
|
|
|
key: item.relation_parameter.sort ? item.relation_parameter.sort : '',
|
|
|
name: item.category_name,
|
|
|
isSelect: false,
|
|
|
})
|
|
|
});
|
|
|
filterCategoryDetailFilterList.sort;
|
|
|
filterCategoryDetailFilterList.sort = newSortList;
|
|
|
}
|
|
|
|
|
|
if (filter['brand']) {
|
|
|
categoryFilterList.push({
|
|
|
key: 'brand',
|
|
|
name: '品牌',
|
|
|
isSelect: false,
|
|
|
});
|
|
|
let brandList = filter['brand'];
|
|
|
let newBrandList = [];
|
|
|
newBrandList.push({
|
|
|
key: '',
|
|
|
name: '所有品牌',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
brandList.map((item, i) => {
|
|
|
newBrandList.push({
|
|
|
key: item.id,
|
|
|
name: item.brand_name,
|
|
|
isSelect: false,
|
|
|
})
|
|
|
});
|
|
|
filterCategoryDetailFilterList.brand;
|
|
|
filterCategoryDetailFilterList.brand = newBrandList;
|
|
|
}
|
|
|
|
|
|
if (filter['color']) {
|
|
|
categoryFilterList.push({
|
|
|
key: 'color',
|
|
|
name: '颜色',
|
|
|
isSelect: false,
|
|
|
});
|
|
|
let colorList = filter['color'];
|
|
|
let newColorList = [];
|
|
|
newColorList.push({
|
|
|
key: '',
|
|
|
name: '所有颜色',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
colorList.map((item, i) => {
|
|
|
newColorList.push({
|
|
|
key: item.color_id,
|
|
|
name: item.color_name,
|
|
|
isSelect: false,
|
|
|
});
|
|
|
});
|
|
|
filterCategoryDetailFilterList.color;
|
|
|
filterCategoryDetailFilterList.color = newColorList;
|
|
|
}
|
|
|
|
|
|
if (filter['size']) {
|
|
|
categoryFilterList.push({
|
|
|
key: 'sizeKey',
|
|
|
name: '尺码',
|
|
|
isSelect: false,
|
|
|
});
|
|
|
let sizeList = filter['size'];
|
|
|
let newSizeList = [];
|
|
|
newSizeList.push({
|
|
|
key: '',
|
|
|
name: '所有尺码',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
sizeList.map((item, i) => {
|
|
|
newSizeList.push({
|
|
|
key: item.size_id,
|
|
|
name: item.size_name,
|
|
|
isSelect: false,
|
|
|
});
|
|
|
});
|
|
|
filterCategoryDetailFilterList.sizeKey;
|
|
|
filterCategoryDetailFilterList.sizeKey = newSizeList;
|
|
|
}
|
|
|
|
|
|
if (filter['priceRange']) {
|
|
|
categoryFilterList.push({
|
|
|
key: 'price',
|
|
|
name: '价格',
|
|
|
isSelect: false,
|
|
|
});
|
|
|
let priceObject = filter['priceRange'];
|
|
|
priceObject = sortListByField(priceObject, 'name'); // 折扣,价格区间,需要排序
|
|
|
let newPriceList = [];
|
|
|
newPriceList.push({
|
|
|
key: '',
|
|
|
name: '所有价格',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
_.forEach(priceObject, (v, k) => {
|
|
|
newPriceList.push({
|
|
|
key: v._key,
|
|
|
name: v._value,
|
|
|
isSelect: false,
|
|
|
});
|
|
|
});
|
|
|
filterCategoryDetailFilterList.price;
|
|
|
filterCategoryDetailFilterList.price = newPriceList;
|
|
|
}
|
|
|
|
|
|
if (filter['discount']) {
|
|
|
categoryFilterList.push({
|
|
|
key: 'p_d',
|
|
|
name: '折扣',
|
|
|
isSelect: false,
|
|
|
});
|
|
|
let p_dObject = filter['discount'];
|
|
|
p_dObject = sortListByField(p_dObject, 'name'); // 折扣,价格区间,需要排序
|
|
|
let newP_dList = [];
|
|
|
newP_dList.push({
|
|
|
key: '',
|
|
|
name: '所有折扣',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
_.forEach(p_dObject, (v, k) => {
|
|
|
newP_dList.push({
|
|
|
key: v._key,
|
|
|
name: v.name,
|
|
|
isSelect: false,
|
|
|
});
|
|
|
});
|
|
|
filterCategoryDetailFilterList.p_d;
|
|
|
filterCategoryDetailFilterList.p_d = newP_dList;
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
list,
|
|
|
categoryFilterList,
|
|
|
filterCategoryDetailFilterList,
|
|
|
currentPage,
|
|
|
pageCount,
|
|
|
total,
|
|
|
};
|
|
|
|
|
|
} |
...
|
...
|
|