SchoolAge.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Component } from 'react';
  9. import {
  10. Platform,
  11. StyleSheet,
  12. Text,
  13. View,
  14. Image,
  15. TouchableOpacity,
  16. StatusBar,
  17. ImageBackground,
  18. Button,
  19. DeviceEventEmitter
  20. } from 'react-native';
  21. import BasePage from './BasePage';
  22. import commonutil from './utils/commonutil';
  23. import http_user from './services/user';
  24. type Props = {};
  25. export default class SchoolAge extends BasePage {
  26. state = {};
  27. render() {
  28. return (
  29. <ImageBackground
  30. // source={{
  31. // uri:
  32. // 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg'
  33. // }}
  34. style={{
  35. flex: 1,
  36. width: '100%',
  37. height: '100%',
  38. backgroundColor: 'white'
  39. }}
  40. >
  41. <StatusBar backgroundColor={'transparent'} translucent={true} barStyle={'dark-content'} />
  42. <View style={{ flex: 0.5 }} />
  43. <Text style={styles.title_text}>请选择孩子所在的学龄段</Text>
  44. <View style={{ flex: 0.1 }} />
  45. <View
  46. style={{
  47. flex: 5,
  48. flexDirection: 'column',
  49. justifyContent: 'center',
  50. alignItems: 'center'
  51. }}
  52. >
  53. <View style={styles.view_flex} />
  54. <TouchableOpacity activeOpacity={1} onPress={this.pres.bind(this)} style={styles.touchable_item}>
  55. <Image source={require('./images/schoolAge/preschool.png')} style={styles.image_item} />
  56. </TouchableOpacity>
  57. <View style={styles.view_flex} />
  58. <TouchableOpacity activeOpacity={1} onPress={this.primary.bind(this)} style={styles.touchable_item}>
  59. <Image source={require('./images/schoolAge/primary.png')} style={styles.image_item} />
  60. </TouchableOpacity>
  61. <View style={styles.view_flex} />
  62. <TouchableOpacity activeOpacity={1} onPress={this.middle.bind(this)} style={styles.touchable_item}>
  63. <Image source={require('./images/schoolAge/middle.png')} style={styles.image_item} />
  64. </TouchableOpacity>
  65. <View style={styles.view_flex} />
  66. </View>
  67. </ImageBackground>
  68. );
  69. }
  70. componentWillMount() {}
  71. pres() {
  72. //PRESCHOOL("学前")
  73. this.updateUserInfo('PRESCHOOL');
  74. }
  75. primary() {
  76. // PRIMARY_SCHOOL("小学")
  77. this.updateUserInfo('PRIMARY_SCHOOL');
  78. }
  79. middle() {
  80. this.updateUserInfo('MIDDLE_SCHOOL');
  81. }
  82. async updateUserInfo(group) {
  83. if (global.userInfo.isVisitor) {
  84. console.log('游客登录');
  85. //是访客登录
  86. global.userInfo.ageGroup = group;
  87. this.clearPageToNext('MainPage');
  88. commonutil.saveUserInfo();
  89. return true;
  90. } else {
  91. console.log('正常登录');
  92. let opts = {
  93. method: 'PUT', //请求方法
  94. body: { ageGroup: group } //请求体
  95. };
  96. await http_user.update_UserInfo(opts).then((res) => {
  97. global.userInfo.ageGroup = group;
  98. commonutil.saveUserInfo();
  99. this.clearPageToNext('MainPage');
  100. });
  101. }
  102. }
  103. }
  104. const styles = StyleSheet.create({
  105. title_text: {
  106. justifyContent: 'center',
  107. alignItems: 'center',
  108. color: 'black',
  109. fontSize: 20,
  110. fontWeight: '300',
  111. textAlign: 'center'
  112. },
  113. view_flex: { flex: 0.1 },
  114. touchable_item: {
  115. flex: 1,
  116. width: '90%',
  117. justifyContent: 'center',
  118. alignItems: 'center'
  119. },
  120. image_item: {
  121. width: '100%',
  122. height: '95%',
  123. resizeMode: 'contain'
  124. }
  125. });