| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- /**
- * V3版本Profile页面
- * @邠心vbe on 2024/05/30
- */
- import React, { Component } from 'react';
- import { View, StyleSheet, Image, ScrollView, StatusBar, Pressable } from 'react-native';
- import Button, { ElevationObject } from '../../components/Button';
- import TextView from '../../components/TextView';
- import Dialog from '../../components/Dialog';
- import apiUser from '../../api/apiUser';
- import { setAccessToken } from '../../api/http';
- import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
- import utils from '../../utils/utils';
- import { PageList } from '../Router';
- import app from '../../../app.json';
- import Svg, { Defs, Ellipse, G, LinearGradient, Path, Rect, Stop } from 'react-native-svg';
- import ShadowView from '../../components/ShadowView';
- import MyStatusBar from '../../components/MyStatusBar';
- export default class ProfileV3 extends Component {
- constructor(props) {
- super(props);
- this.state = {
- isHide: false,
- userInfo: userInfo,
- totalVehicle: 0
- };
- }
- componentDidMount() {
- this.init();
- this.props.navigation.addListener('focus', () => {
- this.init();
- this.setState({
- isHide: false
- }, () => {
- setTimeout(() => {
- MyStatusBar.setStatusBarTheme(MyStatusBar.LIGHT_STYLE);
- }, 100);
- });
-
- });
- this.props.navigation.addListener('blur', () => {
- this.setState({
- isHide: true
- })
- MyStatusBar.setStatusBarTheme(MyStatusBar.DARK_STYLE);
- });
- }
- init() {
- getUserInfo(info => {
- this.setState({
- userInfo: info
- });
- }, true);
- }
- deleteAccount() {
- 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) {
- 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() {
- 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 (
- <ScrollView style={styles.container} stickyHeaderIndices={[0]}>
- {/* <StatusBar backgroundColor={this.state.isHide ? colorLight : colorPrimary} /> */}
- <View style={styles.headerView}>
- <Pressable
- style={styles.titleBar}
- onPress={() => goBack()}>
- <MaterialIcons
- name={'arrow-back-ios'}
- size={20}
- color={textLight} />
- <TextView style={styles.titleText}>Profile</TextView>
- </Pressable>
- <View style={styles.profileHeader}>
- {this.state.userInfo.photoUrl
- ? <Image
- style={styles.avatarImage}
- source={{ uri: utils.getImageUrl(this.state.userInfo.photoUrl) }} />
- : <Image
- style={styles.avatarImage}
- source={require('../../images/user/ic-avatar-default.png')} />
- }
- <View style={styles.infoContent}>
- <View style={ui.flexc}>
- <TextView
- style={styles.nickname}
- ellipsizeMode='tail'
- numberOfLines={1}>{this.state.userInfo.nickName}</TextView>
- <TextView
- style={styles.countryLabel}>Singapore</TextView>
- </View>
- <TextView style={styles.userText}>{this.state.userInfo.email}</TextView>
- <View style={ui.flex}>
- <Button
- text={"Edit"}
- textSize={12}
- textColor={colorPrimary}
- style={styles.editButton}
- viewStyle={styles.editButtonView}
- iconRight={
- <Feather
- name="edit-3"
- size={14}
- color={colorPrimary} />
- }
- onClick={() => startPage(PageList.editProfile)}
- />
- </View>
- </View>
- </View>
- </View>
- <View style={styles.circleButtomView}>
- <Svg width={$vw(100)} height={$vw(42.13)} viewBox="0 0 375 158" fill="none">
- <Ellipse cx={187.5} cy={79} rx={238.5} ry={79} fill={colorPrimary} />
- </Svg>
- </View>
- <Pressable
- style={styles.walletView}
- onPress={() => startPage(PageList.transaction)}>
- <Image
- style={styles.walletIcon}
- source={require("../../images/wallet/lumi-logo.png")}/>
- <View style={styles.walletContent}>
- <TextView style={styles.walletTitle}>Available Credits:</TextView>
- <TextView style={styles.walletAmount}>{this.state.userInfo?.creditStr}</TextView>
- </View>
- <Button
- text={"Buy"}
- textSize={12}
- textColor={textLight}
- style={styles.topupButton}
- viewStyle={styles.topupButtonView}
- iconRight={
- <MaterialIcons
- name="chevron-right"
- size={16}
- color={textLight} />
- }
- onClick={() => startPage(PageList.topupNew)}/>
- </Pressable>
- <ShadowView/>
- <Button
- style={styles.cardView}
- viewStyle={styles.cardItem}
- onClick={() => startPage(app.vehicle.newVersionPage ? PageList.vehiclesListV2 : PageList.myVehicles)}>
- {/* <Image
- style={styles.cardIcon}
- source={require('../../images/user/card-vehicle.png')}/> */}
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{$t('profile.myVehicles')}</TextView>
- {/* <TextView style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</TextView> */}
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.cardView}
- viewStyle={styles.cardItem}
- onClick={() => {}}>
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{"Saved Cards"}</TextView>
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.cardView}
- viewStyle={styles.cardItem}
- onClick={() => startPage(PageList.settings)}>
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{"App Settings"}</TextView>
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.cardView}
- viewStyle={styles.profileItem}
- onClick={() => startPage(PageList.changePassword, {action: "change"})}>
- {/* <Image
- style={styles.cardIcon}
- source={require('../../images/user/card-account.png')}/> */}
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{$t('route.changePassword')}</TextView>
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.cardView}
- viewStyle={styles.profileItem}
- onClick={() => startPage(PageList.feedback)}>
- {/* <MaterialCommunityIcons
- style={styles.cardIcon}
- name="message-alert-outline"
- color="#00638C"
- size={32}
- /> */}
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{$t('drawer.feedback')}</TextView>
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.cardView}
- viewStyle={styles.cardItem}
- onClick={() => {}}>
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{"Contact Us"}</TextView>
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.cardView}
- viewStyle={styles.profileItem}
- onClick={() => startPage(PageList.about)}>
- {/* <MaterialCommunityIcons
- style={styles.cardIcon}
- name="information-outline"
- color="#00638C"
- size={32}
- /> */}
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{$t('drawer.about')}</TextView>
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.cardView}
- viewStyle={styles.cardItem}
- onClick={() => startPage(PageList.profile)}>
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{"Check For Updates"}</TextView>
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.cardView}
- viewStyle={styles.profileItem}
- onClick={() => this.deleteAccount()}>
- {/* <MaterialCommunityIcons
- style={styles.cardIcon}
- name="account-remove"
- size={32}
- color="#00638C"/> */}
- <View style={styles.cardInfo}>
- <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
- </View>
- <FontAwesome
- size={24}
- color={textPrimary}
- name='angle-right'/>
- </Button>
- {/* <ShadowView/> */}
- <Button
- style={styles.deleteButton}
- text={'LOGOUT'}
- textColor={textLight}
- onClick={() => this.logout()}
- />
- <ShadowView/>
- <EndView/><EndView/>
- </ScrollView>
- );
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: pageBackground
- },
- headerView: {
- zIndex: 2,
- paddingTop: statusHeight,
- backgroundColor: colorPrimary
- },
- titleBar: {
- padding: 16,
- alignItems: 'center',
- flexDirection: 'row'
- },
- titleText: {
- color: textLight,
- fontSize: 20,
- fontWeight: 'bold'
- },
- profileHeader: {
- padding: 16,
- alignItems: 'center',
- flexDirection: 'row'
- },
- avatarImage: {
- width: 80,
- height: 80,
- borderWidth: 2,
- borderRadius: 80,
- borderColor: colorLight,
- backgroundColor: colorLight
- },
- infoContent: {
- flex: 1,
- paddingLeft: 16
- },
- nickname: {
- color: textLight,
- fontSize: 20,
- fontWeight: 'bold',
- paddingTop: 1,
- paddingBottom: 1
- },
- userText: {
- color: textLight,
- fontSize: 13,
- paddingTop: 4
- },
- countryLabel: {
- color: textLight,
- fontSize: 10,
- ...$padding(2, 8),
- marginLeft: 8,
- borderRadius: 4,
- backgroundColor: "#f8a300"
- },
- editButton: {
- marginTop: 8,
- borderRadius: 4,
- backgroundColor: colorLight
- },
- editButtonView: {
- width: 65,
- ...$padding(4, 10),
- alignItems: 'center',
- flexDirection: 'row'
- },
- circleButtomView: {
- zIndex: 1,
- marginTop: -$vw(30)
- },
- walletView: {
- zIndex: 2,
- padding: 12,
- paddingRight: 6,
- marginTop: -$vw(12),
- marginLeft: 16,
- marginRight: 16,
- borderWidth: 2,
- borderColor: colorPrimary,
- borderRadius: 6,
- alignItems: "center",
- flexDirection: "row",
- backgroundColor: colorLight,
- },
- walletIcon: {
- width: 48,
- height: 48
- },
- walletContent: {
- flex: 1,
- paddingLeft: 8
- },
- walletTitle: {
- color: textPrimary,
- fontSize: 14,
- paddingTop: 3
- },
- walletAmount: {
- color: colorPrimary,
- fontSize: 20,
- fontWeight: "bold",
- paddingTop: 2
- },
- topupButton: {
- marginTop: 8,
- borderRadius: 4,
- backgroundColor: colorPrimary
- },
- topupButtonView: {
- width: 65,
- alignItems: 'center',
- flexDirection: 'row',
- ...$padding(4, 8, 4, 10)
- },
- cardView: {
- zIndex: 2,
- //padding: 16,
- marginTop: 8,
- marginLeft: 16,
- marginRight: 16,
- borderRadius: 10,
- overflow: 'hidden',
- alignItems: 'center',
- flexDirection: 'row',
- borderWidth: 1,
- borderColor: "#DADADA",
- //...ElevationObject(2),
- backgroundColor: colorLight
- },
- cardItem: {
- padding: 16,
- alignItems: 'center',
- flexDirection: 'row',
- justifyContent: 'center',
- },
- cardIcon: {
- width: 32,
- height: 32
- },
- cardInfo: {
- flex: 1,
- //paddingLeft: 16,
- alignItems: 'center',
- flexDirection: 'row'
- },
- cardLabel: {
- color: textPrimary,
- fontSize: 12
- },
- deleteButton: {
- zIndex: 2,
- borderRadius: 4,
- backgroundColor: '#EA0A2A',
- ...$margin(16, 16, 0)
- }
- })
|