index.js
12.6 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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
import React, { Component } from "react";
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
Image,
Alert,
AlertIOS,
AsyncStorage,
Button,
ScrollView
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";
export default class Mine extends Component {
constructor(props) {
super(props);
this.state = {
IS_LOGIN: "",
USER_ID: "",
NICKNAME: "",
PROFESSION: "",
PHONT: "",
COMPONY: ""
};
this.saveResponse1 = this.saveResponse1.bind(this);
this.saveResponse2 = this.saveResponse2.bind(this);
}
componentWillMount() {
var _that = this;
AsyncStorage.multiGet(
["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"],
(err, result) => {
if (err) {
console.error(err);
}
console.log("最初始的四个个值", result);
_that.setState({
IS_LOGIN: result[0][1],
USER_ID: result[1][1] != null ? result[1][1].toString() : "",
NICKNAME: result[2][1] != null ? result[2][1].toString() : "",
PROFESSION: result[3][1] != null ? result[3][1].toString() : ""
});
}
);
}
componentDidMount() {
// console.log("hello,AsyncStorage");
}
signOut() {
var _that = this;
AsyncStorage.multiSet(
[
["IS_LOGIN", "no"],
["USER_ID", ""],
["NICKNAME", ""],
["PROFESSION", ""]
],
function(err) {
if (err) {
console.log("存储出错", err);
return false;
}
_that.setState({
IS_LOGIN: "no",
USER_ID: "",
NICKNAME: "",
PROFESSION: ""
});
console.log("退出登录后的值", _that.state);
}
);
}
saveResponse1(d) {
let that = this,
formData = new FormData();
if (that.state.IS_LOGIN != "yes") {
Alert.alert("请先登录账号");
return false;
}
formData.append("user", this.state.USER_ID);
formData.append("profession", "");
formData.append("nickname", d);
return fetch(`https://devpay.brae.co/test/insurance/change`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: formData
})
.then(resp => {
if (resp.status === 200) {
return resp.json();
} else {
console.error("something went wrong!");
}
})
.then(respJson => {
if (respJson.enmsg != "ok") {
alert(respJson.cnmsg);
} else {
AsyncStorage.setItem("NICKNAME", d).then(() => {
console.log("保存修改成功");
that.setState({ NICKNAME: d });
});
}
})
.catch(err => console.error(err));
}
saveResponse2(d) {
let that = this,
formData = new FormData();
if (that.state.IS_LOGIN != "yes") {
Alert.alert("请先登录账号");
return false;
}
formData.append("user", this.state.USER_ID);
formData.append("profession", d);
formData.append("nickname", "");
return fetch(`https://devpay.brae.co/test/insurance/change`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: formData
})
.then(resp => {
if (resp.status === 200) {
return resp.json();
} else {
console.error("something went wrong!");
}
})
.then(respJson => {
if (respJson.enmsg != "ok") {
Alert.alert(respJson.cnmsg);
} else {
AsyncStorage.setItem("PROFESSION", d).then(() => {
console.log("保存修改成功");
that.setState({ PROFESSION: d });
});
}
})
.catch(err => console.error(err));
}
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<ScrollView>
{/* 头部头像 */}
<View style={styles.header}>
{this.state.IS_LOGIN == "yes" ? (
<Image
source={require("../../assets/Mine/iconpic1.png")}
style={styles.mineIcon}
/>
) : (
<Image
source={require("../../assets/Mine/iconpic_gray.png")}
style={styles.mineIcon}
/>
)}
{this.state.IS_LOGIN == "yes" ? null : (
<Text style={styles.headerText}>登录可享更多特权</Text>
)}
</View>
{/* 设置昵称和职业 */}
{this.state.IS_LOGIN == "yes" ? (
<View style={styles.midContainer}>
{/* 更改昵称 */}
<TouchableOpacity
style={styles.itemContainer}
onPress={() => {
if (this.state.IS_LOGIN == "yes") {
AlertIOS.prompt("更改昵称", null, this.saveResponse1);
} else {
Alert.alert("请先登录账号");
}
}}
>
<View style={styles.itemLeft}>
<Text style={styles.leftTitle}>昵称</Text>
</View>
<View style={styles.itemRight}>
{this.state.IS_LOGIN === "yes" ? (
<Text style={styles.itemRightContent}>
{this.state.NICKNAME}
</Text>
) : null}
<Image
style={styles.itemRightImg}
source={require("../../assets/Mine/rightArrow_gray.png")}
/>
</View>
</TouchableOpacity>
{/* 更改职业 */}
<TouchableOpacity
style={styles.itemContainer}
onPress={() => {
if (this.state.IS_LOGIN == "yes") {
AlertIOS.prompt("更改职业", null, this.saveResponse2);
} else {
Alert.alert("请先登录账号");
}
}}
>
<View style={styles.itemLeft}>
<Text style={styles.leftTitle}>职业</Text>
</View>
<View style={styles.itemRight}>
{this.state.IS_LOGIN === "yes" ? (
<Text style={styles.itemRightContent}>
{this.state.PROFESSION}
</Text>
) : null}
<Image
style={styles.itemRightImg}
source={require("../../assets/Mine/rightArrow_gray.png")}
/>
</View>
</TouchableOpacity>
{/* 公司 */}
<TouchableOpacity
style={styles.itemContainer}
onPress={() => {
if (this.state.IS_LOGIN == "yes") {
AlertIOS.prompt("更改手机", null, this.saveResponse2);
} else {
Alert.alert("请先登录账号");
}
}}
>
<View style={styles.itemLeft}>
<Text style={styles.leftTitle}>手机</Text>
</View>
<View style={styles.itemRight}>
{this.state.IS_LOGIN === "yes" ? (
<Text style={styles.itemRightContent}>
{this.state.PHONT}
</Text>
) : null}
<Image
style={styles.itemRightImg}
source={require("../../assets/Mine/rightArrow_gray.png")}
/>
</View>
</TouchableOpacity>
{/* 手机 */}
<TouchableOpacity
style={styles.itemContainer}
onPress={() => {
if (this.state.IS_LOGIN == "yes") {
AlertIOS.prompt("更改公司", null, this.saveResponse2);
} else {
Alert.alert("请先登录账号");
}
}}
>
<View style={styles.itemLeft}>
<Text style={styles.leftTitle}>公司</Text>
</View>
<View style={styles.itemRight}>
{this.state.IS_LOGIN === "yes" ? (
<Text style={styles.itemRightContent}>
{this.state.COMPONY}
</Text>
) : null}
<Image
style={styles.itemRightImg}
source={require("../../assets/Mine/rightArrow_gray.png")}
/>
</View>
</TouchableOpacity>
</View>
) : null}
<View style={styles.midContainer}>
<TouchableOpacity style={styles.itemContainer}>
<View style={styles.itemLeft}>
<Text style={styles.leftTitle}>评价我们</Text>
</View>
<View style={styles.itemRight}>
<Image
style={styles.itemRightImg}
source={require("../../assets/Mine/rightArrow_gray.png")}
/>
</View>
</TouchableOpacity>
<TouchableOpacity style={styles.itemContainer}>
<View style={styles.itemLeft}>
<Text style={styles.leftTitle}>客服电话</Text>
</View>
<View style={styles.itemRight}>
<Text style={styles.itemRightContent}>4001-608876</Text>
<Image
style={styles.itemRightImg}
source={require("../../assets/Mine/rightArrow_gray.png")}
/>
</View>
</TouchableOpacity>
</View>
<View style={styles.midContainer}>
<TouchableOpacity style={styles.itemContainer}>
<View style={styles.itemLeft}>
<Text style={styles.leftTitle}>当前版本</Text>
</View>
<View style={styles.itemRight}>
<Text style={styles.itemRightContent}>
V1.0.0
</Text>
</View>
</TouchableOpacity>
</View>
{/* 登录 */}
<TouchableOpacity
style={styles.loginOut}
onLogin={this.props.onLogin}
onPress={() => {
this.state.IS_LOGIN == "yes"
? this.signOut()
: navigate("Login", {
refreshCallback: data => {
console.log("refreshCallback参数", data);
this.setState({
IS_LOGIN: data.IS_LOGIN,
USER_ID: data.USER_ID,
NICKNAME: data.NICKNAME,
PROFESSION: data.PROFESSION
});
}
});
}}
>
<Text style={styles.loginOutText}>
{this.state.IS_LOGIN == "yes" ? "退出登录" : "登录"}
</Text>
</TouchableOpacity>
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "flex-start",
alignItems: "stretch",
backgroundColor: "#EFEFEF"
},
header: {
backgroundColor: "#1B9341",
height: 154,
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
marginBottom: 10
},
headerText: {
fontSize: 15,
color: "#fff",
marginLeft: 22
},
mineIcon: {
width: 86,
height: 86
},
mineName: {
fontSize: 16,
lineHeight: 22,
color: "#fff"
},
headerRight: {
width: 14,
height: 14
},
midContainer: {
marginBottom: 10
},
itemContainer: {
height: 46,
paddingLeft: 16,
paddingRight: 16,
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
backgroundColor: "#fff",
borderStyle: "solid",
borderColor: "#F0F0F0",
borderBottomWidth: 1
},
itemLeft: {
flexDirection: "row",
justifyContent: "flex-start",
alignItems: "center"
},
leftTitle: {
fontSize: 15,
color: "#242424"
},
itemRight: {
flexDirection: "row",
justifyContent: "flex-start",
alignItems: "center"
},
itemRightContent: {
marginRight: 5,
color: "#7A7A7A"
},
itemRightImg: {
width: 14,
height: 14
},
loginOut: {
marginBottom: 10,
height: 46,
backgroundColor: "#fff",
justifyContent: "center"
},
loginOutText: {
textAlign: "center",
fontSize: 15
}
});