import React, {Component} from 'react'; import { Image, Text, View, TouchableOpacity, DeviceEventEmitter, Alert, } from 'react-native'; import personal_center_page_css from './personal_center_page_css'; import public_css from '../../source/css/public_css'; import {RetrieveData, ClearAll} from '../../data/storage'; import Spinner from 'react-native-loading-spinner-overlay'; import loading_css from '../../source/css/loading_css'; import {GetDataPost, GetNetworkUrl} from '../../data/encryption'; export default class personal_center_page extends Component { constructor(props) { super(props); this.state = { user_name: '', user_type: '', spinner: false, user: '', }; } render() { return ( {this.state.user == '' || this.state.user == null ? ( ) : ( )} {this.state.user_name === '' ? ( this.props.navigation.navigate('login_head')}> 登录 ) : ( {this.state.user_name} )} this.getLandingStatus(1)} style={personal_center_page_css.textListStyle}> 个人信息 {this.state.user_name === '' ? ( ) : ( this.showAlert()}> 退出登录 )} {/**/} {/* this.getLandingStatus(2)}*/} {/* style={personal_center_page_css.textListStyle}>*/} {/* */} {/* 客户信息*/} {/* */} {/* */} {/**/} {/**/} {/* this.getLandingStatus(3)}*/} {/* style={personal_center_page_css.textListStyle}>*/} {/* */} {/* 企业信息*/} {/* */} {/* */} {/**/} ); } //页面加载获取信息 componentDidMount(): void { this.getSignIn(); } //获取登录信息 getSignIn = async () => { let user_name = await RetrieveData('userName'); let user_type = await RetrieveData('usertype'); let token = await RetrieveData('token'); let account = await RetrieveData('account'); if (user_name && user_type && token && account) { user_name = user_name.substring(1, user_name.length - 1); account = account.substring(1, account.length - 1); token = token.substring(1, token.length - 1); this.setState({ user_name: user_name, user_type: user_type, }); this.getUserInformation(account, token); } }; //获取用户信息 getUserInformation = async (account, token) => { const url = '/auth/comm/user/personalInfo/find'; let response = await GetDataPost( url, token, { mobile: account, }, false, 2, ); if (response) { this.setState({ user: response.data, }); } }; //退出登录 signOut = async () => { this.setLoadingStatus(true); await ClearAll(); this.setLoadingStatus(false); DeviceEventEmitter.emit('updateCurMon', null); this.props.navigation.navigate('home_navigation'); }; //显示loading层 setLoadingStatus(isLoading) { this.setState({ spinner: isLoading, }); } //判断是否登录 getLandingStatus = async type => { const account = await RetrieveData('account'); if (account) { if (type == 1) { this.props.navigation.navigate('personal_information', { user: this.state.user, }); } // if (type == 2) { // this.props.navigation.navigate('customer_information'); // } // if (type == 3) { // this.props.navigation.navigate('enterprise_list'); // } } else { this.props.navigation.navigate('login_head'); } }; //显示红冲确认信息 showAlert = () => { Alert.alert( '退出登录', '确定要退出登录吗!', [ { text: '取消', onPress: () => console.log('Cancel Pressed'), style: 'cancel', }, {text: '确定', onPress: () => this.signOut()}, ], {cancelable: false}, ); }; }