personal_center_page.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 loading_css from '../../source/css/loading_css';
  14. import {GetDataPost} from '../../data/encryption';
  15. import Spinner from 'react-native-loading-spinner-overlay';
  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={{flexDirection: 'row', backgroundColor: '#ffffff'}}>
  35. {this.state.user == '' || this.state.user == null ? (
  36. <Image
  37. source={require('../../source/img/personal/headImg.png')}
  38. style={[personal_center_page_css.headImg]}
  39. />
  40. ) : (
  41. <Image
  42. source={{
  43. uri: 'https://app.taxbk.cn:9443' + this.state.user.avatar,
  44. }}
  45. style={[personal_center_page_css.headImg]}
  46. />
  47. )}
  48. {this.state.user_name === '' ? (
  49. <View style={[personal_center_page_css.headStyle]}>
  50. <TouchableOpacity
  51. onPress={() => this.props.navigation.navigate('login_head')}>
  52. <Text>登陆</Text>
  53. </TouchableOpacity>
  54. </View>
  55. ) : (
  56. <View style={[personal_center_page_css.headStyle]}>
  57. <Text style={{fontSize: 18}}>{this.state.user_name}</Text>
  58. </View>
  59. )}
  60. </View>
  61. <View>
  62. <TouchableOpacity
  63. onPress={() => this.getLandingStatus(1)}
  64. style={personal_center_page_css.textListStyle}>
  65. <Text style={personal_center_page_css.textListFontStyle}>
  66. 修改手机号
  67. </Text>
  68. </TouchableOpacity>
  69. </View>
  70. <View>
  71. <TouchableOpacity
  72. onPress={() => this.getLandingStatus(1)}
  73. style={personal_center_page_css.textListStyle}>
  74. <Text style={personal_center_page_css.textListFontStyle}>
  75. 联系客服
  76. </Text>
  77. </TouchableOpacity>
  78. </View>
  79. {this.state.user_name === '' ? (
  80. <View />
  81. ) : (
  82. <View style={public_css.buttonView}>
  83. <TouchableOpacity
  84. style={public_css.button}
  85. onPress={() => this.showAlert()}>
  86. <Text style={public_css.buttonText}>退出登录</Text>
  87. </TouchableOpacity>
  88. </View>
  89. )}
  90. </View>
  91. );
  92. }
  93. //页面加载获取信息
  94. componentDidMount(): void {
  95. this.getSignIn();
  96. }
  97. //获取登陆信息
  98. getSignIn = async () => {
  99. let user_name = await RetrieveData('userName');
  100. let user_type = await RetrieveData('usertype');
  101. let token = await RetrieveData('token');
  102. let account = await RetrieveData('account');
  103. if (user_name && user_type && token && account) {
  104. user_name = user_name.substring(1, user_name.length - 1);
  105. account = account.substring(1, account.length - 1);
  106. token = token.substring(1, token.length - 1);
  107. this.setState({
  108. user_name: user_name,
  109. user_type: user_type,
  110. });
  111. this.getUserInformation(account, token);
  112. }
  113. };
  114. //获取用户信息
  115. getUserInformation = async (account, token) => {
  116. const url = 'https://app.taxbk.cn:9443/auth/comm/user/personalInfo/find';
  117. let response = await GetDataPost(
  118. url,
  119. token,
  120. {
  121. mobile: account,
  122. },
  123. false,
  124. 2,
  125. );
  126. if (response) {
  127. this.setState({
  128. user: response.data,
  129. });
  130. }
  131. };
  132. //退出登陆
  133. signOut = async () => {
  134. this.setLoadingStatus(true);
  135. await ClearAll();
  136. this.setLoadingStatus(false);
  137. // DeviceEventEmitter.emit('updateCurMon', null);
  138. this.props.navigation.navigate('home_navigation');
  139. };
  140. //显示loading层
  141. setLoadingStatus(isLoading) {
  142. this.setState({
  143. spinner: isLoading,
  144. });
  145. }
  146. //判断是否登陆
  147. getLandingStatus = async (type) => {
  148. const account = await RetrieveData('account');
  149. if (account) {
  150. if (type == 1) {
  151. this.props.navigation.navigate('personal_information', {
  152. user: this.state.user,
  153. });
  154. }
  155. // if (type == 2) {
  156. // this.props.navigation.navigate('customer_information');
  157. // }
  158. // if (type == 3) {
  159. // this.props.navigation.navigate('enterprise_list');
  160. // }
  161. } else {
  162. this.props.navigation.navigate('login_head');
  163. }
  164. };
  165. //显示红冲确认信息
  166. showAlert = () => {
  167. Alert.alert(
  168. '退出登陆',
  169. '确定要退出登陆吗!',
  170. [
  171. {
  172. text: '取消',
  173. onPress: () => console.log('Cancel Pressed'),
  174. style: 'cancel',
  175. },
  176. {text: '确定', onPress: () => this.signOut()},
  177. ],
  178. {cancelable: false},
  179. );
  180. };
  181. }