罗广聪

增加手机和公司 可修改

... ... @@ -32,6 +32,8 @@ export default class Login extends Component {
USER_ID: "",
NICKNAME: "",
PROFESSION: "",
COMPANY: "",
PHONE: "",
};
}
componentWillMount() {
... ... @@ -43,11 +45,10 @@ export default class Login extends Component {
_that.setState({
IS_LOGIN: result
});
// console.log("Login页面的AsyncStorage", result);
});
}
componentDidMount() {
console.log("thisprops", this.props);
// console.log("thisprops", this.props);
}
render() {
const { navigate } = this.props.navigation;
... ... @@ -227,27 +228,31 @@ export default class Login extends Component {
if (respJson.enmsg != "ok") {
alert(respJson.cnmsg);
} else {
console.log("登录后拿到的ID和nickname",respJson.data);
console.log("登录后返回值",respJson.data);
let id = JSON.stringify(respJson.data.id),
nickname = respJson.data.nickname,
phone = respJson.data.phone.toString(),
company = respJson.data.company,
profession = respJson.data.profession;
AsyncStorage.multiSet(
[["IS_LOGIN", "yes"], ["USER_ID",id], ["NICKNAME",nickname], ["PROFESSION",profession]],
[["IS_LOGIN", "yes"], ["USER_ID",id], ["NICKNAME",nickname], ["PROFESSION",profession], ["COMPANY",company], ["PHONE",phone]],
function(err) {
if (err) {
console.log("存储出错", err);
return false;
}
AsyncStorage.multiGet(["IS_LOGIN","USER_ID","NICKNAME","PROFESSION"],(err, result) => {
AsyncStorage.multiGet(["IS_LOGIN","USER_ID","NICKNAME","PROFESSION","COMPANY","PHONE"],(err, result) => {
if (err) {
console.error(err);
}
console.log("点击登录后的值",result)
// console.log("点击登录后的值",result)
that.setState({
IS_LOGIN: result[0][1],
USER_ID: (result[1][1] != null) ? result[1][1] : "",
NICKNAME: (result[2][1] != null) ? result[2][1] : "",
PROFESSION: (result[3][1] != null) ? result[3][1] : "",
COMPANY: (result[4][1] != null) ? result[4][1] : "",
PHONE: (result[5][1] != null) ? result[5][1] : "",
})
})
that.props.navigation.state.params.refreshCallback({
... ... @@ -255,6 +260,8 @@ export default class Login extends Component {
USER_ID: id,
NICKNAME: nickname,
PROFESSION: profession,
COMPANY: company,
PHONE: phone,
});
setTimeout(function () {
that.props.navigation.goBack();
... ...
... ... @@ -55,25 +55,30 @@ export default class Mine extends Component {
NICKNAME: "",
PROFESSION: "",
PHONT: "",
COMPONY: ""
COMPANY: "",
PHONE: "",
};
this.saveResponse1 = this.saveResponse1.bind(this);
this.saveResponse2 = this.saveResponse2.bind(this);
this.saveResponse3 = this.saveResponse3.bind(this);
this.saveResponse4 = this.saveResponse4.bind(this);
}
componentWillMount() {
var _that = this;
AsyncStorage.multiGet(
["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"],
["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION","COMPANY","PHONE"],
(err, result) => {
if (err) {
console.error(err);
}
console.log("最初始的四个个值", result);
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() : ""
PROFESSION: result[3][1] != null ? result[3][1].toString() : "",
COMPANY: result[4][1] != null ? result[4][1].toString() : "",
PHONE: result[5][1] != null ? result[5][1].toString() : "",
});
}
);
... ... @@ -108,12 +113,11 @@ export default class Mine extends Component {
saveResponse1(d) {
let that = this,
formData = new FormData();
if (that.state.IS_LOGIN != "yes") {
Alert.alert("请先登录账号");
return false;
}
// 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",
... ... @@ -145,13 +149,12 @@ export default class Mine extends Component {
saveResponse2(d) {
let that = this,
formData = new FormData();
if (that.state.IS_LOGIN != "yes") {
Alert.alert("请先登录账号");
return false;
}
// 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: {
... ... @@ -179,6 +182,78 @@ export default class Mine extends Component {
})
.catch(err => console.error(err));
}
saveResponse3(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("phone", 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.alert(respJson.cnmsg);
} else {
AsyncStorage.setItem("PHONE", d).then(() => {
console.log("保存修改成功");
that.setState({ PHONE: d });
});
}
})
.catch(err => console.error(err));
}
saveResponse4(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("company", 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.alert(respJson.cnmsg);
} else {
AsyncStorage.setItem("COMPANY", d).then(() => {
console.log("保存修改成功");
that.setState({ COMPANY: d });
});
}
})
.catch(err => console.error(err));
}
render() {
const { navigate } = this.props.navigation;
... ... @@ -258,12 +333,12 @@ export default class Mine extends Component {
/>
</View>
</TouchableOpacity>
{/* 公司 */}
{/* 手机 */}
<TouchableOpacity
style={styles.itemContainer}
onPress={() => {
if (this.state.IS_LOGIN == "yes") {
AlertIOS.prompt("更改手机", null, this.saveResponse2);
AlertIOS.prompt("更改手机", null, this.saveResponse3);
} else {
Alert.alert("请先登录账号");
}
... ... @@ -275,7 +350,7 @@ export default class Mine extends Component {
<View style={styles.itemRight}>
{this.state.IS_LOGIN === "yes" ? (
<Text style={styles.itemRightContent}>
{this.state.PHONT}
{this.state.PHONE}
</Text>
) : null}
<Image
... ... @@ -284,12 +359,12 @@ export default class Mine extends Component {
/>
</View>
</TouchableOpacity>
{/* 手机 */}
{/* 公司 */}
<TouchableOpacity
style={styles.itemContainer}
onPress={() => {
if (this.state.IS_LOGIN == "yes") {
AlertIOS.prompt("更改公司", null, this.saveResponse2);
AlertIOS.prompt("更改公司", null, this.saveResponse4);
} else {
Alert.alert("请先登录账号");
}
... ... @@ -301,7 +376,7 @@ export default class Mine extends Component {
<View style={styles.itemRight}>
{this.state.IS_LOGIN === "yes" ? (
<Text style={styles.itemRightContent}>
{this.state.COMPONY}
{this.state.COMPANY}
</Text>
) : null}
<Image
... ... @@ -400,7 +475,9 @@ export default class Mine extends Component {
IS_LOGIN: data.IS_LOGIN,
USER_ID: data.USER_ID,
NICKNAME: data.NICKNAME,
PROFESSION: data.PROFESSION
PROFESSION: data.PROFESSION,
COMPANY: data.COMPANY,
PHONE: data.PHONE,
});
}
});
... ...