|
|
'use strict';
|
|
|
|
|
|
import ReactNative from 'react-native';
|
|
|
import CategoryProListService from '../../services/CategoryProListService';
|
|
|
import * as _ from 'lodash';
|
|
|
import Utils from '../../utils/Utils'
|
|
|
|
|
|
const {
|
|
|
PRODUCT_LIST_REQUEST,
|
|
|
PRODUCT_LIST_SUCCESS,
|
|
|
PRODUCT_LIST_FAILURE,
|
|
|
PRODUCT_FILTER_ACTION,
|
|
|
RESET_LIST_PAGE_INFO,
|
|
|
SET_PRODUCT_LIST_FILTER,
|
|
|
SET_SIMILAR_PRODUCT_INDEX,
|
|
|
SELECT_STANDARDFILTER_ITEM
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
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
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function getProductList(reload=false) {
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
|
let {app, categoryProList} = getState();
|
|
|
let {productList, filterFactors, standardFilterList} = categoryProList;
|
|
|
let {originParams} = app;
|
|
|
|
|
|
if (reload) {
|
|
|
|
|
|
} else {
|
|
|
if (productList.isFetching || productList.endReached || productList.error) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
let page = productList.currentPage + 1;
|
|
|
let pageSize = productList.pageSize;
|
|
|
let order = productList.order;
|
|
|
|
|
|
let bSelectedFilterFactor,allFilterFactors;
|
|
|
allFilterFactors = filterFactors.toJS();
|
|
|
|
|
|
for (let prop in allFilterFactors) {
|
|
|
if (allFilterFactors.hasOwnProperty(prop)) {
|
|
|
if (allFilterFactors[prop] === '' || !allFilterFactors[prop]) {
|
|
|
delete allFilterFactors[prop];
|
|
|
}
|
|
|
if (prop == 'sizeKey' && allFilterFactors[prop]) {
|
|
|
allFilterFactors['size'] = allFilterFactors[prop];
|
|
|
delete allFilterFactors[prop];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
let standard = '';
|
|
|
let standardList = standardFilterList.toJS();
|
|
|
|
|
|
for (var i = 0; i < standardList.length; i++) {
|
|
|
let filterItem = standardList[i]
|
|
|
if (filterItem.isSelect) {
|
|
|
let selectFilter = filterItem.selectFilter;
|
|
|
if (standard.length == 0) {
|
|
|
standard = filterItem.standard_id + '_' + selectFilter.standard_id;
|
|
|
} else {
|
|
|
standard = standard + ',' + filterItem.standard_id + '_' + selectFilter.standard_id;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
allFilterFactors['standard'] = standard;
|
|
|
|
|
|
console.log(allFilterFactors);
|
|
|
|
|
|
dispatch(productListRequest());
|
|
|
return new CategoryProListService(app.host).productList(page, pageSize, originParams, allFilterFactors, order, '')
|
|
|
.then(json => {
|
|
|
let payload = Utils.parseProductList(json);
|
|
|
payload.endReached = payload.currentPage == payload.pageCount;
|
|
|
|
|
|
if (payload.currentPage > 1) {
|
|
|
let oldList = productList.list.toJS();
|
|
|
let list = [...oldList, ...payload.list];
|
|
|
payload.list = list;
|
|
|
}
|
|
|
|
|
|
let categoryFilterList = payload.categoryFilterList;
|
|
|
let filterCategoryDetailFilterList = payload.filterCategoryDetailFilterList;
|
|
|
let filters = Utils.parsecategoryFilter({categoryFilterList,filterCategoryDetailFilterList});
|
|
|
ReactNative.NativeModules.YH_ProductListRNViewHelper.setFilterData(filters);
|
|
|
ReactNative.NativeModules.YH_ScreenCategoryViewHelper.enableBrandFilter();
|
|
|
dispatch(productListSuccess(payload));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(productListFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
export function resetListPageInfo() {
|
|
|
return {
|
|
|
type: RESET_LIST_PAGE_INFO,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function setProductListFilter(value) {
|
|
|
return {
|
|
|
type: SET_PRODUCT_LIST_FILTER,
|
|
|
payload: value
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function setSimilarIndex(rowID) {
|
|
|
return {
|
|
|
type: SET_SIMILAR_PRODUCT_INDEX,
|
|
|
payload: rowID
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function setProductFilterFactors(array) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, categoryProList} = getState();
|
|
|
let {filterFactors} = categoryProList;
|
|
|
filterFactors = filterFactors.toJS();
|
|
|
|
|
|
for (var i = 0; i < array.length; i++) {
|
|
|
let item = array[i];
|
|
|
filterFactors[item._key] = item._value;
|
|
|
}
|
|
|
dispatch({
|
|
|
type: PRODUCT_FILTER_ACTION,
|
|
|
payload: filterFactors
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function selectStandardFilter(item) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {categoryProList} = getState();
|
|
|
let {standardFilterList} = categoryProList;
|
|
|
standardFilterList = standardFilterList ? standardFilterList.toJS() : [];
|
|
|
for (var i = 0; i < standardFilterList.length; i++) {
|
|
|
let filterItem = standardFilterList[i];
|
|
|
if (filterItem.standard_id == item.standard_id) {
|
|
|
filterItem.isSelect = true;
|
|
|
filterItem.selectFilter = item.selectFilter;
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
dispatch({
|
|
|
type: SELECT_STANDARDFILTER_ITEM,
|
|
|
payload: standardFilterList
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function clearStandardFilter(item) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {categoryProList} = getState();
|
|
|
let {standardFilterList} = categoryProList;
|
|
|
standardFilterList = standardFilterList ? standardFilterList.toJS() : [];
|
|
|
for (var i = 0; i < standardFilterList.length; i++) {
|
|
|
let filterItem = standardFilterList[i];
|
|
|
if (filterItem.standard_id == item.standard_id) {
|
|
|
filterItem.isSelect = false;
|
|
|
filterItem.selectFilter = {
|
|
|
standard_id: '',
|
|
|
standard_name: '',
|
|
|
};
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
dispatch({
|
|
|
type: SELECT_STANDARDFILTER_ITEM,
|
|
|
payload: standardFilterList
|
|
|
})
|
|
|
}
|
|
|
} |
...
|
...
|
|