Authored by Kennaki

Finish red shop filter data. reviewed by Boss Kai.

“”
... ... @@ -64,4 +64,7 @@ export default keyMirror({
SET_SIMILAR_PRODUCT_INDEX: null,
SET_SHOW_SIMILAR_GUIDER: null,
UPDATE_LAST_SELECTED_POPULAR: null,
FILTER_DATA_SUCCESS: null,
});
... ...
... ... @@ -71,6 +71,7 @@ const {
SET_SHOW_SIMILAR_GUIDER,
UPDATE_LAST_SELECTED_POPULAR,
FILTER_DATA_SUCCESS,
} = require('../../constants/actionTypes').default;
... ... @@ -201,12 +202,225 @@ export function shopInfoFailure(error) {
}
}
export function setFilterView(show) {
export function setFilterData(payload) {
return {
type: FILTER_LIST_VIEW,
payload: show
type: FILTER_DATA_SUCCESS,
payload,
}
}
export function setFilterView(show) {
return (dispatch, getState) => {
let {app, brandStore} = getState();
let {filterDataReady, shopId} = brandStore;
if (!filterDataReady && show) {
let channel = app.channel;
return new BrandStoreService(app.host).productFilter(shopId, channel)
.then(json => {
let payload = parseFilterData(json);
dispatch(setFilterData(payload));
dispatch({
type: FILTER_LIST_VIEW,
payload: show
});
})
.catch(error => {
});
} else {
dispatch({
type: FILTER_LIST_VIEW,
payload: show
});
}
};
}
function parseFilterData(json) {
let filter = json && json.filter ? json.filter : {};
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 {
categoryFilterList,
filterCategoryDetailFilterList,
};
}
export function setFilterMoreView(show) {
return {
type: FILTER_MORE_VIEW,
... ...
... ... @@ -6,6 +6,9 @@ let InitialState = Record({
shopId: 0,
keyWord: '',
storeFilter: 0,
filterDataReady: false,//只加载一次
categoryFilterList: List(),
filterCategoryDetailFilterList: List(),
receiveCouponResult: new (Record({
... ...
... ... @@ -60,6 +60,7 @@ const {
SET_SIMILAR_PRODUCT_INDEX,
SET_SHOW_SIMILAR_GUIDER,
UPDATE_LAST_SELECTED_POPULAR,
FILTER_DATA_SUCCESS,
} = require('../../constants/actionTypes').default;
... ... @@ -258,7 +259,17 @@ export default function brandStoreReducer(state=initialState, action) {
return newState;
}
case FILTER_DATA_SUCCESS:{
let {
categoryFilterList,
filterCategoryDetailFilterList,
} = action.payload;
let newState = state.set('categoryFilterList', Immutable.fromJS(categoryFilterList))
.set('filterCategoryDetailFilterList', Immutable.fromJS(filterCategoryDetailFilterList))
.set('filterDataReady',true);
return newState;
}
case PRODUCT_LIST_FAILURE: {
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload);
... ...
... ... @@ -78,6 +78,23 @@ export default class BrandStoreService {
});
}
async productFilter(shop_id, yh_channel=1) {
return await this.api.get({
url: '',
body: {
method: 'app.search.shop.filterOld',
shop_id,
yh_channel,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async productList(shop_id, yh_channel=1, order='s_t_asc', page=1, limit=60, filterFactors={},brand='', v=7) {
return await this.api.get({
url: '',
... ...
... ... @@ -65,4 +65,6 @@ export default keyMirror({
GET_LIVE_COUNT_SUCCESS: null,
GET_LIVE_COUNT_FAILURE: null,
UPDATE_MORE_FILTER_SELECTED_ORDER: null,
FILTER_DATA_SUCCESS: null,
});
... ...
... ... @@ -65,6 +65,7 @@ const {
GET_LIVE_COUNT_FAILURE,
UPDATE_MORE_FILTER_SELECTED_ORDER,
FILTER_DATA_SUCCESS,
} = require('../../constants/actionTypes').default;
... ... @@ -130,35 +131,225 @@ export function setProductListFilter(value) {
}
}
export function setFilterData(payload) {
return {
type: FILTER_DATA_SUCCESS,
payload,
}
}
export function setFilterView(show) {
return (dispatch, getState) => {
// console.log('bbbbbb');
// let {app, redBrand} = getState();
// let {filterDataReady, shopId} = redBrand;
// console.log(redBrand.toJS());
// console.log(show);
// console.log(filterDataReady);
// if (!filterDataReady && show) {
// let channel = app.channel;
// return new RedBrandService(app.host).productFilter(shopId, channel)
// .then(json => {
// console.log('ccccc');
// console.log(json);
// })
// .catch(error => {
// console.log('eeeee');
// console.log(error);
// });
// } else {
// console.log('ggggggggß');
let {app, redBrand} = getState();
let {filterDataReady, shopId} = redBrand;
if (!filterDataReady && show) {
let channel = app.channel;
return new RedBrandService(app.host).productFilter(shopId, channel)
.then(json => {
let payload = parseFilterData(json);
dispatch(setFilterData(payload));
dispatch({
type: FILTER_LIST_VIEW,
payload: show
});
})
.catch(error => {
});
} else {
dispatch({
type: FILTER_LIST_VIEW,
payload: show
});
// }
}
};
}
function parseFilterData(json) {
let filter = json && json.filter ? json.filter : {};
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 {
categoryFilterList,
filterCategoryDetailFilterList,
};
}
export function setFilterMoreView(show) {
return {
type: FILTER_MORE_VIEW,
... ...
... ... @@ -8,7 +8,7 @@ let InitialState = Record({
launchProfile: false,//header 详情展开收起开关
fliter: 0,//红人首页。全部商品切换开关
filterDataReady: false,
filterDataReady: false,//只加载一次
categoryFilterList: List(),
filterCategoryDetailFilterList: List(),
similarIndex : -1,
... ...
... ... @@ -64,6 +64,7 @@ const {
GET_LIVE_COUNT_FAILURE,
UPDATE_MORE_FILTER_SELECTED_ORDER,
FILTER_DATA_SUCCESS,
} = require('../../constants/actionTypes').default;
... ... @@ -131,6 +132,17 @@ export default function redBrandReducer(state=initialState, action) {
return newState;
}
case FILTER_DATA_SUCCESS:{
let {
categoryFilterList,
filterCategoryDetailFilterList,
} = action.payload;
let newState = state.set('categoryFilterList', Immutable.fromJS(categoryFilterList))
.set('filterCategoryDetailFilterList', Immutable.fromJS(filterCategoryDetailFilterList))
.set('filterDataReady',true);
return newState;
}
case PRODUCT_LIST_FOR_NEW_REQUEST: {
return state.setIn(['productListForNew', 'isFetching'], true)
.setIn(['productListForNew', 'error'], null);
... ...
... ... @@ -64,7 +64,6 @@ export default class RedBrandService {
}
async productFilter(shop_id, yh_channel=1) {
console.log('ffffffff');
return await this.api.get({
url: '',
body: {
... ... @@ -74,8 +73,6 @@ export default class RedBrandService {
}
})
.then((json) => {
console.log('aaaa');
console.log(json);
return json;
})
.catch((error) => {
... ...