/** * Profile Settings页面 * @邠心vbe on 2021/04/27 */ import React, { Component } from 'react'; import { View, StyleSheet, Image, ScrollView } from 'react-native'; import apiUser from '../../api/apiUser'; import { setAccessToken } from '../../api/http'; import Button, { ElevationObject } from '../../components/Button'; import Dialog from '../../components/Dialog'; import TextView from '../../components/TextView'; import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage'; import utils from '../../utils/utils'; import { PageList } from '../Router'; import app from '../../../app.json'; import { ShadowViewV2 } from '../../components/ShadowView'; export default class ProfileV2 extends Component { constructor(props) { super(props); this.state = { userInfo: userInfo, refreshId: 0, totalVehicle: 0 }; } componentDidMount() { this.init(); this.props.navigation.addListener('focus', () => { this.init(); }); } init() { getUserInfo(info => { this.setState({ userInfo: info, refreshId: this.state.refreshId + 1 }); }, true); } deleteAccount() { utils.logEventTracking("user_action: delete_account") Dialog.showDialog({ title: $t('profile.deleteAccount'), message: $t('profile.confirmDeleteAccount'), ok: $t('nav.confirm'), callback: button => { if (button == Dialog.BUTTON_OK) { this.deleteMyAccount(); } } }) } deleteMyAccount(again=false) { Dialog.showProgressDialog(); apiUser.deleteAccount({ secondConfirm: again }).then(res => { toastShort($t('profile.deleteAccountSuccess')) Dialog.dismissLoading(); this.requestLogout(); /*setTimeout(() => { startPage(PageList.login); }, 500);*/ }).catch(err => { Dialog.dismissLoading(); //toastShort(err) setTimeout(() => { if (err.code == 5334 || err.code == 5368) { Dialog.showDialog({ title: $t('profile.deleteAccount'), message: err.msg, ok: $t("nav.confirm"), callback: button => { if (button == Dialog.BUTTON_OK) { setTimeout(() => { this.deleteMyAccount(true); }, 500) } } }) } else { Dialog.showResultDialog(err.msg); } }, 500); }) } logout() { utils.logEventTracking("user_action: logout") Dialog.showDialog({ title: $t('profile.signOut'), message: $t('profile.tipSignOut'), callback: btn => { if (btn == Dialog.BUTTON_OK) { Dialog.showProgressDialog(); setTimeout(() => { this.requestLogout(); }, 500); } } }) } async requestLogout() { const data = await getStorageJsonSync('loginData'); if (data && data.email) { delete data.password setStorageJson('loginData', data); setStorage('RegisterTokenDate', ""); } global.userInfo = {} /*this.setState({ isLogin: false, userInfo: {} });*/ setAccessToken(''); goBack(); Dialog.dismissLoading(); } render() { return ( {/* Profile Info */} {/* Wallet Info */} {/* app.v4.wallet ? : */} { (utils.isNotEmpty(this.state.userInfo.groupWallet) && !app.v4.wallet) && <> } {/* Vehicle Info */} { app.vehicle.enable && <> } {/* Vehicle List */} {/* {$t('profile.myVehicles')} */} {/* { this.setState({ totalVehicle: count }) }} onDelete={id => this.removeVehicle(id)} /> */} {/* Account List */} {/* My Cards */} {/* */} {/* Notifications */} { !app.v3.drawer && <> } { (app.modules.apply_phv && this.state.userInfo.userType.toLowerCase() == "public") && <> } { app.v3.drawer && <> } {/*