罗广聪

返回可刷新保圈

... ... @@ -8,7 +8,7 @@ import {
TouchableOpacity,
Image,
AsyncStorage,
Alert,
Alert
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";
import Details from "./details";
... ... @@ -37,7 +37,8 @@ export default class InsuranceCircle extends Component {
IS_LOGIN: "",
USER_ID: "",
NICKNAME: "",
PROFESSION: ""
PROFESSION: "",
forGoBack: "",
};
}
componentWillMount() {
... ... @@ -52,7 +53,7 @@ export default class InsuranceCircle extends Component {
testLoginAndGo() {
const that = this;
const { navigate } = this.props.navigation;
console.log("为何是underfined?",this);
// console.log("为何是underfined?",this);
// this.getAsyncStorage();
AsyncStorage.multiGet(
["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"],
... ... @@ -60,26 +61,28 @@ export default class InsuranceCircle extends Component {
if (err) {
console.error(err);
}
console.log("点击登录后的值", result);
that.setState({
// 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] : ""
},() => {
if (this.state.IS_LOGIN == 'yes') {
navigate("Release");
},
() => {
if (this.state.IS_LOGIN == "yes") {
navigate("Release", { refreshCallback: data => {
that.setState({
ListData: data
})
} });
} else {
Alert.alert("请先登录账号");
}
});
}
);
// if (this.state.IS_LOGIN == 'yes') {
// navigate("Release");
// } else {
// Alert.alert("请先登录账号");
// }
}
);
}
getAsyncStorage() {
... ... @@ -125,7 +128,7 @@ export default class InsuranceCircle extends Component {
that.setState({
ListData: respJson.data.data
});
console.log("state.ListData", this.state.ListData);
// console.log("state.ListData", this.state.ListData);
}
})
.catch(err => console.error(err));
... ...
... ... @@ -24,7 +24,8 @@ export default class Home extends Component {
IS_LOGIN: "",
USER_ID: "",
NICKNAME: "",
PROFESSION: ""
PROFESSION: "",
listData: []
};
}
componentWillMount() {
... ... @@ -51,9 +52,45 @@ export default class Home extends Component {
}
);
}
getListData() {
let that = this;
return fetch(`https://devpay.brae.co/test/insurance/topic`, {
addArticle() {
let that = this,
id = this.state.USER_ID,
content = this.state.content,
title = this.state.title,
formData = new FormData();
formData.append("userid", id);
formData.append("title", title);
formData.append("content", content);
return fetch(`https://devpay.brae.co/test/insurance/article/add`, {
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 {
that.getArticles();
setTimeout(function() {
that.props.navigation.goBack();
}, 1000);
}
});
}
getArticles() {
var that = this;
// 请求文章数据
return fetch(`https://devpay.brae.co/test/insurance/article`, {
method: "POST",
headers: {
Accept: "application/json",
... ... @@ -72,11 +109,14 @@ export default class Home extends Component {
alert(respJson.cnmsg);
} else {
that.setState({
ListData: respJson.data.topic
});
console.log("首页列表", this.state.ListData);
listData: respJson.data.data
},() => {
that.props.navigation.state.params.refreshCallback(that.state.listData)
console.log("fanhuide",that.state.listData)
})
}
});
})
.catch(err => console.error(err));
}
submit() {
if (!this.state.title) {
... ... @@ -87,8 +127,9 @@ export default class Home extends Component {
Alert.alert("请填写内容");
return false;
}
console.log("title和content",this.state.title,this.state.content);
this.addArticle();
}
render() {
const { navigate } = this.props.navigation;
return (
... ...