Authored by 张丽霞

个人信息页面内部跳转,review by Redding

... ... @@ -8,6 +8,7 @@ import {
View,
Text,
Image,
TouchableOpacity,
} from 'react-native';
import {Map} from 'immutable';
... ... @@ -29,12 +30,27 @@ export default class PersonalInfo extends Component {
if (dataSource.get('id') == 'portrait' && dataSource.get('url') == '') {
imageUrl = require('../image/avatar_icon.png');
} else if (dataSource.get('id') == 'VIPLevel') {
imageUrl = require('../image/VIP1.png');
switch (dataSource.get('content')) {
case '1':
imageUrl = require('../image/VIP1.png');
break;
case '2':
imageUrl = require('../image/VIP2.png');
break;
case '3':
imageUrl = require('../image/VIP3.png');
break;
default:
imageUrl = '';
}
} else if (dataSource.get('id') == 'mineQRCode') {
imageUrl = require('../image/mine_qr.png');
}
let url = YH_Image.getSlicedUrl(dataSource.get('url'), 40, 40, 2); // 商品缩略图
return (
<TouchableOpacity activeOpacity={1.0} onPress={() => {
this.props.onPressInfoCell && this.props.onPressInfoCell(dataSource);
}}>
<View style={[styles.container,{height: cellHeight + (withoutBottomLine?0.0:0.5)}]}>
<View style={[styles.contentContainer,{height: cellHeight}]}>
... ... @@ -42,10 +58,12 @@ export default class PersonalInfo extends Component {
{dataSource.get('title')}
</Text>
<View style={styles.contentContainer}>
<Text style={styles.content}>
{dataSource.get('content')}
</Text>
{dataSource.get('id') == 'VIPLevel'?
null
:<Text style={styles.content}>
{dataSource.get('content')}
</Text>
}
{dataSource.get('id') == 'portrait' && dataSource.get('url') != '' ?
<YH_Image url={url} style={styles.userImage} />
:null
... ... @@ -63,6 +81,7 @@ export default class PersonalInfo extends Component {
<View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5',}}/>
}
</View>
</TouchableOpacity>
);
}
}
... ...
... ... @@ -34,13 +34,13 @@ export default class PersonalInfo extends Component {
return(
<InfoCell
dataSource={rowData}
onPressInfoCell={this.props.onPressInfoCell}
/>
);
}
render() {
let {dataSource} = this.props;
let dataList = [0,1,2];
return (
<View style={styles.container}>
<ListView
... ...
... ... @@ -46,13 +46,21 @@ function mapDispatchToProps(dispatch) {
class PersonalInfoContainer extends Component {
constructor(props) {
super(props);
this._onPressInfoCell = this._onPressInfoCell.bind(this);
}
_onPressInfoCell(cellInfo) {
this.props.actions.onPressInfoCell(cellInfo);
}
componentDidMount() {
this.props.actions.fetchPersonalInfo();
}
componentWillUnmount() {
this.props.actions.modifyUserBaseInfo();
}
render() {
let {personalInfo} = this.props;
let {pageCellList} = personalInfo;
... ... @@ -60,6 +68,7 @@ class PersonalInfoContainer extends Component {
<View style={styles.container}>
<PersonalInfo
dataSource={pageCellList}
onPressInfoCell={this._onPressInfoCell}
/>
</View>
);
... ...
... ... @@ -84,7 +84,7 @@ function processProfile(profile){
case 'portrait':
cellItem.url = profile.head_ico;
break;
case 'nickname':
case 'nick_name':
cellItem.content = profile.nickname;
break;
case 'gender':{
... ... @@ -95,7 +95,7 @@ function processProfile(profile){
}
}
break;
case 'birthDay':
case 'birthday':
cellItem.content = profile.birthday;
break;
case 'VIPLevel':{
... ... @@ -117,3 +117,143 @@ function processProfile(profile){
dispatch(updatePageCellList(pageCellList));
}
}
export function modifyUserBaseInfo(cellList) {
return (dispatch, getState) => {
let {app, personalInfo} = getState();
let {pageCellList} = personalInfo;
if (!cellList) {
cellList = pageCellList.toJS();
}
let params = {};
cellList.map((cellItem, i) => {
if (cellItem.id == 'gender') {
let gender = 0;
if (cellItem.content == 'BOY') {
gender = 1;
} else if (cellItem.content == 'GIRL') {
gender = 2;
}
params.gender = gender;
}else {
if (cellItem.baseUpload) {
params[cellItem.id] = cellItem.content;
}
}
})
return new PersonalInfoService(app.host).modifyUserBaseInfo(params)
.then(json => {
console.log('-----更新信息');
console.log(json);
})
.catch(error => {
console.log('-----更新信息');
console.log(error);
})
}
}
export function onPressInfoCell(cellInfo) {
return (dispatch, getState) => {
let {app, personalInfo} = getState();
let {pageCellList} = personalInfo;
pageCellList = pageCellList.toJS();
switch (cellInfo.get('id')) {
case 'portrait':{
ReactNative.NativeModules.YH_PersonalInfoHelper.selectAvatarAction()
.then(data => {
if (data && data != '') {
pageCellList[0].url = data;
}
dispatch(updatePageCellList(pageCellList));
})
.catch(error => {
console.log('-----imageUrl error');
console.log(error);
});
}
break;
case 'nick_name': {
ReactNative.NativeModules.YH_PersonalInfoHelper.gotoEditNickName(cellInfo.get('content'))
.then(data => {
pageCellList[cellInfo.get('index')].content = data;
dispatch(updatePageCellList(pageCellList));
dispatch(modifyUserBaseInfo(pageCellList));
})
.catch(error => {
console.log('-----nickname error');
console.log(error);
});
}
break;
case 'gender':{
ReactNative.NativeModules.YH_PersonalInfoHelper.selectGenderAction()
.then(data => {
console.log('-----gender');
console.log(data);
pageCellList[cellInfo.get('index')].content = data;
dispatch(updatePageCellList(pageCellList));
})
.catch(error => {
console.log('-----nickname error');
console.log(error);
});
}
break;
case 'birthday':{
ReactNative.NativeModules.YH_PersonalInfoHelper.selectBirthdayAction()
.then(data => {
console.log('-----gender');
console.log(data);
pageCellList[cellInfo.get('index')].content = data;
dispatch(updatePageCellList(pageCellList));
})
.catch(error => {
console.log('-----nickname error');
console.log(error);
});
}
break;
case 'VIPLevel':{
ReactNative.NativeModules.YH_PersonalInfoHelper.gotoVIPLevelVC();
}
break;
case 'mineQRCode':{
ReactNative.NativeModules.YH_PersonalInfoHelper.gotoMineQRCode();
}
break;
case 'height':
case 'weight':{
ReactNative.NativeModules.YH_PersonalInfoHelper.selectHeightWeightAction()
.then(data => {
console.log('-----height & weight');
console.log(data);
if (cellInfo.get('id') == 'height') {
pageCellList[cellInfo.get('index')].content = data.height;
pageCellList[cellInfo.get('index') + 1].content = data.weight;
} else if (cellInfo.get('id') == 'weight') {
pageCellList[cellInfo.get('index')].content = data.weight;
pageCellList[cellInfo.get('index') - 1].content = data.height;
}
dispatch(updatePageCellList(pageCellList));
})
.catch(error => {
console.log('-----nickname error');
console.log(error);
});
}
break;
case 'addressManage':{
ReactNative.NativeModules.YH_PersonalInfoHelper.gotoManagerAddressVC();
}
break;
case 'accountBind':{
ReactNative.NativeModules.YH_PersonalInfoHelper.gotoAccountBindVC();
}
break;
default:
}
}
}
... ...
... ... @@ -6,50 +6,66 @@ let personalInfoCelllist = [
id: 'portrait',
title: '头像',
url: '',
index: 0,
},{
id: 'nickname',
id: 'nick_name',
title: '昵称',
content: '',
index: 1,
baseUpload: true,
},{
id: 'gender',
title: '性别',
content: '',
content: '选择性别',
index: 2,
baseUpload: true,
},{
id: 'birthDay',
id: 'birthday',
title: '生日',
content: '',
index: 3,
baseUpload: true,
},{
id: 'VIPLevel',
title: '会员等级',
content: '',
index: 4,
},{
id: 'mineQRCode',
title: '我的二维码',
content: '',
withoutBottomLine: true,
index: 5,
},{
id: 'separate',
index: 6,
},{
id: 'height',
title: '身高',
content: '',
index: 7,
baseUpload: true,
},{
id: 'weight',
title: '体重',
content: '',
withoutBottomLine: true,
index: 8,
baseUpload: true,
},{
id: 'separate',
index: 9,
},{
id: 'addressManage',
title: '地址管理',
content: '',
index: 10,
},{
id: 'accountBind',
title: '账号绑定',
content: '',
withoutBottomLine: true,
index: 11,
}
]
... ... @@ -58,7 +74,7 @@ let InitialState = Record({
userProfile: new (Record({
isFetching: false,
profile: Map(),
}))
})),
});
export default InitialState;
... ...
... ... @@ -27,4 +27,20 @@ export default class MineGuangService {
throw(error);
});
}
async modifyUserBaseInfo(params) {
return await this.api.get({
url: '',
body: {
method: 'app.passport.modifyBase',
...params,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...