Showing
3 changed files
with
107 additions
and
50 deletions
src/assets/Mine/iconpic_gray.png
0 → 100644
6.56 KB
| @@ -8,7 +8,8 @@ import { | @@ -8,7 +8,8 @@ import { | ||
| 8 | TouchableOpacity, | 8 | TouchableOpacity, |
| 9 | Image, | 9 | Image, |
| 10 | TextInput, | 10 | TextInput, |
| 11 | - KeyboardAvoidingView | 11 | + KeyboardAvoidingView, |
| 12 | + AsyncStorage | ||
| 12 | } from "react-native"; | 13 | } from "react-native"; |
| 13 | import WebView from "../../Components/CommonWebView"; | 14 | import WebView from "../../Components/CommonWebView"; |
| 14 | 15 | ||
| @@ -18,17 +19,34 @@ export default class Details extends Component { | @@ -18,17 +19,34 @@ export default class Details extends Component { | ||
| 18 | this.state = { | 19 | this.state = { |
| 19 | data: this.props.navigation.state.params.item, | 20 | data: this.props.navigation.state.params.item, |
| 20 | // 留言 | 21 | // 留言 |
| 21 | - text: "", | 22 | + content: "", |
| 22 | - comments: [] | 23 | + comments: [], |
| 24 | + IS_LOGIN: "", | ||
| 25 | + USER_ID: "", | ||
| 26 | + NICKNAME: "", | ||
| 27 | + PROFESSION: "" | ||
| 23 | }; | 28 | }; |
| 24 | } | 29 | } |
| 25 | componentWillMount() { | 30 | componentWillMount() { |
| 26 | - console.log("详情页", this); | ||
| 27 | this.getComments(); | 31 | this.getComments(); |
| 32 | + var _that = this; | ||
| 33 | + AsyncStorage.multiGet( | ||
| 34 | + ["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"], | ||
| 35 | + (err, result) => { | ||
| 36 | + if (err) { | ||
| 37 | + console.error(err); | ||
| 38 | + } | ||
| 39 | + _that.setState({ | ||
| 40 | + IS_LOGIN: result[0][1], | ||
| 41 | + USER_ID: result[1][1] != null ? result[1][1].toString() : "", | ||
| 42 | + NICKNAME: result[2][1] != null ? result[2][1].toString() : "", | ||
| 43 | + PROFESSION: result[3][1] != null ? result[3][1].toString() : "" | ||
| 44 | + }); | ||
| 45 | + console.log("详情页", this.state); | ||
| 46 | + } | ||
| 47 | + ); | ||
| 28 | } | 48 | } |
| 29 | - componentDidMount() { | 49 | + componentDidMount() {} |
| 30 | - // this.getComments(); | ||
| 31 | - } | ||
| 32 | 50 | ||
| 33 | render() { | 51 | render() { |
| 34 | const { data, comments } = this.state; | 52 | const { data, comments } = this.state; |
| @@ -98,8 +116,8 @@ export default class Details extends Component { | @@ -98,8 +116,8 @@ export default class Details extends Component { | ||
| 98 | <TextInput | 116 | <TextInput |
| 99 | style={styles.msgInput} | 117 | style={styles.msgInput} |
| 100 | placeholder="留言" | 118 | placeholder="留言" |
| 101 | - onChangeText={text => this.setState({ text })} | 119 | + onChangeText={content => this.setState({ content })} |
| 102 | - value={this.state.text} | 120 | + value={this.state.content} |
| 103 | autoCapitalize="none" | 121 | autoCapitalize="none" |
| 104 | selectionColor="#1B9341" | 122 | selectionColor="#1B9341" |
| 105 | clearTextOnFocus={true} | 123 | clearTextOnFocus={true} |
| @@ -153,17 +171,22 @@ export default class Details extends Component { | @@ -153,17 +171,22 @@ export default class Details extends Component { | ||
| 153 | }) | 171 | }) |
| 154 | .catch(err => console.error(err)); | 172 | .catch(err => console.error(err)); |
| 155 | } | 173 | } |
| 156 | - | 174 | + addComment() { |
| 157 | - sendMsg() { | ||
| 158 | var that = this, | 175 | var that = this, |
| 159 | - formData = new FormData(); | 176 | + id = this.state.USER_ID, |
| 160 | - // 请求文章数据 | 177 | + articleID = this.state.data.id, |
| 178 | + content = this.state.content, | ||
| 179 | + formData = new FormData(); | ||
| 180 | + formData.append("user", id); | ||
| 181 | + formData.append("article", articleID); | ||
| 182 | + formData.append("content", content); | ||
| 161 | return fetch(`https://devpay.brae.co/test/insurance/comment/add`, { | 183 | return fetch(`https://devpay.brae.co/test/insurance/comment/add`, { |
| 162 | method: "POST", | 184 | method: "POST", |
| 163 | headers: { | 185 | headers: { |
| 164 | Accept: "application/json", | 186 | Accept: "application/json", |
| 165 | "Content-Type": "application/json" | 187 | "Content-Type": "application/json" |
| 166 | - } | 188 | + }, |
| 189 | + body: formData | ||
| 167 | }) | 190 | }) |
| 168 | .then(resp => { | 191 | .then(resp => { |
| 169 | if (resp.status === 200) { | 192 | if (resp.status === 200) { |
| @@ -176,16 +199,21 @@ export default class Details extends Component { | @@ -176,16 +199,21 @@ export default class Details extends Component { | ||
| 176 | if (respJson.enmsg != "ok") { | 199 | if (respJson.enmsg != "ok") { |
| 177 | alert(respJson.cnmsg); | 200 | alert(respJson.cnmsg); |
| 178 | } else { | 201 | } else { |
| 202 | + that.getComments(); | ||
| 179 | that.setState({ | 203 | that.setState({ |
| 180 | - ListData: respJson.data.data | 204 | + content: "" |
| 181 | }); | 205 | }); |
| 182 | - console.log("state.ListData", this.state.ListData); | ||
| 183 | } | 206 | } |
| 184 | }) | 207 | }) |
| 185 | .catch(err => console.error(err)); | 208 | .catch(err => console.error(err)); |
| 186 | - this.setState({ | 209 | + } |
| 187 | - text: "" | 210 | + sendMsg() { |
| 188 | - }); | 211 | + if (this.state.IS_LOGIN != "yes") { |
| 212 | + alert("请先登录账号"); | ||
| 213 | + return false; | ||
| 214 | + } else { | ||
| 215 | + this.addComment(); | ||
| 216 | + } | ||
| 189 | } | 217 | } |
| 190 | } | 218 | } |
| 191 | 219 |
| @@ -19,25 +19,28 @@ export default class Mine extends Component { | @@ -19,25 +19,28 @@ export default class Mine extends Component { | ||
| 19 | IS_LOGIN: "", | 19 | IS_LOGIN: "", |
| 20 | USER_ID: "", | 20 | USER_ID: "", |
| 21 | NICKNAME: "", | 21 | NICKNAME: "", |
| 22 | - PROFESSION: "", | 22 | + PROFESSION: "" |
| 23 | }; | 23 | }; |
| 24 | this.saveResponse1 = this.saveResponse1.bind(this); | 24 | this.saveResponse1 = this.saveResponse1.bind(this); |
| 25 | this.saveResponse2 = this.saveResponse2.bind(this); | 25 | this.saveResponse2 = this.saveResponse2.bind(this); |
| 26 | } | 26 | } |
| 27 | componentWillMount() { | 27 | componentWillMount() { |
| 28 | var _that = this; | 28 | var _that = this; |
| 29 | - AsyncStorage.multiGet(["IS_LOGIN","USER_ID","NICKNAME","PROFESSION"],(err, result) => { | 29 | + AsyncStorage.multiGet( |
| 30 | - if (err) { | 30 | + ["IS_LOGIN", "USER_ID", "NICKNAME", "PROFESSION"], |
| 31 | - console.error(err); | 31 | + (err, result) => { |
| 32 | + if (err) { | ||
| 33 | + console.error(err); | ||
| 34 | + } | ||
| 35 | + console.log("最初始的四个个值", result); | ||
| 36 | + _that.setState({ | ||
| 37 | + IS_LOGIN: result[0][1], | ||
| 38 | + USER_ID: result[1][1] != null ? result[1][1].toString() : "", | ||
| 39 | + NICKNAME: result[2][1] != null ? result[2][1].toString() : "", | ||
| 40 | + PROFESSION: result[3][1] != null ? result[3][1].toString() : "" | ||
| 41 | + }); | ||
| 32 | } | 42 | } |
| 33 | - console.log("最初始的四个个值",result) | 43 | + ); |
| 34 | - _that.setState({ | ||
| 35 | - IS_LOGIN: result[0][1], | ||
| 36 | - USER_ID: (result[1][1] != null) ? result[1][1].toString() : "", | ||
| 37 | - NICKNAME: (result[2][1] != null) ? result[2][1].toString() : "", | ||
| 38 | - PROFESSION: (result[3][1] != null) ? result[3][1].toString() : "", | ||
| 39 | - }) | ||
| 40 | - }) | ||
| 41 | } | 44 | } |
| 42 | componentDidMount() { | 45 | componentDidMount() { |
| 43 | // console.log("hello,AsyncStorage"); | 46 | // console.log("hello,AsyncStorage"); |
| @@ -45,8 +48,13 @@ export default class Mine extends Component { | @@ -45,8 +48,13 @@ export default class Mine extends Component { | ||
| 45 | signOut() { | 48 | signOut() { |
| 46 | var _that = this; | 49 | var _that = this; |
| 47 | AsyncStorage.multiSet( | 50 | AsyncStorage.multiSet( |
| 48 | - [["IS_LOGIN", "no"], ["USER_ID",""], ["NICKNAME",""],["PROFESSION",""]], | 51 | + [ |
| 49 | - function (err) { | 52 | + ["IS_LOGIN", "no"], |
| 53 | + ["USER_ID", ""], | ||
| 54 | + ["NICKNAME", ""], | ||
| 55 | + ["PROFESSION", ""] | ||
| 56 | + ], | ||
| 57 | + function(err) { | ||
| 50 | if (err) { | 58 | if (err) { |
| 51 | console.log("存储出错", err); | 59 | console.log("存储出错", err); |
| 52 | return false; | 60 | return false; |
| @@ -55,11 +63,11 @@ export default class Mine extends Component { | @@ -55,11 +63,11 @@ export default class Mine extends Component { | ||
| 55 | IS_LOGIN: "no", | 63 | IS_LOGIN: "no", |
| 56 | USER_ID: "", | 64 | USER_ID: "", |
| 57 | NICKNAME: "", | 65 | NICKNAME: "", |
| 58 | - PROFESSION: "", | 66 | + PROFESSION: "" |
| 59 | - }) | 67 | + }); |
| 60 | - console.log("退出登录后的值",_that.state) | 68 | + console.log("退出登录后的值", _that.state); |
| 61 | - } | 69 | + } |
| 62 | - ) | 70 | + ); |
| 63 | } | 71 | } |
| 64 | saveResponse1(d) { | 72 | saveResponse1(d) { |
| 65 | if (this.state.IS_LOGIN == "yes") { | 73 | if (this.state.IS_LOGIN == "yes") { |
| @@ -77,10 +85,25 @@ export default class Mine extends Component { | @@ -77,10 +85,25 @@ export default class Mine extends Component { | ||
| 77 | <View style={styles.container}> | 85 | <View style={styles.container}> |
| 78 | {/* 头部头像 */} | 86 | {/* 头部头像 */} |
| 79 | <View style={styles.header}> | 87 | <View style={styles.header}> |
| 80 | - <Image | 88 | + {this.state.IS_LOGIN == "yes" ? ( |
| 89 | + <Image | ||
| 90 | + source={require("../../assets/Mine/iconpic1.png")} | ||
| 91 | + style={styles.mineIcon} | ||
| 92 | + /> | ||
| 93 | + ) : ( | ||
| 94 | + <Image | ||
| 95 | + source={require("../../assets/Mine/iconpic_gray.png")} | ||
| 96 | + style={styles.mineIcon} | ||
| 97 | + /> | ||
| 98 | + )} | ||
| 99 | + {/* <Image | ||
| 81 | source={require("../../assets/Mine/iconpic1.png")} | 100 | source={require("../../assets/Mine/iconpic1.png")} |
| 82 | style={styles.mineIcon} | 101 | style={styles.mineIcon} |
| 83 | /> | 102 | /> |
| 103 | + <Image | ||
| 104 | + source={require("../../assets/Mine/iconpic_gray.png")} | ||
| 105 | + style={styles.mineIcon} | ||
| 106 | + /> */} | ||
| 84 | </View> | 107 | </View> |
| 85 | <View style={styles.midContainer}> | 108 | <View style={styles.midContainer}> |
| 86 | {/* 更改昵称 */} | 109 | {/* 更改昵称 */} |
| @@ -99,7 +122,9 @@ export default class Mine extends Component { | @@ -99,7 +122,9 @@ export default class Mine extends Component { | ||
| 99 | </View> | 122 | </View> |
| 100 | <View style={styles.itemRight}> | 123 | <View style={styles.itemRight}> |
| 101 | {this.state.IS_LOGIN === "yes" ? ( | 124 | {this.state.IS_LOGIN === "yes" ? ( |
| 102 | - <Text style={styles.itemRightContent}>{this.state.NICKNAME}</Text> | 125 | + <Text style={styles.itemRightContent}> |
| 126 | + {this.state.NICKNAME} | ||
| 127 | + </Text> | ||
| 103 | ) : null} | 128 | ) : null} |
| 104 | <Image | 129 | <Image |
| 105 | style={styles.itemRightImg} | 130 | style={styles.itemRightImg} |
| @@ -122,7 +147,9 @@ export default class Mine extends Component { | @@ -122,7 +147,9 @@ export default class Mine extends Component { | ||
| 122 | <Text style={styles.leftTitle}>设置职业</Text> | 147 | <Text style={styles.leftTitle}>设置职业</Text> |
| 123 | </View> | 148 | </View> |
| 124 | <View style={styles.itemRight}> | 149 | <View style={styles.itemRight}> |
| 125 | - <Text style={styles.itemRightContent}>{this.state.PROFESSION}</Text> | 150 | + <Text style={styles.itemRightContent}> |
| 151 | + {this.state.PROFESSION} | ||
| 152 | + </Text> | ||
| 126 | {this.state.IS_LOGIN === "yes" ? ( | 153 | {this.state.IS_LOGIN === "yes" ? ( |
| 127 | <Text style={styles.itemRightContent}> | 154 | <Text style={styles.itemRightContent}> |
| 128 | {this.state.identity} | 155 | {this.state.identity} |
| @@ -143,15 +170,17 @@ export default class Mine extends Component { | @@ -143,15 +170,17 @@ export default class Mine extends Component { | ||
| 143 | onPress={() => { | 170 | onPress={() => { |
| 144 | this.state.IS_LOGIN == "yes" | 171 | this.state.IS_LOGIN == "yes" |
| 145 | ? this.signOut() | 172 | ? this.signOut() |
| 146 | - : navigate("Login", { refreshCallback: (data)=>{ | 173 | + : navigate("Login", { |
| 147 | - console.log("refreshCallback参数",data); | 174 | + refreshCallback: data => { |
| 148 | - this.setState({ | 175 | + console.log("refreshCallback参数", data); |
| 149 | - IS_LOGIN: data.IS_LOGIN, | 176 | + this.setState({ |
| 150 | - USER_ID: data.USER_ID, | 177 | + IS_LOGIN: data.IS_LOGIN, |
| 151 | - NICKNAME: data.NICKNAME, | 178 | + USER_ID: data.USER_ID, |
| 152 | - PROFESSION: data.PROFESSION, | 179 | + NICKNAME: data.NICKNAME, |
| 153 | - }) | 180 | + PROFESSION: data.PROFESSION |
| 154 | - } }); | 181 | + }); |
| 182 | + } | ||
| 183 | + }); | ||
| 155 | }} | 184 | }} |
| 156 | > | 185 | > |
| 157 | <Text style={styles.loginOutText}> | 186 | <Text style={styles.loginOutText}> |
-
Please register or login to post a comment