...
|
...
|
@@ -5,6 +5,394 @@ import HomeService from '../../services/HomeService'; |
|
|
import store from 'react-native-simple-store';
|
|
|
|
|
|
const {
|
|
|
SET_CHANNEL,
|
|
|
HOME_BOY_FLOOR_REQUEST,
|
|
|
HOME_BOY_FLOOR_SUCCESS,
|
|
|
HOME_BOY_FLOOR_FAILURE,
|
|
|
|
|
|
HOME_GIRL_FLOOR_REQUEST,
|
|
|
HOME_GIRL_FLOOR_SUCCESS,
|
|
|
HOME_GIRL_FLOOR_FAILURE,
|
|
|
|
|
|
HOME_KIDS_FLOOR_REQUEST,
|
|
|
HOME_KIDS_FLOOR_SUCCESS,
|
|
|
HOME_KIDS_FLOOR_FAILURE,
|
|
|
|
|
|
HOME_LIFESTYLE_FLOOR_REQUEST,
|
|
|
HOME_LIFESTYLE_FLOOR_SUCCESS,
|
|
|
HOME_LIFESTYLE_FLOOR_FAILURE,
|
|
|
|
|
|
HOME_BOY_FAVORITE_REQUEST,
|
|
|
HOME_BOY_FAVORITE_SUCCESS,
|
|
|
HOME_BOY_FAVORITE_FAILURE,
|
|
|
|
|
|
HOME_GIRL_FAVORITE_REQUEST,
|
|
|
HOME_GIRL_FAVORITE_SUCCESS,
|
|
|
HOME_GIRL_FAVORITE_FAILURE,
|
|
|
|
|
|
HOME_KIDS_FAVORITE_REQUEST,
|
|
|
HOME_KIDS_FAVORITE_SUCCESS,
|
|
|
HOME_KIDS_FAVORITE_FAILURE,
|
|
|
|
|
|
HOME_LIFESTYLE_FAVORITE_REQUEST,
|
|
|
HOME_LIFESTYLE_FAVORITE_SUCCESS,
|
|
|
HOME_LIFESTYLE_FAVORITE_FAILURE,
|
|
|
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function fetchFloor() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, home} = getState();
|
|
|
let channel = app.channel;
|
|
|
|
|
|
if ((channel == 1 && home.boy.isFetching)||
|
|
|
(channel == 2 && home.girl.isFetching)||
|
|
|
(channel == 3 && home.kid.isFetching)||
|
|
|
(channel == 4 && home.lifeStyle.isFetching)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (channel == 1) {
|
|
|
dispatch(fetchBoyFloor());
|
|
|
}else if (channel == 2) {
|
|
|
dispatch(fetchGirlFloor());
|
|
|
}else if (channel == 3) {
|
|
|
dispatch(fetchKidsFloor());
|
|
|
}else if (channel == 4) {
|
|
|
dispatch(fetchLifeStyleFloor());
|
|
|
}
|
|
|
|
|
|
let fetchFloorRequest = (sourcePage, contentCode, gender, new_device) => {
|
|
|
return new HomeService(app.serviceHost).fetchHomeFloorRequest(contentCode, channel, gender, sourcePage, new_device)
|
|
|
.then(json => {
|
|
|
let payload = parseHomeFloor(json)
|
|
|
console.log(payload);
|
|
|
if (channel == 1) {
|
|
|
dispatch(fetchBoyFloorSuccess(payload));
|
|
|
}else if (channel == 2) {
|
|
|
dispatch(fetchGirlFloorSuccess(payload));
|
|
|
}else if (channel == 3) {
|
|
|
dispatch(fetchKidsFloorSuccess(payload));
|
|
|
}else if (channel == 4) {
|
|
|
dispatch(fetchLifeStyleFloorSuccess(payload));
|
|
|
}
|
|
|
|
|
|
// 请求商品列表
|
|
|
dispatch(fetchHomeFavoriteList(channel, gender, contentCode, sourcePage));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
if (channel == 1) {
|
|
|
dispatch(fetchBoyFloorFailure(error));
|
|
|
}else if (channel == 2) {
|
|
|
dispatch(fetchGirlFloorFailure(error));
|
|
|
}else if (channel == 3) {
|
|
|
dispatch(fetchKidsFloorFailure(error));
|
|
|
}else if (channel == 4) {
|
|
|
dispatch(fetchLifeStyleFloorFailure(error));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let sourcePage = '';
|
|
|
let contentCode = '';
|
|
|
let gender = '';
|
|
|
let new_device = '';
|
|
|
|
|
|
Promise.all([
|
|
|
ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_HomeViewController'),
|
|
|
ReactNative.NativeModules.YH_CommonHelper.isNewDevice(),
|
|
|
ReactNative.NativeModules.YH_CommonHelper.currentHomeContentCode(),
|
|
|
ReactNative.NativeModules.YH_CommonHelper.currentGender(),
|
|
|
]).then(result => {
|
|
|
sourcePage = result[0];
|
|
|
new_device = result[1];
|
|
|
contentCode = result[2];
|
|
|
gender = result[3];
|
|
|
fetchFloorRequest(sourcePage, contentCode, gender, new_device);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
fetchFloorRequest(sourcePage, contentCode, gender, new_device);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function fetchHomeFavoriteList(channel, gender, contentCode, fromPage) {
|
|
|
return (dispatch, getState) => {
|
|
|
if (channel == 1 || channel == 2) {
|
|
|
dispatch(fetchBoyGirlFavoriteList(contentCode, gender, fromPage));
|
|
|
}else if (channel == 3) {
|
|
|
dispatch(fetchKidsFavoriteList(fromPage));
|
|
|
}else if (channel == 4) {
|
|
|
dispatch(fetchLifeStyleFavoriteList(fromPage));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function fetchBoyGirlFavoriteList(contentCode, gender, page, fromPage) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, home} = getState();
|
|
|
let channel = app.channel;
|
|
|
let data = home.boy;
|
|
|
|
|
|
if (channel == 1) {
|
|
|
dispatch(fetchBoyFavorite());
|
|
|
}else if (channel == 2) {
|
|
|
data = home.girl;
|
|
|
dispatch(fetchGirlFavorite());
|
|
|
}
|
|
|
|
|
|
let page = data.favorite.get('currentPage') + 1;
|
|
|
|
|
|
return new HomeService(app.host).fetchHomeFavoriteData(channel, contentCode, gender, fromPage, page)
|
|
|
.then(json =>{
|
|
|
let payload = parseHomeFavorite(json);
|
|
|
//商品列表最多分四页
|
|
|
payload.endReached = (payload.currentPage > 4) || (payload.currentPage == payload.pageCount);
|
|
|
|
|
|
if (channel == 1) {
|
|
|
dispatch(fetchBoyFavoriteSuccess(payload));
|
|
|
}else if (channel == 2) {
|
|
|
dispatch(fetchGirlFavoriteSuccess(payload));
|
|
|
}
|
|
|
})
|
|
|
.catch(error =>{
|
|
|
if (channel == 1) {
|
|
|
dispatch(fetchBoyFavoriteFailure(error));
|
|
|
}else if (channel == 2) {
|
|
|
dispatch(fetchGirlFavoriteFailure(error));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function fetchKidsFavoriteList(page, fromPage) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, home} = getState();
|
|
|
let data = home.kid;
|
|
|
let page = data.favorite.get('currentPage') + 1;
|
|
|
|
|
|
dispatch(fetchKidsFavorite());
|
|
|
return new HomeService(app.host).fetchHomeKidFavoriteData(fromPage, page)
|
|
|
.then(json =>{
|
|
|
dispatch(fetchKidsFavoriteSuccess(json));
|
|
|
})
|
|
|
.catch(error =>{
|
|
|
dispatch(fetchKidsFavoriteFailure(error));
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function fetchLifeStyleFavoriteList(fromPage) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, home} = getState();
|
|
|
let data = home.lifeStyle;
|
|
|
let page = data.get('currentPage') + 1;
|
|
|
|
|
|
dispatch(fetchLifeStyleFavorite());
|
|
|
return new HomeService(app.host).fetchHomeHotNewData(fromPage, page)
|
|
|
.then(json =>{
|
|
|
dispatch(fetchLifeStyleFavoriteSuccess(json));
|
|
|
})
|
|
|
.catch(error =>{
|
|
|
dispatch(fetchLifeStyleFavoriteFailure(error));
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function parseHomeFloor(json) {
|
|
|
let list = json && json.list ? json.list : [];
|
|
|
let content_code = json && json.content_code ? json.content_code : '';
|
|
|
return {
|
|
|
list,
|
|
|
content_code,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function parseHomeFavorite(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 list = json && json.list ? json.list : [];
|
|
|
|
|
|
return {
|
|
|
currentPage,
|
|
|
pageCount,
|
|
|
total,
|
|
|
list
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/******** 首页楼层 *********/
|
|
|
// 开始请求
|
|
|
export function fetchBoyFloor(channel) {
|
|
|
return {
|
|
|
type: HOME_BOY_FLOOR_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchGirlFloor(channel) {
|
|
|
return {
|
|
|
type: HOME_GIRL_FLOOR_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchKidsFloor(channel) {
|
|
|
return {
|
|
|
type: HOME_KIDS_FLOOR_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchLifeStyleFloor(channel) {
|
|
|
return {
|
|
|
type: HOME_LIFESTYLE_FLOOR_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 请求成功
|
|
|
export function fetchBoyFloorSuccess(json) {
|
|
|
return {
|
|
|
type: HOME_BOY_FLOOR_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchGirlFloorSuccess(json) {
|
|
|
return {
|
|
|
type: HOME_GIRL_FLOOR_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchKidsFloorSuccess(json) {
|
|
|
return {
|
|
|
type: HOME_KIDS_FLOOR_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchLifeStyleFloorSuccess(json) {
|
|
|
return {
|
|
|
type: HOME_LIFESTYLE_FLOOR_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 请求失败
|
|
|
export function fetchBoyFloorFailure(error, channel) {
|
|
|
return {
|
|
|
type: HOME_BOY_FLOOR_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchGirlFloorFailure(error, channel) {
|
|
|
return {
|
|
|
type: HOME_GIRL_FLOOR_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchKidsFloorFailure(error, channel) {
|
|
|
return {
|
|
|
type: HOME_KIDS_FLOOR_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchLifeStyleFloorFailure(error, channel) {
|
|
|
return {
|
|
|
type: HOME_LIFESTYLE_FLOOR_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/******** 首页猜你喜欢商品列表*********/
|
|
|
|
|
|
//开始请求
|
|
|
|
|
|
export function fetchBoyFavorite() {
|
|
|
return {
|
|
|
type: HOME_BOY_FAVORITE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchGirlFavorite() {
|
|
|
return {
|
|
|
type: HOME_GIRL_FAVORITE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchKidsFavorite() {
|
|
|
return {
|
|
|
type: HOME_KIDS_FAVORITE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchLifeStyleFavorite() {
|
|
|
return {
|
|
|
type: HOME_LIFESTYLE_FAVORITE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 请求成功
|
|
|
|
|
|
export function fetchBoyFavoriteSuccess(json) {
|
|
|
return {
|
|
|
type: HOME_BOY_FAVORITE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchGirlFavoriteSuccess(json) {
|
|
|
return {
|
|
|
type: HOME_GIRL_FAVORITE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
export function fetchKidsFavoriteSuccess(json) {
|
|
|
return {
|
|
|
type: HOME_KIDS_FAVORITE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
export function fetchLifeStyleFavoriteSuccess(json) {
|
|
|
return {
|
|
|
type: HOME_LIFESTYLE_FAVORITE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 请求失败
|
|
|
|
|
|
export function fetchBoyFavoriteFailure(error) {
|
|
|
return {
|
|
|
type: HOME_BOY_FAVORITE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchGirlFavoriteFailure(error) {
|
|
|
return {
|
|
|
type: HOME_GIRL_FAVORITE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchKidsFavoriteFailure(error) {
|
|
|
return {
|
|
|
type: HOME_KIDS_FAVORITE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function fetchLifeStyleFavoriteFailure(error) {
|
|
|
return {
|
|
|
type: HOME_LIFESTYLE_FAVORITE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
} |
...
|
...
|
|