罗广聪

返回可刷新保圈

@@ -8,7 +8,7 @@ import { @@ -8,7 +8,7 @@ import {
8 TouchableOpacity, 8 TouchableOpacity,
9 Image, 9 Image,
10 AsyncStorage, 10 AsyncStorage,
11 - Alert, 11 + Alert
12 } from "react-native"; 12 } from "react-native";
13 import { StackNavigator, TabNavigator } from "react-navigation"; 13 import { StackNavigator, TabNavigator } from "react-navigation";
14 import Details from "./details"; 14 import Details from "./details";
@@ -37,7 +37,8 @@ export default class InsuranceCircle extends Component { @@ -37,7 +37,8 @@ export default class InsuranceCircle extends Component {
37 IS_LOGIN: "", 37 IS_LOGIN: "",
38 USER_ID: "", 38 USER_ID: "",
39 NICKNAME: "", 39 NICKNAME: "",
40 - PROFESSION: "" 40 + PROFESSION: "",
  41 + forGoBack: "",
41 }; 42 };
42 } 43 }
43 componentWillMount() { 44 componentWillMount() {
@@ -52,7 +53,7 @@ export default class InsuranceCircle extends Component { @@ -52,7 +53,7 @@ export default class InsuranceCircle extends Component {
52 testLoginAndGo() { 53 testLoginAndGo() {
53 const that = this; 54 const that = this;
54 const { navigate } = this.props.navigation; 55 const { navigate } = this.props.navigation;
55 - console.log("为何是underfined?",this); 56 + // console.log("为何是underfined?",this);
56 // this.getAsyncStorage(); 57 // this.getAsyncStorage();
57 AsyncStorage.multiGet( 58 AsyncStorage.multiGet(
58 ["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"], 59 ["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"],
@@ -60,26 +61,28 @@ export default class InsuranceCircle extends Component { @@ -60,26 +61,28 @@ export default class InsuranceCircle extends Component {
60 if (err) { 61 if (err) {
61 console.error(err); 62 console.error(err);
62 } 63 }
63 - console.log("点击登录后的值", result); 64 + // console.log("点击登录后的值", result);
64 - that.setState({ 65 + that.setState(
  66 + {
65 IS_LOGIN: result[0][1], 67 IS_LOGIN: result[0][1],
66 USER_ID: result[1][1] != null ? result[1][1] : "", 68 USER_ID: result[1][1] != null ? result[1][1] : "",
67 NICKNAME: result[2][1] != null ? result[2][1] : "", 69 NICKNAME: result[2][1] != null ? result[2][1] : "",
68 PROFESSION: result[3][1] != null ? result[3][1] : "" 70 PROFESSION: result[3][1] != null ? result[3][1] : ""
69 - },() => { 71 + },
70 - if (this.state.IS_LOGIN == 'yes') { 72 + () => {
71 - navigate("Release"); 73 + if (this.state.IS_LOGIN == "yes") {
  74 + navigate("Release", { refreshCallback: data => {
  75 + that.setState({
  76 + ListData: data
  77 + })
  78 + } });
72 } else { 79 } else {
73 Alert.alert("请先登录账号"); 80 Alert.alert("请先登录账号");
74 } 81 }
75 - });  
76 } 82 }
77 ); 83 );
78 - // if (this.state.IS_LOGIN == 'yes') { 84 + }
79 - // navigate("Release"); 85 + );
80 - // } else {  
81 - // Alert.alert("请先登录账号");  
82 - // }  
83 } 86 }
84 87
85 getAsyncStorage() { 88 getAsyncStorage() {
@@ -125,7 +128,7 @@ export default class InsuranceCircle extends Component { @@ -125,7 +128,7 @@ export default class InsuranceCircle extends Component {
125 that.setState({ 128 that.setState({
126 ListData: respJson.data.data 129 ListData: respJson.data.data
127 }); 130 });
128 - console.log("state.ListData", this.state.ListData); 131 + // console.log("state.ListData", this.state.ListData);
129 } 132 }
130 }) 133 })
131 .catch(err => console.error(err)); 134 .catch(err => console.error(err));
@@ -24,7 +24,8 @@ export default class Home extends Component { @@ -24,7 +24,8 @@ export default class Home extends Component {
24 IS_LOGIN: "", 24 IS_LOGIN: "",
25 USER_ID: "", 25 USER_ID: "",
26 NICKNAME: "", 26 NICKNAME: "",
27 - PROFESSION: "" 27 + PROFESSION: "",
  28 + listData: []
28 }; 29 };
29 } 30 }
30 componentWillMount() { 31 componentWillMount() {
@@ -51,9 +52,45 @@ export default class Home extends Component { @@ -51,9 +52,45 @@ export default class Home extends Component {
51 } 52 }
52 ); 53 );
53 } 54 }
54 - getListData() { 55 + addArticle() {
55 - let that = this; 56 + let that = this,
56 - return fetch(`https://devpay.brae.co/test/insurance/topic`, { 57 + id = this.state.USER_ID,
  58 + content = this.state.content,
  59 + title = this.state.title,
  60 + formData = new FormData();
  61 + formData.append("userid", id);
  62 + formData.append("title", title);
  63 + formData.append("content", content);
  64 + return fetch(`https://devpay.brae.co/test/insurance/article/add`, {
  65 + method: "POST",
  66 + headers: {
  67 + Accept: "application/json",
  68 + "Content-Type": "application/json"
  69 + },
  70 + body: formData
  71 + })
  72 + .then(resp => {
  73 + if (resp.status === 200) {
  74 + return resp.json();
  75 + } else {
  76 + console.error("something went wrong!");
  77 + }
  78 + })
  79 + .then(respJson => {
  80 + if (respJson.enmsg != "ok") {
  81 + alert(respJson.cnmsg);
  82 + } else {
  83 + that.getArticles();
  84 + setTimeout(function() {
  85 + that.props.navigation.goBack();
  86 + }, 1000);
  87 + }
  88 + });
  89 + }
  90 + getArticles() {
  91 + var that = this;
  92 + // 请求文章数据
  93 + return fetch(`https://devpay.brae.co/test/insurance/article`, {
57 method: "POST", 94 method: "POST",
58 headers: { 95 headers: {
59 Accept: "application/json", 96 Accept: "application/json",
@@ -72,11 +109,14 @@ export default class Home extends Component { @@ -72,11 +109,14 @@ export default class Home extends Component {
72 alert(respJson.cnmsg); 109 alert(respJson.cnmsg);
73 } else { 110 } else {
74 that.setState({ 111 that.setState({
75 - ListData: respJson.data.topic 112 + listData: respJson.data.data
76 - }); 113 + },() => {
77 - console.log("首页列表", this.state.ListData); 114 + that.props.navigation.state.params.refreshCallback(that.state.listData)
  115 + console.log("fanhuide",that.state.listData)
  116 + })
78 } 117 }
79 - }); 118 + })
  119 + .catch(err => console.error(err));
80 } 120 }
81 submit() { 121 submit() {
82 if (!this.state.title) { 122 if (!this.state.title) {
@@ -87,8 +127,9 @@ export default class Home extends Component { @@ -87,8 +127,9 @@ export default class Home extends Component {
87 Alert.alert("请填写内容"); 127 Alert.alert("请填写内容");
88 return false; 128 return false;
89 } 129 }
90 - console.log("title和content",this.state.title,this.state.content); 130 + this.addArticle();
91 } 131 }
  132 +
92 render() { 133 render() {
93 const { navigate } = this.props.navigation; 134 const { navigate } = this.props.navigation;
94 return ( 135 return (