Info.js
11.4 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/**
* Created by tdzl2003 on 12/18/16.
*/
import React, {Component, PropTypes} from "react";
import {
Dimensions,
Image,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
View,
Platform,
StatusBar,
NativeModules,
ActivityIndicator,
DeviceEventEmitter
} from "react-native";
import {zoomW,zoomH} from '../../utils/getSize';
import xnService from "../../service/AppService";
import {xnToast} from "../../utils/utils"
function isIphoneX() {
let dimen = Dimensions.get('window');
return (
Platform.OS === 'ios' &&
!Platform.isPad &&
!Platform.isTVOS &&
(dimen.height === 812 || dimen.width === 812)
);
}
var ImagePicker = require('react-native-image-picker');
var options = {
title: '选择头像',
storageOptions: {
skipBackup: true,
path: 'images',
waitUntilSaved:true
},
cancelButtonTitle:'取消',
takePhotoButtonTitle:'拍照',
chooseFromLibraryButtonTitle:'选择相册',
quality:1,
noData:true,
maxWidth: 200,
maxHeight: 200
};
export default class Info extends Component {
static navigationOptions = ({navigation}) => ({
headerTitle:'个人信息',
headerLeft:(
<TouchableOpacity style={styles.backWrap} onPress={() => navigation.goBack()}>
<Image source={require('../../img/back_gray.png')} resizeMode="contain" />
</TouchableOpacity>
),
headerRight:(
<View></View>
)
});
constructor(){
super()
this.state = {
loading:false,
avatar:global.user.avatar?{uri:global.user.avatar}:global.user.isPartyMember?require('../../img/defultPartyIcon.png'):require('../../img/personAvatar.png'),
nickName:global.user.nickName?global.user.nickName:global.user.mobilePhone,
age:global.user.age?global.user.age:'',
gender:global.user.gender?global.user.gender:'-',
education:global.user.education?global.user.education:'-',
occupation:global.user.occupation?global.user.occupation:'-',
isPartyMember:global.user.isPartyMember!=undefined?global.user.isPartyMember?'是':'否':'-',
partyName:global.user.partyName!=undefined?global.user.partyName:'-',
employeeNumber:global.user.isEmployee?global.user.employeeNumber:'-',
};
}
componentWillUnmount(){
}
componentDidMount(){
}
check(select){
if (select==0){
//更新头像
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('用户取消了选择!');
}
else if (response.error) {
// alert("ImagePicker发生错误:" + response.error);
}
else {
let fileName = response.fileName ? response.fileName : response.uri.substring(response.uri.lastIndexOf('/')+1);
xnService.getAccess({name:fileName}).then((data) => {
if(data.message){
xnToast(data.message);
return;
}
if(data.errors.length > 0) {
xnToast(data.errors[0].message);
}else{
NativeModules.BlueToolManage.simpleUpload(data.accessKeyId,data.accessKeySecret,data.securityToken,data.info.endpoint,data.info.bucket,fileName,response.path || response.uri).then((res) => {
let extension = res.substring(res.lastIndexOf('.')+1).toLowerCase();
let params = {
userId: global.user.id,
avatar: res,
};
this.setState({
loading:true
});
xnService.undateAvatar(params).then((data) => {
this.setState({
loading: false
});
if (data.message) {
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
xnToast(data.errors[0].message);
} else {
global.user.avatar = res;
DeviceEventEmitter.emit('updateAvatar');
this.setState({
avatar:global.user.avatar?{uri:global.user.avatar}:require('../../img/personAvatar.png')
})
}
})
})
}
})
}
});
}else if (select == 1) {
//更新昵称
this.props.navigation.navigate('ChangeUserInfo',{title:'修改昵称',defultValue:this.state.nickName,type:'nickName',callback:()=>{
this.setState({
nickName:global.user.nickName,
})
}});
}else if (select == 2) {
//更新性别
let itemList=['男','女'];
this.props.navigation.navigate('ChooseUserInfo',{title:'修改性别',defultValue:this.state.gender,itemList:itemList,type:'gender',callback:()=>{
this.setState({
gender:global.user.gender,
})
}});
}else if (select == 3) {
//更新年龄
this.props.navigation.navigate('ChangeUserInfo',{title:'修改年龄',defultValue:this.state.age,type:'age',callback:()=>{
this.setState({
age:global.user.age,
})
}});
}else if (select == 4) {
//更新学历
let itemList = ['小学','初中','中专/高中','专科/本科','硕士研究生','博士研究生'];
this.props.navigation.navigate('ChooseUserInfo',{title:'设置学历',defultValue:this.state.education,itemList:itemList,type:'education',callback:()=>{
this.setState({
education:global.user.education,
})
}});
}else if (select == 5) {
//更新职业
let itemList = ['学龄前','学生','公司职员','自由人士','退休人士'];
this.props.navigation.navigate('ChooseUserInfo',{title:'设置职业',defultValue:this.state.occupation,itemList:itemList,type:'occupation',callback:()=>{
this.setState({
occupation:global.user.occupation,
})
}});
}else if (select == 6) {
//更新党支部
if (global.user.isPartyMember == undefined){
let itemList = ['是','否'];
this.props.navigation.navigate('ChooseUserInfo',{title:'党员认证',defultValue:this.state.isPartyMember,itemList:itemList,type:'partyMember',callback:()=>{
this.setState({
isPartyMember:global.user.isPartyMember?'是':'否',
})
}});
}
}else if (select == 7) {
//更新党支部
let itemList = [
'宣传系统',
'市级机关系统',
'金融系统',
'建交系统','教卫系统',
'科技系统','经信系统',
'合作交流系统','社会工作(两新)系统',
'国资系统','市场监管系统',
'浦东区委','徐汇区委',
'长宁区委','普陀区委',
'静安区委','虹口区委',
'杨浦区委','黄浦区委',
'闵行区委','宝山区委',
'嘉定区委','金山区委',
'松江区委','青浦区委',
'奉贤区委','崇明区委'];
this.props.navigation.navigate('ChooseUserInfo',{title:'党支部组织认证',defultValue:this.state.partyName,itemList:itemList,type:'organization',callback:()=>{
this.setState({
partyName:global.user.partyName,
})
}});
}
}
row(v,i){
return (
<TouchableOpacity style={[styles.row,(i===0||i===6)&&{marginTop:10},(i != 5 || i != 8)&&{borderBottomWidth:1}]} key={i}
onPress={()=>{this.check(i)}}>
<Text style={styles.title}>{v.name}</Text>
{v.img&&<Image style={styles.img} defaultSource={global.user.isPartyMember?require('../../img/defultPartyIcon.png'):require('../../img/personAvatar.png')} source={v.img} resizeMode={'cover'}/>}
<Text style={styles.text}>{v.text}</Text>
<Image style={styles.icon} source={require('../../img/arrow_right.png')} resizeMode={'contain'}/>
</TouchableOpacity>
)
}
render(){
return(
<View style={styles.bg}>
<StatusBar barStyle={'default'}/>
<ScrollView >
{this.row({name:'头像',img:this.state.avatar},0)}
{this.row({name:'昵称',text:this.state.nickName},1)}
{this.row({name:'性别',text:this.state.gender=='M'?'男':this.state.gender=='-'?'-':'女'},2)}
{this.row({name:'年龄',text:this.state.age},3)}
{this.row({name:'学历',text:this.state.education},4)}
{this.row({name:'职业',text:this.state.occupation},5)}
{this.row({name:'党员认证',text:this.state.isPartyMember},6)}
{this.row({name:'党支部认证',text:this.state.partyName},7)}
{this.row({name:'员工认证',text:this.state.employeeNumber},8)}
</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,
},
back: {
width: 8.5/zoomW,
height: 15/zoomH,
},
bg:{
flex:1,
backgroundColor:'#f6f6f6',
},
row:{
height:44/zoomH,
flexDirection:'row',
paddingHorizontal:15/zoomW,
alignItems:'center',
borderBottomColor:'#dddddd',
backgroundColor:'white'
},
title:{
fontSize:16,
color:'#4b4b4b',
flex:1
},
text:{
color:'#8c8c8c',
fontSize:14,
marginRight:14/zoomW
},
img:{
width:31/zoomW,
height:31/zoomW,
borderRadius:31/zoomW/2,
},
loadingBg:{
width:'100%',
height:'100%',
position:'absolute',
display:'flex',
alignItems:'center',
justifyContent:'center'
},
});