/** * Profile Settings页面 * @邠心vbe on 2021/04/27 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, Image, ScrollView, Switch, Pressable } from 'react-native'; import apiUser from '../../api/apiUser'; import { host } from '../../api/http'; import Button, { ElevationObject } from '../../components/Button'; import Dialog from '../../components/Dialog'; import { StationBack } from '../../components/Toolbar'; import ProfileBackground from '../../icons/ProfileBackground'; import TopChargeBackground from '../../icons/TopChargeBackground'; import utils from '../../utils/utils'; import { PageList } from '../Router'; import VehicleList from './VehicleList'; export default class Profile extends Component { constructor(props) { super(props); this.state = { userInfo: { notifyLowBalance: true, notifyChargingComplete: true, notifyPromotionsOffers: true }, refreshId: 0, totalVehicle: 0 }; this.changed = false; } componentDidMount() { this.props.navigation.addListener('focus', () => { getUserInfo(info => { this.setState({ userInfo: info, refreshId: this.state.refreshId + 1 }); }, true); }); } componentWillUnmount() { if (this.changed) { this.setChangedSwitch(); } } removeVehicle(id) { Dialog.showDialog({ title: 'Remove Vehicle', message: 'Are you sure you want to remove this vehicle?', callback: btn => { if (btn == 'ok') { Dialog.dismissLoading(); this.deleteVehicle(id); } } }) } deleteVehicle(id) { Dialog.showProgressDialog(); apiUser.deleteVehicle({ vehiclePk: id }).then(res => { Dialog.dismissLoading(); toastShort('Delete successfully'); this.setState({ refreshId: this.state.refreshId + 1 }) }).catch(err => { Dialog.dismissLoading(); toastShort(err); }); } changeSwitch(key, value) { userInfo[key] = value; this.setState({ userInfo: userInfo }); this.changed = true; } setChangedSwitch() { apiUser.setNotifySwitch(userInfo); } deleteAccount() { Dialog.showDialog({ title: 'Delete My Account', message: 'Are you sure you want to delete your account? This operation cannot be revoke.', ok: 'CONFIRM', callback: button => { if (button == Dialog.BUTTON_OK) { this.deleteMyAccount(); } } }) } deleteMyAccount() { Dialog.showProgressDialog(); apiUser.deleteAccount().then(res => { toastShort('Successfully deleted!') Dialog.dismissLoading(); setTimeout(() => { startPage(PageList.login); }, 500); }).catch(err => { Dialog.dismissLoading(); toastShort(err) }) } render() { return ( {/* Profile Info */} {/* */} {/* */} { startPage(PageList.editProfile); }}> { userInfo.photoUrl ? : } {userInfo.nickName} {userInfo.email} {(utils.isNotEmpty(userInfo.callingCode) && "+" + userInfo.callingCode) + userInfo.phone} {/* Summary Info */} {this.state.totalVehicle} My Vehicles { startPage(PageList.wallet); }}> {currency}{userInfo.credit} Credit Wallet {/* Vehicle List */} My Vehicles { this.setState({ totalVehicle: count }) }} onDelete={id => this.removeVehicle(id)} /> {/* Account List */} {/* My Cards */} {/* Notifications */} Notifications { this.changeSwitch("notifyChargingComplete", !userInfo.notifyChargingComplete); }}> Notify me when charging complete { this.changeSwitch("notifyChargingComplete", v); }}/> { this.changeSwitch("notifyLowBalance", !userInfo.notifyLowBalance); }}> Notify me when wallet is low balance { this.changeSwitch("notifyLowBalance", v); }}/> { this.changeSwitch("notifyPromotionsOffers", !userInfo.notifyPromotionsOffers); }}> Notify me for promotions and offers { this.changeSwitch("notifyPromotionsOffers", v); }}/>