Info.js
14.3 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/**
* 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,
Alert,
PermissionsAndroid
} from "react-native";
import {zoomW,zoomH} from '../../utils/getSize';
import xnService from "../../service/AppService";
import {checkCamera, xnToast} from "../../utils/utils"
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.politicalStatus == 1?require('../../img/defultPartyIcon.png'):require('../../img/defultIcon.png')),
nickName:global.user.nickName?global.user.nickName:global.user.mobilePhone,
age:global.user.age!==undefined?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?'是':'否':'-',
politicalName:'',
partyName:global.user.partyName?global.user.partyName:'',
volunteerName: global.user.volunteerName?global.user.volunteerName:'',
employeeNumber:global.user.isEmployee?global.user.employeeNumber:'-',
tempEmployeeNumber: ''
};
}
componentWillMount(){
if(global.user.politicalStatus != undefined) {
if(global.user.politicalStatus == 1) {
this.setState({
politicalName: '中共党员',
});
} else if(global.user.politicalStatus == 2) {
this.setState({
politicalName: '群众',
});
} else if(global.user.politicalStatus == 3) {
this.setState({
politicalName: '共青团员',
});
} else if(global.user.politicalStatus == 4) {
this.setState({
politicalName: '民主党派',
});
}
} else {
this.setState({
politicalName: '-',
});
}
}
componentDidMount(){
}
async check(select){
if (select==0){
//更新头像
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('用户取消了选择!');
}
else if (response.error) {
xnToast('相册访问失败,请重新尝试或检查是否开启相册权限');
}
else {
let timestamp = (new Date()).getTime();
let fileName = response.fileName ? global.user.id+timestamp+response.fileName : global.user.id+timestamp+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,data.info.fileUrl,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}:(global.user.politicalStatus == 1?require('../../img/defultPartyIcon.png'):require('../../img/defultIcon.png'))
})
}
})
})
}
})
}
});
}else if (select == 1) {
//更新昵称
this.props.navigation.navigate('ChangeUserInfo',{title:'修改昵称',defultValue:this.state.nickName || '',type:'nickName',callback:()=>{
this.setState({
nickName:global.user.nickName,
});
DeviceEventEmitter.emit('updateAvatar');
}});
}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) {
//更新政治面貌
let itemList = ['中共党员','群众','共青团员','民主党派'];
this.props.navigation.navigate('ChooseUserInfo',{title:'政治面貌',defultValue:this.state.politicalName,itemList:itemList,type:'partyMember',callback:()=>{
if(global.user.politicalStatus == 1) {
this.setState({
politicalName: '中共党员',
});
} else if(global.user.politicalStatus == 2) {
this.setState({
politicalName: '群众',
});
} else if(global.user.politicalStatus == 3) {
this.setState({
politicalName: '共青团员',
});
} else if(global.user.politicalStatus == 4) {
this.setState({
politicalName: '民主党派',
});
}
}});
}else if (select == 7) {
//更新员工认证
let data = await checkCamera();
if (data == 0){
}else{
this.props.navigation.navigate('IOSScan',{callBack:this.callBackBarcode})
}
}else if (select == 8) {
//更新活动一
this.props.navigation.navigate('ChooseActivityAttribute',{title:'平安地铁先锋行',defultValue:this.state.partyName,callback:()=>{
this.setState({
partyName:global.user.partyName,
})
}});
}else if (select == 9) {
//更新活动二
this.props.navigation.navigate('chooseVolunteerActivity',{title:'上海市平安志愿者',defultValue:this.state.volunteerName,callback:()=>{
this.setState({
volunteerName:global.user.volunteerName,
})
}});
}
}
// 扫描
callBackBarcode=(barcode) => {
// console.log(barcode,'---------------------------');
if(this.state.tempEmployeeNumber === barcode.split('-')[0]) {
return;
}
let _this = this;
let code = barcode.split('-')[0];
this.setState({
tempEmployeeNumber: code,
loading: true,
});
xnService.updateUserCompany({ userId: global.user.id, userCode: code }).then((data) => {
_this.setState({
loading: false,
});
if(data.code != '0') {
Alert.alert(
'认证失败',
'员工编号无效!',
[
{ text: '确定', onPress: () => _this.setState({ tempEmployeeNumber: '' })},
],
{ cancelable: false },
)
} else {
global.user.isEmployee = true;
global.user.employeeNumber = code;
_this.setState({
employeeNumber: code,
});
}
});
};
row(v,i){
return (
<TouchableOpacity style={[styles.row,{marginTop: (i === 0 || i === 6) ? 10 : 0, borderBottomWidth: (i === 5 || i === 7 || i === 9) ? 0 : 1}]} key={i}
onPress={()=>{this.check(i)}}>
<Text style={[styles.title,{fontSize:(i===8||i===9) ? 14 : 16}]}>{v.name}</Text>
{v.img&&<Image style={styles.img} defaultSource={global.user.politicalStatus == 1?require('../../img/defultPartyIcon.png'):require('../../img/defultIcon.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 scrollEventThrottle={200}>
{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.politicalName},6)}
{this.row({name:'员工认证',text:this.state.employeeNumber},7)}
<View style={[styles.row,{marginTop:10,borderBottomWidth:1}]}>
<Text style={[styles.title,{fontSize:16}]}>所属类别</Text>
</View>
{this.row({name:'平安地铁先锋行',text:this.state.partyName},8)}
{this.row({name:'上海市平安志愿者',text:this.state.volunteerName},9)}
</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:{
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'
},
});