...
|
...
|
@@ -6,58 +6,52 @@ import ListService from '../../services/ListService'; |
|
|
import helper from '../../../common/utils/helper';
|
|
|
|
|
|
const {
|
|
|
GET_PRODUCT_LIST_REQUEST,
|
|
|
GET_PRODUCT_LIST_SUCCESS,
|
|
|
GET_PRODUCT_LIST_FAILURE,
|
|
|
FETCH_BANNER_REQUEST,
|
|
|
FETCH_BANNER_SUCCESS,
|
|
|
FETCH_BANNER_FAILURE,
|
|
|
GET_ORDER_LIST_REQUEST,
|
|
|
GET_ORDER_LIST_SUCCESS,
|
|
|
GET_ORDER_LIST_FAILURE,
|
|
|
|
|
|
SET_FIRST_SHOW_INDEX,
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function getProductList() {
|
|
|
export function setFirstShowIndex(firstShowIndex) {
|
|
|
return {
|
|
|
type: SET_FIRST_SHOW_INDEX,
|
|
|
payload: firstShowIndex,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function getOrderListByType(type) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, list} = getState();
|
|
|
let {products} = list;
|
|
|
|
|
|
if (products.isFetching || products.endReached || products.error) {
|
|
|
let currentList = list.get(type);
|
|
|
let typeMap = list.get('typeMap');
|
|
|
let currentType = typeMap.get(type);
|
|
|
let page = currentList.currentPage + 1;
|
|
|
let pageSize = currentList.pageSize;
|
|
|
|
|
|
if (currentList.isFetching || currentList.endReached || currentList.error) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let fetchList = (channel, gender, uid, page, pageSize) => {
|
|
|
dispatch(getProductListRequest());
|
|
|
return new ListService(app.serviceHost).getProductListData(channel, gender, uid, page, pageSize)
|
|
|
.then(json => {
|
|
|
let payload = parseProductList(json);
|
|
|
payload.endReached = payload.currentPage == payload.pageCount;
|
|
|
|
|
|
if (payload.currentPage > 1) {
|
|
|
let oldList = products.list.toJS();
|
|
|
let list = [...oldList, ...payload.list];
|
|
|
payload.list = list;
|
|
|
}
|
|
|
dispatch(getProductListSuccess(payload));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(getProductListFailure(error));
|
|
|
});
|
|
|
};
|
|
|
|
|
|
let channel = app.channel;
|
|
|
let gender = '';
|
|
|
let uid = 0;
|
|
|
let page = products.currentPage + 1;
|
|
|
let pageSize = products.pageSize;
|
|
|
|
|
|
Promise.all([
|
|
|
ReactNative.NativeModules.YH_CommonHelper.currentGender(),
|
|
|
ReactNative.NativeModules.RNNativeConfig.uid(),
|
|
|
]).then(result => {
|
|
|
gender = result[0];
|
|
|
uid = result[1];
|
|
|
fetchList(channel, gender, uid, page, pageSize);
|
|
|
}).catch(error => {
|
|
|
|
|
|
});
|
|
|
dispatch(getProductListRequest());
|
|
|
return new ListService(app.host).getOrderListByType(currentType, page, pageSize)
|
|
|
.then(json => {
|
|
|
console.log(json);
|
|
|
let payload = parseProductList(json);
|
|
|
payload.endReached = payload.currentPage == payload.pageCount;
|
|
|
|
|
|
if (payload.currentPage > 1) {
|
|
|
let oldList = products.list.toJS();
|
|
|
let list = [...oldList, ...payload.list];
|
|
|
payload.list = list;
|
|
|
}
|
|
|
dispatch(getProductListSuccess(payload));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(getProductListFailure(error));
|
|
|
});
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
...
|
...
|
@@ -77,59 +71,20 @@ function parseProductList(json) { |
|
|
|
|
|
export function getProductListRequest() {
|
|
|
return {
|
|
|
type: GET_PRODUCT_LIST_REQUEST,
|
|
|
type: GET_ORDER_LIST_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function getProductListSuccess(json) {
|
|
|
return {
|
|
|
type: GET_PRODUCT_LIST_SUCCESS,
|
|
|
type: GET_ORDER_LIST_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function getProductListFailure(error) {
|
|
|
return {
|
|
|
type: GET_PRODUCT_LIST_FAILURE,
|
|
|
type: GET_ORDER_LIST_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
} |
|
|
|
|
|
export function fetchBanner() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, list} = getState();
|
|
|
let {banner} = list;
|
|
|
|
|
|
if (banner.isFetching || banner.error) {
|
|
|
return;
|
|
|
}
|
|
|
dispatch(fetchBannerRequest());
|
|
|
return new ListService(app.serviceHost).fetchBannerData()
|
|
|
.then(json => {
|
|
|
dispatch(fetchBannerSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(fetchBannerFailure(error));
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function fetchBannerRequest() {
|
|
|
return {
|
|
|
type: FETCH_BANNER_REQUEST
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchBannerSuccess(json) {
|
|
|
return {
|
|
|
type: FETCH_BANNER_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchBannerFailure(error) {
|
|
|
return {
|
|
|
type: FETCH_BANNER_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
} |
...
|
...
|
|