/** * 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 { StationBack } from '../../components/Toolbar'; import utils from '../../utils/utils'; import { PageList } from '../Router'; import { CardList } from '../wallet/CardList'; 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); } 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); }}/> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'white' }, headerView: { paddingBottom: 72 }, background: { left: 0, bottom: 0, width: $vw(100), height: $vw(62.4), resizeMode: "cover", position: 'absolute' }, profileView: { padding: 16, zIndex: 10, alignItems: 'center', flexDirection: 'row' }, avatar: { width: 66, height: 66, borderWidth: 2, borderRadius: 80, borderColor: '#fff' }, infoContent: { flex: 1, paddingLeft: 16, }, nickname: { color: '#000', fontSize: 16, paddingTop: 1, paddingBottom: 1.5, }, userText: { color: '#333', fontSize: 13, paddingTop: 1.5 }, cardView: { padding: 16, marginTop: -56, marginLeft: 16, marginRight: 16, borderRadius: 10, ...ElevationObject(2), alignItems: 'center', flexDirection: 'row', backgroundColor: 'white', }, cardItem: { flex: 1, alignItems: 'center', flexDirection: 'row', justifyContent: 'center' }, cardDivide: { borderLeftWidth: 1, borderLeftColor: '#EEE' }, cardIcon: { width: 32, height: 32 }, cardInfo: { paddingLeft: 16, alignItems: 'center' }, cardPrimary: { color: '#333', fontSize: 18, paddingBottom: 2 }, cardLabel: { color: '#333', fontSize: 13, }, titleView: { padding: 12, alignItems: 'center', flexDirection: 'row' }, title: { flex: 1, padding: 8, color: '#000', fontSize: 16, }, titleAdd: { padding: 8, color: '#333', alignItems: 'center', flexDirection: 'row' }, verhicleList: { paddingLeft: 16, paddingRight: 16, marginBottom: -16 }, accountList: { paddingLeft: 16, paddingRight: 16, marginBottom: -16 }, notificationView: { marginLeft: 16, marginRight: 16, marginBottom: 20, borderRadius: 10, overflow: 'hidden', paddingLeft: 16, paddingRight: 16, borderColor: '#f5f5f5', borderWidth: 1, backgroundColor: 'white', ...ElevationObject(1.5) }, notificationItem: { paddingTop: 16, paddingBottom: 16, alignItems: 'center', flexDirection: 'row' }, notiLabel: { flex: 1, color: '#333', fontSize: 14 }, divide: { borderTopWidth: 1, borderTopColor: '#eee' } })