罗广聪

增加手机和公司 可修改

@@ -32,6 +32,8 @@ export default class Login extends Component { @@ -32,6 +32,8 @@ export default class Login extends Component {
32 USER_ID: "", 32 USER_ID: "",
33 NICKNAME: "", 33 NICKNAME: "",
34 PROFESSION: "", 34 PROFESSION: "",
  35 + COMPANY: "",
  36 + PHONE: "",
35 }; 37 };
36 } 38 }
37 componentWillMount() { 39 componentWillMount() {
@@ -43,11 +45,10 @@ export default class Login extends Component { @@ -43,11 +45,10 @@ export default class Login extends Component {
43 _that.setState({ 45 _that.setState({
44 IS_LOGIN: result 46 IS_LOGIN: result
45 }); 47 });
46 - // console.log("Login页面的AsyncStorage", result);  
47 }); 48 });
48 } 49 }
49 componentDidMount() { 50 componentDidMount() {
50 - console.log("thisprops", this.props); 51 + // console.log("thisprops", this.props);
51 } 52 }
52 render() { 53 render() {
53 const { navigate } = this.props.navigation; 54 const { navigate } = this.props.navigation;
@@ -227,27 +228,31 @@ export default class Login extends Component { @@ -227,27 +228,31 @@ export default class Login extends Component {
227 if (respJson.enmsg != "ok") { 228 if (respJson.enmsg != "ok") {
228 alert(respJson.cnmsg); 229 alert(respJson.cnmsg);
229 } else { 230 } else {
230 - console.log("登录后拿到的ID和nickname",respJson.data); 231 + console.log("登录后返回值",respJson.data);
231 let id = JSON.stringify(respJson.data.id), 232 let id = JSON.stringify(respJson.data.id),
232 nickname = respJson.data.nickname, 233 nickname = respJson.data.nickname,
  234 + phone = respJson.data.phone.toString(),
  235 + company = respJson.data.company,
233 profession = respJson.data.profession; 236 profession = respJson.data.profession;
234 AsyncStorage.multiSet( 237 AsyncStorage.multiSet(
235 - [["IS_LOGIN", "yes"], ["USER_ID",id], ["NICKNAME",nickname], ["PROFESSION",profession]], 238 + [["IS_LOGIN", "yes"], ["USER_ID",id], ["NICKNAME",nickname], ["PROFESSION",profession], ["COMPANY",company], ["PHONE",phone]],
236 function(err) { 239 function(err) {
237 if (err) { 240 if (err) {
238 console.log("存储出错", err); 241 console.log("存储出错", err);
239 return false; 242 return false;
240 } 243 }
241 - AsyncStorage.multiGet(["IS_LOGIN","USER_ID","NICKNAME","PROFESSION"],(err, result) => { 244 + AsyncStorage.multiGet(["IS_LOGIN","USER_ID","NICKNAME","PROFESSION","COMPANY","PHONE"],(err, result) => {
242 if (err) { 245 if (err) {
243 console.error(err); 246 console.error(err);
244 } 247 }
245 - console.log("点击登录后的值",result) 248 + // console.log("点击登录后的值",result)
246 that.setState({ 249 that.setState({
247 IS_LOGIN: result[0][1], 250 IS_LOGIN: result[0][1],
248 USER_ID: (result[1][1] != null) ? result[1][1] : "", 251 USER_ID: (result[1][1] != null) ? result[1][1] : "",
249 NICKNAME: (result[2][1] != null) ? result[2][1] : "", 252 NICKNAME: (result[2][1] != null) ? result[2][1] : "",
250 PROFESSION: (result[3][1] != null) ? result[3][1] : "", 253 PROFESSION: (result[3][1] != null) ? result[3][1] : "",
  254 + COMPANY: (result[4][1] != null) ? result[4][1] : "",
  255 + PHONE: (result[5][1] != null) ? result[5][1] : "",
251 }) 256 })
252 }) 257 })
253 that.props.navigation.state.params.refreshCallback({ 258 that.props.navigation.state.params.refreshCallback({
@@ -255,6 +260,8 @@ export default class Login extends Component { @@ -255,6 +260,8 @@ export default class Login extends Component {
255 USER_ID: id, 260 USER_ID: id,
256 NICKNAME: nickname, 261 NICKNAME: nickname,
257 PROFESSION: profession, 262 PROFESSION: profession,
  263 + COMPANY: company,
  264 + PHONE: phone,
258 }); 265 });
259 setTimeout(function () { 266 setTimeout(function () {
260 that.props.navigation.goBack(); 267 that.props.navigation.goBack();
@@ -55,25 +55,30 @@ export default class Mine extends Component { @@ -55,25 +55,30 @@ export default class Mine extends Component {
55 NICKNAME: "", 55 NICKNAME: "",
56 PROFESSION: "", 56 PROFESSION: "",
57 PHONT: "", 57 PHONT: "",
58 - COMPONY: "" 58 + COMPANY: "",
  59 + PHONE: "",
59 }; 60 };
60 this.saveResponse1 = this.saveResponse1.bind(this); 61 this.saveResponse1 = this.saveResponse1.bind(this);
61 this.saveResponse2 = this.saveResponse2.bind(this); 62 this.saveResponse2 = this.saveResponse2.bind(this);
  63 + this.saveResponse3 = this.saveResponse3.bind(this);
  64 + this.saveResponse4 = this.saveResponse4.bind(this);
62 } 65 }
63 componentWillMount() { 66 componentWillMount() {
64 var _that = this; 67 var _that = this;
65 AsyncStorage.multiGet( 68 AsyncStorage.multiGet(
66 - ["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"], 69 + ["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION","COMPANY","PHONE"],
67 (err, result) => { 70 (err, result) => {
68 if (err) { 71 if (err) {
69 console.error(err); 72 console.error(err);
70 } 73 }
71 - console.log("最初始的四个个值", result); 74 + console.log("最初始的全局值", result);
72 _that.setState({ 75 _that.setState({
73 IS_LOGIN: result[0][1], 76 IS_LOGIN: result[0][1],
74 USER_ID: result[1][1] != null ? result[1][1].toString() : "", 77 USER_ID: result[1][1] != null ? result[1][1].toString() : "",
75 NICKNAME: result[2][1] != null ? result[2][1].toString() : "", 78 NICKNAME: result[2][1] != null ? result[2][1].toString() : "",
76 - PROFESSION: result[3][1] != null ? result[3][1].toString() : "" 79 + PROFESSION: result[3][1] != null ? result[3][1].toString() : "",
  80 + COMPANY: result[4][1] != null ? result[4][1].toString() : "",
  81 + PHONE: result[5][1] != null ? result[5][1].toString() : "",
77 }); 82 });
78 } 83 }
79 ); 84 );
@@ -108,12 +113,11 @@ export default class Mine extends Component { @@ -108,12 +113,11 @@ export default class Mine extends Component {
108 saveResponse1(d) { 113 saveResponse1(d) {
109 let that = this, 114 let that = this,
110 formData = new FormData(); 115 formData = new FormData();
111 - if (that.state.IS_LOGIN != "yes") { 116 + // if (that.state.IS_LOGIN != "yes") {
112 - Alert.alert("请先登录账号"); 117 + // Alert.alert("请先登录账号");
113 - return false; 118 + // return false;
114 - } 119 + // }
115 formData.append("user", this.state.USER_ID); 120 formData.append("user", this.state.USER_ID);
116 - formData.append("profession", "");  
117 formData.append("nickname", d); 121 formData.append("nickname", d);
118 return fetch(`https://devpay.brae.co/test/insurance/change`, { 122 return fetch(`https://devpay.brae.co/test/insurance/change`, {
119 method: "POST", 123 method: "POST",
@@ -145,13 +149,12 @@ export default class Mine extends Component { @@ -145,13 +149,12 @@ export default class Mine extends Component {
145 saveResponse2(d) { 149 saveResponse2(d) {
146 let that = this, 150 let that = this,
147 formData = new FormData(); 151 formData = new FormData();
148 - if (that.state.IS_LOGIN != "yes") { 152 + // if (that.state.IS_LOGIN != "yes") {
149 - Alert.alert("请先登录账号"); 153 + // Alert.alert("请先登录账号");
150 - return false; 154 + // return false;
151 - } 155 + // }
152 formData.append("user", this.state.USER_ID); 156 formData.append("user", this.state.USER_ID);
153 formData.append("profession", d); 157 formData.append("profession", d);
154 - formData.append("nickname", "");  
155 return fetch(`https://devpay.brae.co/test/insurance/change`, { 158 return fetch(`https://devpay.brae.co/test/insurance/change`, {
156 method: "POST", 159 method: "POST",
157 headers: { 160 headers: {
@@ -179,6 +182,78 @@ export default class Mine extends Component { @@ -179,6 +182,78 @@ export default class Mine extends Component {
179 }) 182 })
180 .catch(err => console.error(err)); 183 .catch(err => console.error(err));
181 } 184 }
  185 + saveResponse3(d) {
  186 + let that = this,
  187 + formData = new FormData();
  188 + // if (that.state.IS_LOGIN != "yes") {
  189 + // Alert.alert("请先登录账号");
  190 + // return false;
  191 + // }
  192 + formData.append("user", this.state.USER_ID);
  193 + formData.append("phone", d);
  194 + return fetch(`https://devpay.brae.co/test/insurance/change`, {
  195 + method: "POST",
  196 + headers: {
  197 + Accept: "application/json",
  198 + "Content-Type": "application/json"
  199 + },
  200 + body: formData
  201 + })
  202 + .then(resp => {
  203 + if (resp.status === 200) {
  204 + return resp.json();
  205 + } else {
  206 + console.error("something went wrong!");
  207 + }
  208 + })
  209 + .then(respJson => {
  210 + if (respJson.enmsg != "ok") {
  211 + Alert.alert(respJson.cnmsg);
  212 + } else {
  213 + AsyncStorage.setItem("PHONE", d).then(() => {
  214 + console.log("保存修改成功");
  215 + that.setState({ PHONE: d });
  216 + });
  217 + }
  218 + })
  219 + .catch(err => console.error(err));
  220 + }
  221 + saveResponse4(d) {
  222 + let that = this,
  223 + formData = new FormData();
  224 + // if (that.state.IS_LOGIN != "yes") {
  225 + // Alert.alert("请先登录账号");
  226 + // return false;
  227 + // }
  228 + formData.append("user", this.state.USER_ID);
  229 + formData.append("company", d);
  230 + return fetch(`https://devpay.brae.co/test/insurance/change`, {
  231 + method: "POST",
  232 + headers: {
  233 + Accept: "application/json",
  234 + "Content-Type": "application/json"
  235 + },
  236 + body: formData
  237 + })
  238 + .then(resp => {
  239 + if (resp.status === 200) {
  240 + return resp.json();
  241 + } else {
  242 + console.error("something went wrong!");
  243 + }
  244 + })
  245 + .then(respJson => {
  246 + if (respJson.enmsg != "ok") {
  247 + Alert.alert(respJson.cnmsg);
  248 + } else {
  249 + AsyncStorage.setItem("COMPANY", d).then(() => {
  250 + console.log("保存修改成功");
  251 + that.setState({ COMPANY: d });
  252 + });
  253 + }
  254 + })
  255 + .catch(err => console.error(err));
  256 + }
182 257
183 render() { 258 render() {
184 const { navigate } = this.props.navigation; 259 const { navigate } = this.props.navigation;
@@ -258,12 +333,12 @@ export default class Mine extends Component { @@ -258,12 +333,12 @@ export default class Mine extends Component {
258 /> 333 />
259 </View> 334 </View>
260 </TouchableOpacity> 335 </TouchableOpacity>
261 - {/* 公司 */} 336 + {/* 手机 */}
262 <TouchableOpacity 337 <TouchableOpacity
263 style={styles.itemContainer} 338 style={styles.itemContainer}
264 onPress={() => { 339 onPress={() => {
265 if (this.state.IS_LOGIN == "yes") { 340 if (this.state.IS_LOGIN == "yes") {
266 - AlertIOS.prompt("更改手机", null, this.saveResponse2); 341 + AlertIOS.prompt("更改手机", null, this.saveResponse3);
267 } else { 342 } else {
268 Alert.alert("请先登录账号"); 343 Alert.alert("请先登录账号");
269 } 344 }
@@ -275,7 +350,7 @@ export default class Mine extends Component { @@ -275,7 +350,7 @@ export default class Mine extends Component {
275 <View style={styles.itemRight}> 350 <View style={styles.itemRight}>
276 {this.state.IS_LOGIN === "yes" ? ( 351 {this.state.IS_LOGIN === "yes" ? (
277 <Text style={styles.itemRightContent}> 352 <Text style={styles.itemRightContent}>
278 - {this.state.PHONT} 353 + {this.state.PHONE}
279 </Text> 354 </Text>
280 ) : null} 355 ) : null}
281 <Image 356 <Image
@@ -284,12 +359,12 @@ export default class Mine extends Component { @@ -284,12 +359,12 @@ export default class Mine extends Component {
284 /> 359 />
285 </View> 360 </View>
286 </TouchableOpacity> 361 </TouchableOpacity>
287 - {/* 手机 */} 362 + {/* 公司 */}
288 <TouchableOpacity 363 <TouchableOpacity
289 style={styles.itemContainer} 364 style={styles.itemContainer}
290 onPress={() => { 365 onPress={() => {
291 if (this.state.IS_LOGIN == "yes") { 366 if (this.state.IS_LOGIN == "yes") {
292 - AlertIOS.prompt("更改公司", null, this.saveResponse2); 367 + AlertIOS.prompt("更改公司", null, this.saveResponse4);
293 } else { 368 } else {
294 Alert.alert("请先登录账号"); 369 Alert.alert("请先登录账号");
295 } 370 }
@@ -301,7 +376,7 @@ export default class Mine extends Component { @@ -301,7 +376,7 @@ export default class Mine extends Component {
301 <View style={styles.itemRight}> 376 <View style={styles.itemRight}>
302 {this.state.IS_LOGIN === "yes" ? ( 377 {this.state.IS_LOGIN === "yes" ? (
303 <Text style={styles.itemRightContent}> 378 <Text style={styles.itemRightContent}>
304 - {this.state.COMPONY} 379 + {this.state.COMPANY}
305 </Text> 380 </Text>
306 ) : null} 381 ) : null}
307 <Image 382 <Image
@@ -400,7 +475,9 @@ export default class Mine extends Component { @@ -400,7 +475,9 @@ export default class Mine extends Component {
400 IS_LOGIN: data.IS_LOGIN, 475 IS_LOGIN: data.IS_LOGIN,
401 USER_ID: data.USER_ID, 476 USER_ID: data.USER_ID,
402 NICKNAME: data.NICKNAME, 477 NICKNAME: data.NICKNAME,
403 - PROFESSION: data.PROFESSION 478 + PROFESSION: data.PROFESSION,
  479 + COMPANY: data.COMPANY,
  480 + PHONE: data.PHONE,
404 }); 481 });
405 } 482 }
406 }); 483 });