SchoolAge.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. file_user_data: new Map()
  28. };
  29. render() {
  30. return (
  31. <ImageBackground
  32. // source={{
  33. // uri:
  34. // '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'
  35. // }}
  36. style={{
  37. flex: 1,
  38. width: '100%',
  39. height: '100%',
  40. backgroundColor: 'white'
  41. }}
  42. >
  43. <StatusBar backgroundColor={'transparent'} translucent={true} barStyle={'dark-content'} />
  44. <View style={{ flex: 0.5 }} />
  45. <Text style={styles.title_text}>请选择孩子所在的学龄段</Text>
  46. <View style={{ flex: 0.1 }} />
  47. <View
  48. style={{
  49. flex: 5,
  50. flexDirection: 'column',
  51. justifyContent: 'center',
  52. alignItems: 'center'
  53. }}
  54. >
  55. <View style={styles.view_flex} />
  56. <TouchableOpacity activeOpacity={1} onPress={this.pres.bind(this)} style={styles.touchable_item}>
  57. <Image source={require('./images/schoolAge/preschool.png')} style={styles.image_item} />
  58. </TouchableOpacity>
  59. <View style={styles.view_flex} />
  60. <TouchableOpacity activeOpacity={1} onPress={this.primary.bind(this)} style={styles.touchable_item}>
  61. <Image source={require('./images/schoolAge/primary.png')} style={styles.image_item} />
  62. </TouchableOpacity>
  63. <View style={styles.view_flex} />
  64. <TouchableOpacity activeOpacity={1} onPress={this.middle.bind(this)} style={styles.touchable_item}>
  65. <Image source={require('./images/schoolAge/middle.png')} style={styles.image_item} />
  66. </TouchableOpacity>
  67. <View style={styles.view_flex} />
  68. </View>
  69. </ImageBackground>
  70. );
  71. }
  72. componentWillMount() {
  73. this.getUserInfo();
  74. }
  75. pres() {
  76. //PRESCHOOL("学前")
  77. this.updateUserInfo('PRESCHOOL');
  78. }
  79. primary() {
  80. // PRIMARY_SCHOOL("小学")
  81. this.updateUserInfo('PRIMARY_SCHOOL');
  82. }
  83. middle() {
  84. this.updateUserInfo('MIDDLE_SCHOOL');
  85. }
  86. async getUserInfo() {
  87. await global.storage
  88. .load({
  89. key: 'userInfo'
  90. })
  91. .then((result) => {
  92. this.state.file_user_data = commonutil.jsonToMap(result);
  93. })
  94. .catch((err) => {
  95. console.log('ERROR' + err.message);
  96. });
  97. }
  98. async updateUserInfo(group) {
  99. if (this.state.file_user_data.get('isVisitor')) {
  100. this.state.file_user_data.set('ageGroup', group);
  101. this.state.file_user_data.set('channel', this.state.file_user_data.get('channel'));
  102. this.state.file_user_data.set('gmtCreated', this.state.file_user_data.get('gmtCreated'));
  103. this.state.file_user_data.set('gmtModified', this.state.file_user_data.get('gmtModified'));
  104. this.state.file_user_data.set('birthday', '');
  105. this.state.file_user_data.set('city', '');
  106. this.state.file_user_data.set('country', '');
  107. this.state.file_user_data.set('eid', '');
  108. this.state.file_user_data.set('grade', '');
  109. this.state.file_user_data.set('mobile', '');
  110. this.state.file_user_data.set('nickName', '');
  111. this.state.file_user_data.set('province', '');
  112. this.state.file_user_data.set('school', '');
  113. this.state.file_user_data.set('sex', '');
  114. this.state.file_user_data.set('status', '');
  115. this.state.file_user_data.set('uid', '');
  116. this.saveUserInfo(commonutil.mapToJson(this.state.file_user_data));
  117. this.clearPageToNext('MainPage');
  118. return true;
  119. }
  120. let opts = {
  121. method: 'PUT', //请求方法
  122. body: { ageGroup: group } //请求体
  123. };
  124. await http_user.update_UserInfo(opts).then((res) => {
  125. this.state.file_user_data.set('ageGroup', res.data.ageGroup);
  126. this.state.file_user_data.set('avatar', res.data.avatar);
  127. this.state.file_user_data.set('birthday', res.data.birthday);
  128. this.state.file_user_data.set('channel', res.data.channel);
  129. this.state.file_user_data.set('city', res.data.city);
  130. this.state.file_user_data.set('country', res.data.country);
  131. this.state.file_user_data.set('eid', res.data.eid);
  132. this.state.file_user_data.set('gmtCreated', res.data.gmtCreated);
  133. this.state.file_user_data.set('gmtModified', res.data.gmtModified);
  134. this.state.file_user_data.set('mobile', res.data.mobile);
  135. this.state.file_user_data.set('nickName', res.data.nickName);
  136. this.state.file_user_data.set('province', res.data.province);
  137. this.state.file_user_data.set('school', res.data.school);
  138. this.state.file_user_data.set('sex', res.data.sex);
  139. this.state.file_user_data.set('status', res.data.status);
  140. this.state.file_user_data.set('uid', res.data.uid);
  141. this.saveUserInfo(commonutil.mapToJson(this.state.file_user_data));
  142. this.clearPageToNext('MainPage');
  143. });
  144. }
  145. }
  146. const styles = StyleSheet.create({
  147. title_text: {
  148. justifyContent: 'center',
  149. alignItems: 'center',
  150. color: 'black',
  151. fontSize: 20,
  152. fontWeight: '300',
  153. textAlign: 'center'
  154. },
  155. view_flex: { flex: 0.1 },
  156. touchable_item: {
  157. flex: 1,
  158. width: '90%',
  159. justifyContent: 'center',
  160. alignItems: 'center'
  161. },
  162. image_item: {
  163. width: '100%',
  164. height: '95%',
  165. resizeMode: 'contain'
  166. }
  167. });