Showing
3 changed files
with
161 additions
and
61 deletions
| @@ -10,7 +10,8 @@ import { | @@ -10,7 +10,8 @@ import { | ||
| 10 | ListView, | 10 | ListView, |
| 11 | Dimensions, | 11 | Dimensions, |
| 12 | DatePickerIOS, | 12 | DatePickerIOS, |
| 13 | - AsyncStorage | 13 | + AsyncStorage, |
| 14 | + Alert | ||
| 14 | } from "react-native"; | 15 | } from "react-native"; |
| 15 | import { StackNavigator, TabNavigator } from "react-navigation"; | 16 | import { StackNavigator, TabNavigator } from "react-navigation"; |
| 16 | import post from "../../../utils/fetch"; | 17 | import post from "../../../utils/fetch"; |
| @@ -69,34 +70,6 @@ export default class Home extends Component { | @@ -69,34 +70,6 @@ export default class Home extends Component { | ||
| 69 | 70 | ||
| 70 | componentDidMount() {} | 71 | componentDidMount() {} |
| 71 | 72 | ||
| 72 | - getListData() { | ||
| 73 | - let that = this; | ||
| 74 | - return fetch(`https://devpay.brae.co/test/insurance/topic`, { | ||
| 75 | - method: "POST", | ||
| 76 | - headers: { | ||
| 77 | - Accept: "application/json", | ||
| 78 | - "Content-Type": "application/json" | ||
| 79 | - } | ||
| 80 | - }) | ||
| 81 | - .then(resp => { | ||
| 82 | - if (resp.status === 200) { | ||
| 83 | - return resp.json(); | ||
| 84 | - } else { | ||
| 85 | - console.error("something went wrong!"); | ||
| 86 | - } | ||
| 87 | - }) | ||
| 88 | - .then(respJson => { | ||
| 89 | - if (respJson.enmsg != "ok") { | ||
| 90 | - alert(respJson.cnmsg); | ||
| 91 | - } else { | ||
| 92 | - that.setState({ | ||
| 93 | - ListData: respJson.data.topic | ||
| 94 | - }); | ||
| 95 | - console.log("首页列表", this.state.ListData); | ||
| 96 | - } | ||
| 97 | - }); | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | getAsyncStorage() { | 73 | getAsyncStorage() { |
| 101 | const that = this; | 74 | const that = this; |
| 102 | AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { | 75 | AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { |
| @@ -173,34 +146,33 @@ export default class Home extends Component { | @@ -173,34 +146,33 @@ export default class Home extends Component { | ||
| 173 | } | 146 | } |
| 174 | 147 | ||
| 175 | submit() { | 148 | submit() { |
| 176 | - const that = this; | 149 | + const that = this, |
| 177 | - const { answerList,USER_ID } = this.state; | 150 | + { answerList, USER_ID } = this.state, |
| 178 | - const { navigate } = this.props.navigation; | 151 | + { navigate } = this.props.navigation; |
| 179 | let Temp = this.state.QuesList.map(item => item.answers[item.selected]); | 152 | let Temp = this.state.QuesList.map(item => item.answers[item.selected]); |
| 180 | - console.log(Temp); | ||
| 181 | Temp.splice(3, 1, that.format(that.state.date)); | 153 | Temp.splice(3, 1, that.format(that.state.date)); |
| 182 | - that.setState( | 154 | + let Result = { |
| 183 | - { | 155 | + age: 2017 - parseInt(Temp[3].split("-")[0]), |
| 184 | - answerList: Temp | 156 | + security: Temp[5], |
| 185 | - }, | 157 | + income: Temp[4], |
| 186 | - () => { | 158 | + debt: Temp[2] |
| 159 | + }; | ||
| 160 | + console.log("temp Result", Temp, Result); | ||
| 161 | + if (this.state.IS_LOGIN != "yes") { | ||
| 162 | + Alert.alert("请先登录账号"); | ||
| 163 | + } else { | ||
| 187 | post( | 164 | post( |
| 188 | `/test/insurance/advice`, | 165 | `/test/insurance/advice`, |
| 189 | { | 166 | { |
| 190 | - userid: USER_ID, | 167 | + userid: this.state.USER_ID, |
| 191 | - // result: answerList | 168 | + result: Result |
| 192 | }, | 169 | }, |
| 193 | res => { | 170 | res => { |
| 194 | - Alert.alert("导入成功,点击“OK”查看结果", null, () => { | 171 | + navigate("AISolution"); |
| 195 | - navigate("AISolution", { answerList: that.state.answerList }); | ||
| 196 | - }); | ||
| 197 | }, | 172 | }, |
| 198 | - err => { | 173 | + err => {} |
| 199 | - console.log(err); | ||
| 200 | - } | ||
| 201 | ); | 174 | ); |
| 202 | } | 175 | } |
| 203 | - ); | ||
| 204 | } | 176 | } |
| 205 | 177 | ||
| 206 | format(date) { | 178 | format(date) { |
| @@ -8,16 +8,25 @@ import { | @@ -8,16 +8,25 @@ import { | ||
| 8 | TouchableOpacity, | 8 | TouchableOpacity, |
| 9 | ScrollView, | 9 | ScrollView, |
| 10 | ListView, | 10 | ListView, |
| 11 | - Dimensions | 11 | + Dimensions, |
| 12 | + AsyncStorage, | ||
| 13 | + Alert | ||
| 12 | } from "react-native"; | 14 | } from "react-native"; |
| 13 | -import { StackNavigator, TabNavigator, NavigationActions } from "react-navigation"; | 15 | +import { |
| 16 | + StackNavigator, | ||
| 17 | + TabNavigator, | ||
| 18 | + NavigationActions | ||
| 19 | +} from "react-navigation"; | ||
| 14 | import { Col, Row, Grid } from "react-native-easy-grid"; | 20 | import { Col, Row, Grid } from "react-native-easy-grid"; |
| 21 | +import post from "../../../utils/fetch"; | ||
| 15 | 22 | ||
| 16 | export default class Home extends Component { | 23 | export default class Home extends Component { |
| 17 | constructor(props) { | 24 | constructor(props) { |
| 18 | super(props); | 25 | super(props); |
| 19 | this.state = { | 26 | this.state = { |
| 20 | gridData: { | 27 | gridData: { |
| 28 | + IS_LOGIN: "", | ||
| 29 | + USER_ID: "", | ||
| 21 | title: ["角色", "建议产品", "建议保额", "保险年限", "缴费期限", "年缴保费"], | 30 | title: ["角色", "建议产品", "建议保额", "保险年限", "缴费期限", "年缴保费"], |
| 22 | actor: "父亲", | 31 | actor: "父亲", |
| 23 | age: "42岁", | 32 | age: "42岁", |
| @@ -48,10 +57,25 @@ export default class Home extends Component { | @@ -48,10 +57,25 @@ export default class Home extends Component { | ||
| 48 | } | 57 | } |
| 49 | }; | 58 | }; |
| 50 | } | 59 | } |
| 51 | - componentWillMount() {} | 60 | + componentWillMount() { |
| 61 | + this.getAsyncStorage(); | ||
| 62 | + } | ||
| 52 | 63 | ||
| 53 | componentDidMount() {} | 64 | componentDidMount() {} |
| 54 | 65 | ||
| 66 | + getAsyncStorage() { | ||
| 67 | + const that = this; | ||
| 68 | + AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { | ||
| 69 | + if (err) { | ||
| 70 | + console.error(err); | ||
| 71 | + } | ||
| 72 | + that.setState({ | ||
| 73 | + IS_LOGIN: result[0][1], | ||
| 74 | + USER_ID: result[1][1] != null ? result[1][1] : "" | ||
| 75 | + }); | ||
| 76 | + }); | ||
| 77 | + } | ||
| 78 | + | ||
| 55 | getListData() { | 79 | getListData() { |
| 56 | let that = this; | 80 | let that = this; |
| 57 | return fetch(`https://devpay.brae.co/test/insurance/topic`, { | 81 | return fetch(`https://devpay.brae.co/test/insurance/topic`, { |
| @@ -81,6 +105,32 @@ export default class Home extends Component { | @@ -81,6 +105,32 @@ export default class Home extends Component { | ||
| 81 | } | 105 | } |
| 82 | 106 | ||
| 83 | submit() { | 107 | submit() { |
| 108 | + if (this.state.IS_LOGIN != "yes") { | ||
| 109 | + Alert.alert("请先登录账号"); | ||
| 110 | + } else { | ||
| 111 | + post( | ||
| 112 | + `/test/insurance/advice`, | ||
| 113 | + { | ||
| 114 | + userid: this.state.USER_ID, | ||
| 115 | + result: {} | ||
| 116 | + }, | ||
| 117 | + res => { | ||
| 118 | + Alert.alert("保存成功", null, () => { | ||
| 119 | + this.props.navigation.dispatch( | ||
| 120 | + NavigationActions.reset({ | ||
| 121 | + index: 0, | ||
| 122 | + actions: [ | ||
| 123 | + NavigationActions.navigate({ | ||
| 124 | + routeName: "MainTabBar" | ||
| 125 | + }) | ||
| 126 | + ] | ||
| 127 | + }) | ||
| 128 | + ); | ||
| 129 | + }); | ||
| 130 | + }, | ||
| 131 | + err => {} | ||
| 132 | + ); | ||
| 133 | + } | ||
| 84 | this.props.navigation.dispatch(NavigationActions.reset({ | 134 | this.props.navigation.dispatch(NavigationActions.reset({ |
| 85 | index: 0, | 135 | index: 0, |
| 86 | actions: [ | 136 | actions: [ |
| @@ -91,6 +141,7 @@ export default class Home extends Component { | @@ -91,6 +141,7 @@ export default class Home extends Component { | ||
| 91 | })) | 141 | })) |
| 92 | } | 142 | } |
| 93 | 143 | ||
| 144 | + | ||
| 94 | render() { | 145 | render() { |
| 95 | console.log("solution", this.props.navigation); | 146 | console.log("solution", this.props.navigation); |
| 96 | const { navigate } = this.props.navigation; | 147 | const { navigate } = this.props.navigation; |
| @@ -217,7 +268,16 @@ export default class Home extends Component { | @@ -217,7 +268,16 @@ export default class Home extends Component { | ||
| 217 | }} | 268 | }} |
| 218 | style={styles.confirmBtn} | 269 | style={styles.confirmBtn} |
| 219 | > | 270 | > |
| 220 | - <Text style={styles.confirmBtnText}>完成</Text> | 271 | + <Text style={styles.confirmBtnText}>返回</Text> |
| 272 | + </TouchableOpacity> | ||
| 273 | + <TouchableOpacity | ||
| 274 | + onPress={() => { | ||
| 275 | + {/* this.testAgain(); */} | ||
| 276 | + navigate("AIQuestion") | ||
| 277 | + }} | ||
| 278 | + style={styles.testAgainBtn} | ||
| 279 | + > | ||
| 280 | + <Text style={styles.testAgainText}>再测一次</Text> | ||
| 221 | </TouchableOpacity> | 281 | </TouchableOpacity> |
| 222 | </View> | 282 | </View> |
| 223 | ); | 283 | ); |
| @@ -328,7 +388,7 @@ const styles = StyleSheet.create({ | @@ -328,7 +388,7 @@ const styles = StyleSheet.create({ | ||
| 328 | borderColor: "#ccc", | 388 | borderColor: "#ccc", |
| 329 | borderStyle: "solid", | 389 | borderStyle: "solid", |
| 330 | borderBottomWidth: 1, | 390 | borderBottomWidth: 1, |
| 331 | - borderRightWidth: 1, | 391 | + borderRightWidth: 1 |
| 332 | }, | 392 | }, |
| 333 | contentText: { | 393 | contentText: { |
| 334 | fontSize: 12, | 394 | fontSize: 12, |
| @@ -360,7 +420,8 @@ const styles = StyleSheet.create({ | @@ -360,7 +420,8 @@ const styles = StyleSheet.create({ | ||
| 360 | marginLeft: 5 | 420 | marginLeft: 5 |
| 361 | }, | 421 | }, |
| 362 | confirmBtn: { | 422 | confirmBtn: { |
| 363 | - marginVertical: 20, | 423 | + // marginVertical: 20, |
| 424 | + marginTop: 20, | ||
| 364 | marginHorizontal: 40, | 425 | marginHorizontal: 40, |
| 365 | justifyContent: "center", | 426 | justifyContent: "center", |
| 366 | alignItems: "center", | 427 | alignItems: "center", |
| @@ -372,4 +433,14 @@ const styles = StyleSheet.create({ | @@ -372,4 +433,14 @@ const styles = StyleSheet.create({ | ||
| 372 | fontSize: 16, | 433 | fontSize: 16, |
| 373 | color: "white" | 434 | color: "white" |
| 374 | }, | 435 | }, |
| 436 | + testAgainBtn: { | ||
| 437 | + marginHorizontal: 40, | ||
| 438 | + justifyContent: "center", | ||
| 439 | + alignItems: "center", | ||
| 440 | + height: 45, | ||
| 441 | + }, | ||
| 442 | + testAgainText: { | ||
| 443 | + fontSize: 14, | ||
| 444 | + color: "#1B9341" | ||
| 445 | + }, | ||
| 375 | }); | 446 | }); |
| @@ -9,16 +9,23 @@ import { | @@ -9,16 +9,23 @@ import { | ||
| 9 | ScrollView, | 9 | ScrollView, |
| 10 | FlatList, | 10 | FlatList, |
| 11 | ListView, | 11 | ListView, |
| 12 | - Dimensions | 12 | + Dimensions, |
| 13 | + Alert, | ||
| 14 | + AsyncStorage | ||
| 13 | } from "react-native"; | 15 | } from "react-native"; |
| 14 | import { StackNavigator, TabNavigator } from "react-navigation"; | 16 | import { StackNavigator, TabNavigator } from "react-navigation"; |
| 15 | import Swiper from "react-native-swiper"; | 17 | import Swiper from "react-native-swiper"; |
| 18 | +import post from "../../utils/fetch"; | ||
| 16 | 19 | ||
| 17 | export default class Home extends Component { | 20 | export default class Home extends Component { |
| 18 | constructor(props) { | 21 | constructor(props) { |
| 19 | super(props); | 22 | super(props); |
| 20 | this._swiper = this._swiper.bind(this); | 23 | this._swiper = this._swiper.bind(this); |
| 21 | this.state = { | 24 | this.state = { |
| 25 | + IS_LOGIN: "", | ||
| 26 | + USER_ID: "", | ||
| 27 | + result: null, | ||
| 28 | + tested: false, | ||
| 22 | ListData: [], | 29 | ListData: [], |
| 23 | swiperImgList: [ | 30 | swiperImgList: [ |
| 24 | { | 31 | { |
| @@ -32,10 +39,49 @@ export default class Home extends Component { | @@ -32,10 +39,49 @@ export default class Home extends Component { | ||
| 32 | } | 39 | } |
| 33 | componentWillMount() { | 40 | componentWillMount() { |
| 34 | this.getListData(); | 41 | this.getListData(); |
| 42 | + this.getAsyncStorage(); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + gotoAISolution() { | ||
| 46 | + const { navigate } = this.props.navigation; | ||
| 47 | + post( | ||
| 48 | + `/test/insurance/advice`, | ||
| 49 | + { | ||
| 50 | + userid: this.state.USER_ID | ||
| 51 | + }, | ||
| 52 | + res => { | ||
| 53 | + console.log('智能方案答案',res); | ||
| 54 | + this.setState({ | ||
| 55 | + tested: res.data.tested, | ||
| 56 | + result: res.data.tested ? res.data.result : null | ||
| 57 | + }); | ||
| 58 | + }, | ||
| 59 | + err => { | ||
| 60 | + console.log(err); | ||
| 61 | + } | ||
| 62 | + ); | ||
| 35 | } | 63 | } |
| 36 | 64 | ||
| 37 | componentDidMount() {} | 65 | componentDidMount() {} |
| 38 | 66 | ||
| 67 | + getAsyncStorage() { | ||
| 68 | + const that = this; | ||
| 69 | + AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { | ||
| 70 | + if (err) { | ||
| 71 | + console.error(err); | ||
| 72 | + } | ||
| 73 | + that.setState( | ||
| 74 | + { | ||
| 75 | + IS_LOGIN: result[0][1], | ||
| 76 | + USER_ID: result[1][1] != null ? result[1][1] : "" | ||
| 77 | + }, | ||
| 78 | + () => { | ||
| 79 | + this.gotoAISolution(); | ||
| 80 | + } | ||
| 81 | + ); | ||
| 82 | + }); | ||
| 83 | + } | ||
| 84 | + | ||
| 39 | getListData() { | 85 | getListData() { |
| 40 | let that = this; | 86 | let that = this; |
| 41 | return fetch(`https://devpay.brae.co/test/insurance/topic`, { | 87 | return fetch(`https://devpay.brae.co/test/insurance/topic`, { |
| @@ -163,10 +209,19 @@ export default class Home extends Component { | @@ -163,10 +209,19 @@ export default class Home extends Component { | ||
| 163 | <TouchableOpacity | 209 | <TouchableOpacity |
| 164 | style={styles.AHContainer} | 210 | style={styles.AHContainer} |
| 165 | onPress={() => { | 211 | onPress={() => { |
| 212 | + if (this.state.tested) { | ||
| 213 | + navigate("AISolution", { | ||
| 214 | + result: this.state.result | ||
| 215 | + }); | ||
| 216 | + } else { | ||
| 166 | navigate("AIBegin"); | 217 | navigate("AIBegin"); |
| 218 | + } | ||
| 167 | }} | 219 | }} |
| 168 | > | 220 | > |
| 169 | - <Image style={styles.AHIcon} source={require("../../assets/home/ic_intellect.png")} /> | 221 | + <Image |
| 222 | + style={styles.AHIcon} | ||
| 223 | + source={require("../../assets/home/ic_intellect.png")} | ||
| 224 | + /> | ||
| 170 | <Text style={styles.AHText}>智能方案</Text> | 225 | <Text style={styles.AHText}>智能方案</Text> |
| 171 | </TouchableOpacity> | 226 | </TouchableOpacity> |
| 172 | <TouchableOpacity | 227 | <TouchableOpacity |
| @@ -175,7 +230,10 @@ export default class Home extends Component { | @@ -175,7 +230,10 @@ export default class Home extends Component { | ||
| 175 | navigate("HealthQuestionnaire"); | 230 | navigate("HealthQuestionnaire"); |
| 176 | }} | 231 | }} |
| 177 | > | 232 | > |
| 178 | - <Image style={styles.AHIcon} source={require("../../assets/home/ic_questionnaire.png")}/> | 233 | + <Image |
| 234 | + style={styles.AHIcon} | ||
| 235 | + source={require("../../assets/home/ic_questionnaire.png")} | ||
| 236 | + /> | ||
| 179 | <Text style={styles.AHText}>健康问卷</Text> | 237 | <Text style={styles.AHText}>健康问卷</Text> |
| 180 | </TouchableOpacity> | 238 | </TouchableOpacity> |
| 181 | </View> | 239 | </View> |
| @@ -263,22 +321,21 @@ const styles = StyleSheet.create({ | @@ -263,22 +321,21 @@ const styles = StyleSheet.create({ | ||
| 263 | marginTop: 10, | 321 | marginTop: 10, |
| 264 | backgroundColor: "white", | 322 | backgroundColor: "white", |
| 265 | paddingTop: 10, | 323 | paddingTop: 10, |
| 266 | - paddingBottom: 10, | 324 | + paddingBottom: 10 |
| 267 | }, | 325 | }, |
| 268 | AHContainer: { | 326 | AHContainer: { |
| 269 | flexDirection: "row", | 327 | flexDirection: "row", |
| 270 | justifyContent: "center", | 328 | justifyContent: "center", |
| 271 | - alignItems: "center", | 329 | + alignItems: "center" |
| 272 | - | ||
| 273 | }, | 330 | }, |
| 274 | AHIcon: { | 331 | AHIcon: { |
| 275 | width: 40, | 332 | width: 40, |
| 276 | - height: 40, | 333 | + height: 40 |
| 277 | }, | 334 | }, |
| 278 | AHText: { | 335 | AHText: { |
| 279 | fontSize: 16, | 336 | fontSize: 16, |
| 280 | color: "#242424", | 337 | color: "#242424", |
| 281 | - marginLeft: 13, | 338 | + marginLeft: 13 |
| 282 | }, | 339 | }, |
| 283 | textContainer: { | 340 | textContainer: { |
| 284 | backgroundColor: "#fff", | 341 | backgroundColor: "#fff", |
-
Please register or login to post a comment