...
|
...
|
@@ -8,4 +8,112 @@ import {Record, List, Map} from 'immutable'; |
|
|
const {
|
|
|
SET_TYPE,
|
|
|
|
|
|
FETCH_PROFILE_REQUEST,
|
|
|
FETCH_PROFILE_SUCCESS,
|
|
|
FETCH_PROFILE_FAILURE,
|
|
|
|
|
|
UPDATE_PAGE_CELL_LIST,
|
|
|
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function fetchProfileRequest() {
|
|
|
return{
|
|
|
type: FETCH_PROFILE_REQUEST,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function fetchProfileSuccess(json) {
|
|
|
return{
|
|
|
type: FETCH_PROFILE_SUCCESS,
|
|
|
payload: json,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function fetchProfileFailure(error) {
|
|
|
return{
|
|
|
type: FETCH_PROFILE_FAILURE,
|
|
|
payload: error,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function updatePageCellList(list) {
|
|
|
return{
|
|
|
type: UPDATE_PAGE_CELL_LIST,
|
|
|
payload: list,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function fetchPersonalInfo() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, personalInfo} = getState();
|
|
|
let getProfileFunction = (uid) => {
|
|
|
dispatch(fetchProfileRequest());
|
|
|
return new PersonalInfoService(app.host).getProfile(uid)
|
|
|
.then(json => {
|
|
|
dispatch(fetchProfileSuccess(json));
|
|
|
dispatch(processProfile(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(fetchProfileFailure());
|
|
|
})
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
getProfileFunction(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
getProfileFunction(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function processProfile(profile){
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, personalInfo} = getState();
|
|
|
let {pageCellList} = personalInfo;
|
|
|
pageCellList = pageCellList.toJS();
|
|
|
pageCellList.map((cellItem, i) => {
|
|
|
switch (cellItem.id) {
|
|
|
case 'portrait':
|
|
|
cellItem.url = profile.head_ico;
|
|
|
break;
|
|
|
case 'nickname':
|
|
|
cellItem.content = profile.nickname;
|
|
|
break;
|
|
|
case 'gender':{
|
|
|
if (profile.gender == 1) {
|
|
|
cellItem.content = 'BOY';
|
|
|
} else if (profile.gender == 2) {
|
|
|
cellItem.content = 'GIRL';
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case 'birthDay':
|
|
|
cellItem.content = profile.birthday;
|
|
|
break;
|
|
|
case 'VIPLevel':{
|
|
|
if (profile.vip_info.cur_level != '0') {
|
|
|
cellItem.content = profile.vip_info.cur_level;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case 'height':
|
|
|
cellItem.content = profile.height;
|
|
|
break;
|
|
|
case 'weight':
|
|
|
cellItem.content = profile.weight;
|
|
|
break;
|
|
|
default:
|
|
|
|
|
|
}
|
|
|
})
|
|
|
dispatch(updatePageCellList(pageCellList));
|
|
|
}
|
|
|
} |
...
|
...
|
|