ProfileV2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /**
  2. * Profile Settings页面
  3. * @邠心vbe on 2021/04/27
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Image, ScrollView } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import { host, setAccessToken } from '../../api/http';
  9. import Button, { ElevationObject } from '../../components/Button';
  10. import Dialog from '../../components/Dialog';
  11. import TextView from '../../components/TextView';
  12. import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
  13. import utils from '../../utils/utils';
  14. import { PageList } from '../Router';
  15. import app from '../../../app.json';
  16. export default class ProfileV2 extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. userInfo: userInfo,
  21. refreshId: 0,
  22. totalVehicle: 0
  23. };
  24. }
  25. componentDidMount() {
  26. this.init();
  27. this.props.navigation.addListener('focus', () => {
  28. this.init();
  29. });
  30. }
  31. init() {
  32. getUserInfo(info => {
  33. this.setState({
  34. userInfo: info,
  35. refreshId: this.state.refreshId + 1
  36. });
  37. }, true);
  38. }
  39. deleteAccount() {
  40. Dialog.showDialog({
  41. title: $t('profile.deleteAccount'),
  42. message: $t('profile.confirmDeleteAccount'),
  43. ok: $t('nav.confirm'),
  44. callback: button => {
  45. if (button == Dialog.BUTTON_OK) {
  46. this.deleteMyAccount();
  47. }
  48. }
  49. })
  50. }
  51. deleteMyAccount() {
  52. Dialog.showProgressDialog();
  53. apiUser.deleteAccount().then(res => {
  54. toastShort($t('profile.deleteAccountSuccess'))
  55. Dialog.dismissLoading();
  56. this.requestLogout();
  57. /*setTimeout(() => {
  58. startPage(PageList.login);
  59. }, 500);*/
  60. }).catch(err => {
  61. Dialog.dismissLoading();
  62. toastShort(err)
  63. })
  64. }
  65. logout() {
  66. Dialog.showDialog({
  67. title: $t('profile.signOut'),
  68. message: $t('profile.tipSignOut'),
  69. callback: btn => {
  70. if (btn == Dialog.BUTTON_OK) {
  71. Dialog.showProgressDialog();
  72. setTimeout(() => {
  73. this.requestLogout();
  74. }, 500);
  75. }
  76. }
  77. })
  78. }
  79. async requestLogout() {
  80. const data = await getStorageJsonSync('loginData');
  81. if (data && data.email) {
  82. delete data.password
  83. setStorageJson('loginData', data);
  84. setStorage('RegisterTokenDate', "");
  85. }
  86. global.userInfo = {}
  87. /*this.setState({
  88. isLogin: false,
  89. userInfo: {}
  90. });*/
  91. setAccessToken('');
  92. goBack();
  93. Dialog.dismissLoading();
  94. }
  95. render() {
  96. return (
  97. <ScrollView style={styles.container}>
  98. {/* Profile Info */}
  99. <Button
  100. style={styles.cardView}
  101. viewStyle={styles.profileView}
  102. android_ripple={ripple}
  103. onClick={() => startPage(PageList.editProfile)}>
  104. { this.state.userInfo.photoUrl
  105. ? <Image
  106. style={styles.avatar}
  107. source={{uri: host + this.state.userInfo.photoUrl}}/>
  108. : <Image
  109. style={styles.avatar}
  110. source={require('../../images/user/ic-avatar-default.png')}/>
  111. }
  112. <View style={styles.infoContent}>
  113. <TextView
  114. style={styles.nickname}
  115. ellipsizeMode='tail'
  116. numberOfLines={1}>{this.state.userInfo.nickName}</TextView>
  117. <TextView style={styles.userText}>{this.state.userInfo.email}</TextView>
  118. <TextView style={styles.userText}>{(utils.isNotEmpty(this.state.userInfo.callingCode) && "+" + this.state.userInfo.callingCode + " ") + this.state.userInfo.phone}</TextView>
  119. </View>
  120. <FontAwesome
  121. size={34}
  122. color={textCancel}
  123. name='angle-right'/>
  124. </Button>
  125. {/* Wallet Info */}
  126. <Button
  127. style={styles.cardView}
  128. viewStyle={styles.profileItem}
  129. onClick={() => startPage(PageList.wallet)}>
  130. <Image
  131. style={styles.cardIcon}
  132. source={require('../../images/user/card-wallet.png')}/>
  133. <View style={styles.cardInfo}>
  134. <TextView style={styles.cardLabel}>{$t('wallet.creditWalletLabel')}</TextView>
  135. <TextView style={styles.cardPrimary}>{this.state.userInfo.creditStr}</TextView>
  136. </View>
  137. <FontAwesome
  138. size={28}
  139. color={textCancel}
  140. name='angle-right'/>
  141. </Button>
  142. {/* Vehicle Info */}
  143. <Button
  144. style={styles.cardView}
  145. viewStyle={styles.profileItem}
  146. onClick={() => startPage(PageList.myVehicles)}>
  147. <Image
  148. style={styles.cardIcon}
  149. source={require('../../images/user/card-vehicle.png')}/>
  150. <View style={styles.cardInfo}>
  151. <TextView style={styles.cardLabel}>{$t('profile.myVehicles')}</TextView>
  152. <TextView style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</TextView>
  153. </View>
  154. <FontAwesome
  155. size={28}
  156. color={textCancel}
  157. name='angle-right'/>
  158. </Button>
  159. {/* Vehicle List */}
  160. {/* <View style={styles.titleView}>
  161. <Text style={styles.title}>{$t('profile.myVehicles')}</Text>
  162. <Button
  163. style={{backgroundColor: colorLight}}
  164. borderRadius={3}
  165. viewStyle={styles.titleAdd}
  166. onClick={() => {
  167. startPage(PageList.addVehicle)
  168. }}>
  169. <Entypo name='plus' size={14} color={colorDark}/>
  170. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  171. </Button>
  172. </View> */}
  173. {/* <View style={styles.verhicleList}>
  174. <VehicleList
  175. refreshId={this.state.refreshId}
  176. onResult={count => {
  177. this.setState({
  178. totalVehicle: count
  179. })
  180. }}
  181. onDelete={id => this.removeVehicle(id)}
  182. />
  183. </View> */}
  184. {/* Account List */}
  185. {/* <View style={styles.titleView}>
  186. <Text style={styles.title}>My Cards</Text>
  187. <Button
  188. textColor={textPrimary}
  189. style={styles.titleAdd}
  190. onClick={() => {
  191. startPage(PageList.addCard)
  192. }}>
  193. <Entypo name='plus' size={14} color={colorDark}/>
  194. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  195. </Button>
  196. </View>
  197. <View style={styles.accountList}>
  198. <CardList refreshId={this.state.refreshId}/>
  199. </View> */}
  200. <Button
  201. style={styles.cardView}
  202. viewStyle={styles.profileItem}
  203. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  204. <Image
  205. style={styles.cardIcon}
  206. source={require('../../images/user/card-account.png')}/>
  207. <View style={styles.cardInfo}>
  208. <TextView style={styles.cardLabel}>{$t('route.changePassword')}</TextView>
  209. </View>
  210. <FontAwesome
  211. size={28}
  212. color={textCancel}
  213. name='angle-right'/>
  214. </Button>
  215. {/* Notifications */}
  216. <Button
  217. style={styles.cardView}
  218. viewStyle={styles.profileItem}
  219. onClick={() => startPage(PageList.settings)}>
  220. <Image
  221. style={styles.cardIcon}
  222. source={require('../../images/user/card-notification.png')}/>
  223. <View style={styles.cardInfo}>
  224. <TextView style={styles.cardLabel}>{$t('profile.notificationSettings')}</TextView>
  225. </View>
  226. <FontAwesome
  227. size={28}
  228. color={textCancel}
  229. name='angle-right'/>
  230. </Button>
  231. { (!app.modules.membership && this.state.userInfo.userType == "Public") &&
  232. <Button
  233. style={styles.cardView}
  234. viewStyle={styles.profileItem}
  235. onClick={() => startPage(PageList.registerFleet)}>
  236. <MaterialCommunityIcons
  237. style={styles.cardIcon}
  238. name="credit-card-edit"
  239. size={32}
  240. color="#00638C"/>
  241. <View style={styles.cardInfo}>
  242. <Text style={styles.cardLabel}>{$t('profile.apply2Fleet')}</Text>
  243. </View>
  244. <FontAwesome
  245. size={28}
  246. color={textCancel}
  247. name='angle-right'/>
  248. </Button>
  249. }
  250. <Button
  251. style={styles.cardView}
  252. viewStyle={styles.profileItem}
  253. onClick={() => this.deleteAccount()}>
  254. <MaterialCommunityIcons
  255. style={styles.cardIcon}
  256. name="account-remove"
  257. size={32}
  258. color="#00638C"/>
  259. <View style={styles.cardInfo}>
  260. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  261. </View>
  262. <FontAwesome
  263. size={28}
  264. color={textCancel}
  265. name='angle-right'/>
  266. </Button>
  267. {/* <Button
  268. style={styles.deleteButton}
  269. text="DELETE MY ACCOUNT"
  270. textColor={textButton}
  271. onClick={() => this.deleteAccount()}
  272. /> */}
  273. <Button
  274. style={styles.deleteButton}
  275. text={$t('profile.logout')}
  276. textColor={textButton}
  277. onClick={() => this.logout()}
  278. />
  279. </ScrollView>
  280. );
  281. }
  282. }
  283. const styles = StyleSheet.create({
  284. container: {
  285. flex: 1,
  286. backgroundColor: pageBackground
  287. },
  288. headerView: {
  289. paddingBottom: 72
  290. },
  291. background: {
  292. left: 0,
  293. right: 0,
  294. bottom: 0,
  295. height: $vw(62.4),
  296. alignItems: 'center',
  297. position: 'absolute'
  298. },
  299. profileView: {
  300. zIndex: 10,
  301. padding: 16,
  302. alignItems: 'center',
  303. flexDirection: 'row'
  304. },
  305. avatar: {
  306. width: 66,
  307. height: 66,
  308. borderWidth: 2,
  309. borderRadius: 80,
  310. borderColor: "#00638C"
  311. },
  312. infoContent: {
  313. flex: 1,
  314. paddingLeft: 16,
  315. },
  316. nickname: {
  317. color: '#000',
  318. fontSize: 20,
  319. fontWeight: 'bold',
  320. paddingTop: 1,
  321. paddingBottom: 1,
  322. },
  323. userText: {
  324. color: textPrimary,
  325. fontSize: 13,
  326. paddingTop: 1.5
  327. },
  328. cardView: {
  329. //padding: 16,
  330. marginTop: 16,
  331. marginLeft: 16,
  332. marginRight: 16,
  333. borderRadius: 10,
  334. overflow: 'hidden',
  335. ...ElevationObject(5),
  336. alignItems: 'center',
  337. flexDirection: 'row',
  338. backgroundColor: colorLight,
  339. },
  340. profileItem: {
  341. padding: 16,
  342. alignItems: 'center',
  343. flexDirection: 'row',
  344. justifyContent: 'center',
  345. },
  346. cardItem: {
  347. flex: 1,
  348. alignItems: 'center',
  349. flexDirection: 'row',
  350. justifyContent: 'center'
  351. },
  352. cardDivide: {
  353. borderLeftWidth: 1,
  354. borderLeftColor: '#EEE'
  355. },
  356. cardIcon: {
  357. width: 32,
  358. height: 32
  359. },
  360. cardInfo: {
  361. flex: 1,
  362. paddingLeft: 16,
  363. alignItems: 'center',
  364. flexDirection: 'row'
  365. },
  366. cardPrimary: {
  367. color: textPrimary,
  368. fontSize: 18
  369. },
  370. cardLabel: {
  371. color: textPrimary,
  372. fontSize: 16,
  373. fontWeight: 'bold'
  374. },
  375. titleView: {
  376. padding: 12,
  377. alignItems: 'center',
  378. flexDirection: 'row'
  379. },
  380. title: {
  381. flex: 1,
  382. padding: 8,
  383. color: '#000',
  384. fontSize: 16,
  385. },
  386. titleAdd: {
  387. padding: 8,
  388. color: textPrimary,
  389. alignItems: 'center',
  390. flexDirection: 'row'
  391. },
  392. verhicleList: {
  393. paddingLeft: 16,
  394. paddingRight: 16,
  395. marginBottom: -16
  396. },
  397. accountList: {
  398. paddingLeft: 16,
  399. paddingRight: 16,
  400. marginBottom: -16
  401. },
  402. notificationView: {
  403. marginLeft: 16,
  404. marginRight: 16,
  405. marginBottom: 20,
  406. borderRadius: 10,
  407. overflow: 'hidden',
  408. paddingLeft: 16,
  409. paddingRight: 16,
  410. borderColor: '#f5f5f5',
  411. borderWidth: 1,
  412. backgroundColor: colorLight,
  413. ...ElevationObject(1.5)
  414. },
  415. notificationItem: {
  416. paddingTop: 16,
  417. paddingBottom: 16,
  418. alignItems: 'center',
  419. flexDirection: 'row'
  420. },
  421. notiLabel: {
  422. flex: 1,
  423. color: textPrimary,
  424. fontSize: 14
  425. },
  426. divide: {
  427. borderTopWidth: 1,
  428. borderTopColor: '#eee'
  429. },
  430. deleteButton: {
  431. ...$margin(48, 16, 16),
  432. backgroundColor: '#EA0A2A'
  433. }
  434. })