chooseUserInfo.js
6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Created by Cassie on 2018/03/21
*/
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
Animated,
ActivityIndicator,
Platform,
ScrollView,
Button
} from 'react-native';
import moment from 'moment';
import {width,height,zoomW,zoomH} from '../../utils/getSize';
import xnService from "../../service/AppService";
import {clock,xnToast,timeReduce,timePlus,timeEvery,getDay} from '../../utils/utils';
export default class chooseUserInfo extends Component {
static navigationOptions = ({navigation}) => ({
headerTitle:navigation.state.params.title,
headerLeft:(
<TouchableOpacity style={styles.backWrap} onPress={() => navigation.goBack()}>
<Image source={require('../../img/back_gray.png')} resizeMode="contain" />
</TouchableOpacity>
),
headerRight:(
<Button
onPress={navigation.state.params?navigation.state.params.save:()=>console.log('onPress')}
title="保存"
color="#4b85e0"
/>
)
});
constructor(props){
super(props);
this.state = {
loading:false,
select:this.props.navigation.state.params.defultValue,
};
if (this.props.navigation.state.params.type == 'gender'){
if (this.props.navigation.state.params.defultValue == 'M'){
this.state.select = '男'
}else if (this.props.navigation.state.params.defultValue == 'F'){
this.state.select = '女'
}else {
this.state.select = ''
}
}
};
componentWillMount(){
};
componentDidMount(){
this.props.navigation.setParams({
save:this.save,
})
}
save=()=>{
if (this.props.navigation.state.params.type == 'gender'){
let value;
if (this.props.navigation.state.params.defultValue == 'M'){
value = '男'
}else if (this.props.navigation.state.params.defultValue == 'F'){
value = '女'
}else {
value = ''
}
if (this.state.select == value){
xnToast('您并未做出修改');
return;
}
}else {
if (this.state.select == this.props.navigation.state.params.defultValue){
xnToast('您并未做出修改');
return;
}
}
this.setState({
loading:true,
});
let params;
if (this.props.navigation.state.params.type == 'gender'){
params = {
id:global.user.id,
gender:this.state.select =='男'?'M':'F'
};
global.user.nickName = this.state.select =='男'?'M':'F'
}else if (this.props.navigation.state.params.type == 'education'){
params = {
id:global.user.id,
education:this.state.select
};
global.user.education = this.state.select;
}else if (this.props.navigation.state.params.type == 'occupation'){
params = {
id:global.user.id,
occupation:this.state.select
};
global.user.occupation = this.state.select;
}
xnService.undateUserInfo(params).then((data) => {
this.setState({
loading: false
});
if (data.message) {
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
xnToast(data.errors[0].message);
if (this.props.navigation.state.params.type == 'gender'){
global.user.gender = this.props.navigation.state.params.defultValue;
}else if (this.props.navigation.state.params.type == 'education'){
global.user.education = this.props.navigation.state.params.defultValue;
}else if (this.props.navigation.state.params.type == 'occupation'){
global.user.occupation = this.props.navigation.state.params.defultValue;
}
} else {
if (this.props.navigation.state.params.callback){
this.props.navigation.state.params.callback();
this.props.navigation.goBack();
}
}
})
}
renderItem=(v,i)=>{
return (
<TouchableOpacity onPress={()=>this.setState({select:v})}>
<View style={{width:width,height:44/zoomH,justifyContent:'center',alignItems:'center',backgroundColor:'white'}}>
{this.state.select==v&&<Text style={styles.select}>{v}</Text>}
{this.state.select!=v&&<Text style={styles.unSelect}>{v}</Text>}
</View>
<View style={{width:'100%',height:1}}></View>
</TouchableOpacity>
)
}
render(){
return (
<View style={styles.background}>
<ScrollView bounces={false} style={{flex:1}}>
<View style={{width:'100%',height:10/zoomH}}></View>
{this.props.navigation.state.params.itemList.map((v, i) => this.renderItem(v, i))}
</ScrollView>
{this.state.loading && <View style={styles.loadingBg}>
<ActivityIndicator size="large" />
</View>}
</View>
);
}
}
const styles = StyleSheet.create({
backWrap: {
justifyContent: 'center',
paddingLeft: 18.5/zoomW,
paddingRight: 18.5/zoomW,
height: 44/zoomH,
},
background:{
flex:1,
backgroundColor:'#f6f6f6',
display:'flex',
alignItems:'center',
},
itemLine:{
height:44/zoomH,
width:'100%',
backgroundColor:'white',
paddingLeft:15/zoomW,
paddingRight:15/zoomW,
marginTop:12/zoomH
},
select:{
fontSize:15,
color:'#3e6db7'
},
unSelect:{
fontSize:15,
color:'#464646'
}
});