personal_center_page.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import React, {Component} from 'react';
  2. import {
  3. Image,
  4. Text,
  5. View,
  6. TouchableOpacity,
  7. DeviceEventEmitter,
  8. Alert,
  9. } from 'react-native';
  10. import personal_center_page_css from './personal_center_page_css';
  11. import public_css from '../../source/css/public_css';
  12. import {RetrieveData, ClearAll} from '../../data/storage';
  13. import Spinner from 'react-native-loading-spinner-overlay';
  14. import loading_css from '../../source/css/loading_css';
  15. import {GetDataPost, GetNetworkUrl} from '../../data/encryption';
  16. export default class personal_center_page extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. user_name: '',
  21. user_type: '',
  22. spinner: false,
  23. user: '',
  24. };
  25. }
  26. render() {
  27. return (
  28. <View style={{flex: 1}}>
  29. <Spinner
  30. visible={this.state.spinner}
  31. textContent={'Loading...'}
  32. textStyle={loading_css.spinnerTextStyle}
  33. />
  34. <View style={{backgroundColor: '#ffffff', flex: 1}}>
  35. <View
  36. style={{
  37. height: 200,
  38. backgroundColor: '#0A81CF',
  39. position: 'relative',
  40. borderBottomLeftRadius: 600,
  41. borderBottomRightRadius: 600,
  42. alignItems: 'center',
  43. }}>
  44. <Image
  45. source={require('../../source/img/personal/head.png')}
  46. style={{height: 200, width: 200}}
  47. />
  48. </View>
  49. <View
  50. style={{
  51. alignItems: 'center',
  52. top: -70,
  53. zIndex: 100,
  54. }}>
  55. {this.state.user == '' || this.state.user == null ? (
  56. <Image
  57. source={require('../../source/img/personal/headImg.png')}
  58. style={[
  59. personal_center_page_css.headImg,
  60. {position: 'absolute'},
  61. ]}
  62. />
  63. ) : (
  64. <Image
  65. source={{
  66. uri: GetNetworkUrl() + this.state.user.avatar,
  67. }}
  68. style={[
  69. personal_center_page_css.headImg,
  70. {position: 'absolute'},
  71. ]}
  72. />
  73. )}
  74. </View>
  75. {this.state.user_name === '' ? (
  76. <View style={[personal_center_page_css.headStyle]}>
  77. <TouchableOpacity
  78. onPress={() => this.props.navigation.navigate('login_head')}>
  79. <Text>登录</Text>
  80. </TouchableOpacity>
  81. </View>
  82. ) : (
  83. <View style={[personal_center_page_css.headStyle]}>
  84. <Text style={{fontSize: 18}}>{this.state.user_name}</Text>
  85. </View>
  86. )}
  87. </View>
  88. <View style={{flex: 1}}>
  89. <View>
  90. <TouchableOpacity
  91. onPress={() => this.getLandingStatus(1)}
  92. style={personal_center_page_css.textListStyle}>
  93. <Text style={personal_center_page_css.textListFontStyle}>
  94. 个人信息
  95. </Text>
  96. </TouchableOpacity>
  97. </View>
  98. {this.state.user_name === '' ? (
  99. <View />
  100. ) : (
  101. <View style={public_css.buttonView}>
  102. <TouchableOpacity
  103. style={public_css.button}
  104. onPress={() => this.showAlert()}>
  105. <Text style={public_css.buttonText}>退出登录</Text>
  106. </TouchableOpacity>
  107. </View>
  108. )}
  109. </View>
  110. {/*<View>*/}
  111. {/* <TouchableOpacity*/}
  112. {/* onPress={() => this.getLandingStatus(2)}*/}
  113. {/* style={personal_center_page_css.textListStyle}>*/}
  114. {/* <Text style={personal_center_page_css.textListFontStyle}>*/}
  115. {/* 客户信息*/}
  116. {/* </Text>*/}
  117. {/* </TouchableOpacity>*/}
  118. {/*</View>*/}
  119. {/*<View>*/}
  120. {/* <TouchableOpacity*/}
  121. {/* onPress={() => this.getLandingStatus(3)}*/}
  122. {/* style={personal_center_page_css.textListStyle}>*/}
  123. {/* <Text style={personal_center_page_css.textListFontStyle}>*/}
  124. {/* 企业信息*/}
  125. {/* </Text>*/}
  126. {/* </TouchableOpacity>*/}
  127. {/*</View>*/}
  128. </View>
  129. );
  130. }
  131. //页面加载获取信息
  132. componentDidMount(): void {
  133. this.getSignIn();
  134. }
  135. //获取登录信息
  136. getSignIn = async () => {
  137. let user_name = await RetrieveData('userName');
  138. let user_type = await RetrieveData('usertype');
  139. let token = await RetrieveData('token');
  140. let account = await RetrieveData('account');
  141. if (user_name && user_type && token && account) {
  142. user_name = user_name.substring(1, user_name.length - 1);
  143. account = account.substring(1, account.length - 1);
  144. token = token.substring(1, token.length - 1);
  145. this.setState({
  146. user_name: user_name,
  147. user_type: user_type,
  148. });
  149. this.getUserInformation(account, token);
  150. }
  151. };
  152. //获取用户信息
  153. getUserInformation = async (account, token) => {
  154. const url = '/auth/comm/user/personalInfo/find';
  155. let response = await GetDataPost(
  156. url,
  157. token,
  158. {
  159. mobile: account,
  160. },
  161. false,
  162. 2,
  163. );
  164. if (response) {
  165. this.setState({
  166. user: response.data,
  167. });
  168. }
  169. };
  170. //退出登录
  171. signOut = async () => {
  172. this.setLoadingStatus(true);
  173. await ClearAll();
  174. this.setLoadingStatus(false);
  175. DeviceEventEmitter.emit('updateCurMon', null);
  176. this.props.navigation.navigate('home_navigation');
  177. };
  178. //显示loading层
  179. setLoadingStatus(isLoading) {
  180. this.setState({
  181. spinner: isLoading,
  182. });
  183. }
  184. //判断是否登录
  185. getLandingStatus = async type => {
  186. const account = await RetrieveData('account');
  187. if (account) {
  188. if (type == 1) {
  189. this.props.navigation.navigate('personal_information', {
  190. user: this.state.user,
  191. });
  192. }
  193. // if (type == 2) {
  194. // this.props.navigation.navigate('customer_information');
  195. // }
  196. // if (type == 3) {
  197. // this.props.navigation.navigate('enterprise_list');
  198. // }
  199. } else {
  200. this.props.navigation.navigate('login_head');
  201. }
  202. };
  203. //显示红冲确认信息
  204. showAlert = () => {
  205. Alert.alert(
  206. '退出登录',
  207. '确定要退出登录吗!',
  208. [
  209. {
  210. text: '取消',
  211. onPress: () => console.log('Cancel Pressed'),
  212. style: 'cancel',
  213. },
  214. {text: '确定', onPress: () => this.signOut()},
  215. ],
  216. {cancelable: false},
  217. );
  218. };
  219. }