ProfileV2.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /**
  2. * Profile Settings页面
  3. * @邠心vbe on 2021/04/27
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, Image, ScrollView } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import { 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. import { ShadowViewV2 } from '../../components/ShadowView';
  17. export default class ProfileV2 extends Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. userInfo: userInfo,
  22. refreshId: 0,
  23. totalVehicle: 0
  24. };
  25. }
  26. componentDidMount() {
  27. this.init();
  28. this.props.navigation.addListener('focus', () => {
  29. this.init();
  30. });
  31. }
  32. init() {
  33. getUserInfo(info => {
  34. this.setState({
  35. userInfo: info,
  36. refreshId: this.state.refreshId + 1
  37. });
  38. }, true);
  39. }
  40. deleteAccount() {
  41. utils.logEventTracking("user_action: delete_account")
  42. Dialog.showDialog({
  43. title: $t('profile.deleteAccount'),
  44. message: $t('profile.confirmDeleteAccount'),
  45. ok: $t('nav.confirm'),
  46. callback: button => {
  47. if (button == Dialog.BUTTON_OK) {
  48. this.deleteMyAccount();
  49. }
  50. }
  51. })
  52. }
  53. deleteMyAccount(again=false) {
  54. Dialog.showProgressDialog();
  55. apiUser.deleteAccount({
  56. secondConfirm: again
  57. }).then(res => {
  58. toastShort($t('profile.deleteAccountSuccess'))
  59. Dialog.dismissLoading();
  60. this.requestLogout();
  61. /*setTimeout(() => {
  62. startPage(PageList.login);
  63. }, 500);*/
  64. }).catch(err => {
  65. Dialog.dismissLoading();
  66. //toastShort(err)
  67. setTimeout(() => {
  68. if (err.code == 5334 || err.code == 5368) {
  69. Dialog.showDialog({
  70. title: $t('profile.deleteAccount'),
  71. message: err.msg,
  72. ok: $t("nav.confirm"),
  73. callback: button => {
  74. if (button == Dialog.BUTTON_OK) {
  75. setTimeout(() => {
  76. this.deleteMyAccount(true);
  77. }, 500)
  78. }
  79. }
  80. })
  81. } else {
  82. Dialog.showResultDialog(err.msg);
  83. }
  84. }, 500);
  85. })
  86. }
  87. logout() {
  88. utils.logEventTracking("user_action: logout")
  89. Dialog.showDialog({
  90. title: $t('profile.signOut'),
  91. message: $t('profile.tipSignOut'),
  92. callback: btn => {
  93. if (btn == Dialog.BUTTON_OK) {
  94. Dialog.showProgressDialog();
  95. setTimeout(() => {
  96. this.requestLogout();
  97. }, 500);
  98. }
  99. }
  100. })
  101. }
  102. async requestLogout() {
  103. const data = await getStorageJsonSync('loginData');
  104. if (data && data.email) {
  105. delete data.password
  106. setStorageJson('loginData', data);
  107. setStorage('RegisterTokenDate', "");
  108. }
  109. global.userInfo = {}
  110. /*this.setState({
  111. isLogin: false,
  112. userInfo: {}
  113. });*/
  114. setAccessToken('');
  115. goBack();
  116. Dialog.dismissLoading();
  117. }
  118. render() {
  119. return (
  120. <ScrollView style={styles.container}>
  121. {/* Profile Info */}
  122. <EndView half/>
  123. <Button
  124. style={styles.cardView}
  125. viewStyle={styles.profileView}
  126. android_ripple={ripple}
  127. onClick={() => startPage(PageList.editProfile)}>
  128. { this.state.userInfo.photoUrl
  129. ? <Image
  130. style={styles.avatar}
  131. source={{uri: utils.getImageUrl(this.state.userInfo.photoUrl)}}/>
  132. : <Image
  133. style={styles.avatar}
  134. source={require('../../images/user/ic-avatar-default.png')}/>
  135. }
  136. <View style={styles.infoContent}>
  137. <TextView
  138. style={styles.nickname}
  139. ellipsizeMode='tail'
  140. numberOfLines={1}>{this.state.userInfo.nickName}</TextView>
  141. <TextView style={styles.userText}>{this.state.userInfo.email}</TextView>
  142. <TextView style={styles.userText}>{(utils.isNotEmpty(this.state.userInfo.callingCode) && "+" + this.state.userInfo.callingCode + " ") + this.state.userInfo.phone}</TextView>
  143. {/* <View style={styles.userTypeView}>
  144. { this.state.userInfo.userType?.split(";").map((item, index) => {
  145. return <TextView key={index} style={styles.userTypeText}>{item}</TextView>
  146. })
  147. }
  148. </View> */}
  149. </View>
  150. <FontAwesome
  151. size={24}
  152. color={textCancel}
  153. name='angle-right'/>
  154. </Button>
  155. <ShadowViewV2/>
  156. <EndView half/>
  157. {/* Wallet Info */}
  158. {/* app.v4.wallet
  159. ? <Button
  160. style={styles.cardView}
  161. viewStyle={styles.profileItem}
  162. onClick={() => startPage(PageList.wallets)}>
  163. <Image
  164. style={styles.cardIcon}
  165. source={require('../../images/user/card-wallet.png')}/>
  166. <View style={styles.cardInfo}>
  167. <TextView style={styles.cardLabel}>{$t('drawer.wallets')}</TextView>
  168. </View>
  169. <FontAwesome
  170. size={24}
  171. color={textCancel}
  172. name='angle-right'/>
  173. </Button>
  174. : <Button
  175. style={styles.cardView}
  176. viewStyle={styles.profileItem}
  177. onClick={() => startPage(PageList.wallet)}>
  178. <Image
  179. style={styles.cardIcon}
  180. source={require('../../images/user/card-wallet.png')}/>
  181. <View style={styles.cardInfo}>
  182. <TextView style={styles.cardLabel}>{$t('wallet.creditWalletLabel')}</TextView>
  183. <TextView style={styles.cardPrimary}>{this.state.userInfo.creditStr}</TextView>
  184. </View>
  185. <FontAwesome
  186. size={24}
  187. color={textCancel}
  188. name='angle-right'/>
  189. </Button>
  190. */}
  191. <ShadowViewV2/>
  192. { (utils.isNotEmpty(this.state.userInfo.groupWallet) && !app.v4.wallet) && <>
  193. <Button
  194. style={styles.cardView}
  195. viewStyle={styles.profileItem}>
  196. <Image
  197. style={styles.cardIcon}
  198. source={require('../../images/user/card-wallet.png')}/>
  199. <View style={styles.cardInfo}>
  200. <TextView style={styles.cardLabel}>{this.state.userInfo.groupWallet.walletName}:</TextView>
  201. <TextView style={styles.cardPrimary}>{this.state.userInfo.groupWallet.creditStr}, Expires on {this.state.userInfo.groupWallet.expireTime}</TextView>
  202. </View>
  203. </Button>
  204. <ShadowViewV2/>
  205. </>
  206. }
  207. {/* Vehicle Info */}
  208. { app.vehicle.enable && <>
  209. <Button
  210. style={styles.cardView}
  211. viewStyle={styles.profileItem}
  212. onClick={() => startPage(app.vehicle.newVersionPage ? PageList.vehiclesListV2 : PageList.myVehicles)}>
  213. <Image
  214. style={styles.cardIcon}
  215. source={require('../../images/user/card-vehicle.png')}/>
  216. <View style={styles.cardInfo}>
  217. <TextView style={styles.cardLabel}>{$t('profile.myVehicles')}</TextView>
  218. <TextView style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</TextView>
  219. </View>
  220. <FontAwesome
  221. size={24}
  222. color={textCancel}
  223. name='angle-right'/>
  224. </Button>
  225. <ShadowViewV2/>
  226. </>
  227. }
  228. {/* Vehicle List */}
  229. {/* <View style={styles.titleView}>
  230. <Text style={styles.title}>{$t('profile.myVehicles')}</Text>
  231. <Button
  232. style={{backgroundColor: colorLight}}
  233. borderRadius={3}
  234. viewStyle={styles.titleAdd}
  235. onClick={() => {
  236. startPage(PageList.addVehicle)
  237. }}>
  238. <Entypo name='plus' size={14} color={colorDark}/>
  239. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  240. </Button>
  241. </View> */}
  242. {/* <View style={styles.verhicleList}>
  243. <VehicleList
  244. refreshId={this.state.refreshId}
  245. onResult={count => {
  246. this.setState({
  247. totalVehicle: count
  248. })
  249. }}
  250. onDelete={id => this.removeVehicle(id)}
  251. />
  252. </View> */}
  253. {/* Account List */}
  254. {/* <View style={styles.titleView}>
  255. <Text style={styles.title}>My Cards</Text>
  256. <Button
  257. textColor={textPrimary}
  258. style={styles.titleAdd}
  259. onClick={() => {
  260. startPage(PageList.addCard)
  261. }}>
  262. <Entypo name='plus' size={14} color={colorDark}/>
  263. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  264. </Button>
  265. </View>
  266. <View style={styles.accountList}>
  267. <CardList refreshId={this.state.refreshId}/>
  268. </View> */}
  269. {/* <Button
  270. style={styles.cardView}
  271. viewStyle={styles.profileItem}
  272. onClick={() => this.deleteAccount()}>
  273. <MaterialCommunityIcons
  274. style={styles.cardIcon}
  275. name="account-remove"
  276. size={32}
  277. color="#00638C"/>
  278. <View style={styles.cardInfo}>
  279. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  280. </View>
  281. <FontAwesome
  282. size={24}
  283. color={textCancel}
  284. name='angle-right'/>
  285. </Button>
  286. <ShadowViewV2/> */}
  287. <Button
  288. style={styles.cardView}
  289. viewStyle={styles.profileItem}
  290. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  291. <Image
  292. style={styles.cardIcon}
  293. source={require('../../images/user/card-account.png')}/>
  294. <View style={styles.cardInfo}>
  295. <TextView style={styles.cardLabel}>{$t('route.changePassword')}</TextView>
  296. </View>
  297. <FontAwesome
  298. size={24}
  299. color={textCancel}
  300. name='angle-right'/>
  301. </Button>
  302. <ShadowViewV2/>
  303. {/* Notifications */}
  304. { !app.v3.drawer && <>
  305. <Button
  306. style={styles.cardView}
  307. viewStyle={styles.profileItem}
  308. onClick={() => startPage(PageList.settings)}>
  309. <Image
  310. style={styles.cardIcon}
  311. source={require('../../images/user/card-notification.png')}/>
  312. <View style={styles.cardInfo}>
  313. <TextView style={styles.cardLabel}>{$t('profile.notificationSettings')}</TextView>
  314. </View>
  315. <FontAwesome
  316. size={24}
  317. color={textCancel}
  318. name='angle-right'/>
  319. </Button>
  320. <ShadowViewV2/>
  321. </>
  322. }
  323. { (app.modules.apply_phv && this.state.userInfo.userType.toLowerCase() == "public") && <>
  324. <Button
  325. style={styles.cardView}
  326. viewStyle={styles.profileItem}
  327. onClick={() => startPage(PageList.registerFleet)}>
  328. <MaterialCommunityIcons
  329. style={styles.cardIcon}
  330. name="credit-card-edit"
  331. size={32}
  332. color="#00638C"/>
  333. <View style={styles.cardInfo}>
  334. <TextView style={styles.cardLabel}>{$t('profile.apply2Fleet')}</TextView>
  335. </View>
  336. <FontAwesome
  337. size={24}
  338. color={textCancel}
  339. name='angle-right'/>
  340. </Button>
  341. <ShadowViewV2/>
  342. </>
  343. }
  344. { app.v3.drawer && <>
  345. <Button
  346. style={styles.cardView}
  347. viewStyle={styles.profileItem}
  348. onClick={() => startPage(PageList.feedback)}>
  349. <MaterialCommunityIcons
  350. style={styles.cardIcon}
  351. name="message-alert-outline"
  352. color="#00638C"
  353. size={32}
  354. />
  355. <View style={styles.cardInfo}>
  356. <TextView style={styles.cardLabel}>{$t('drawer.feedback')}</TextView>
  357. </View>
  358. <FontAwesome
  359. size={24}
  360. color={textCancel}
  361. name='angle-right'/>
  362. </Button>
  363. <ShadowViewV2/>
  364. <Button
  365. style={styles.cardView}
  366. viewStyle={styles.profileItem}
  367. onClick={() => startPage(PageList.settings)}>
  368. <MaterialIcons
  369. style={styles.cardIcon}
  370. name="settings"
  371. color="#00638C"
  372. size={32}
  373. />
  374. <View style={styles.cardInfo}>
  375. <TextView style={styles.cardLabel}>{$t('drawer.settings')}</TextView>
  376. </View>
  377. <FontAwesome
  378. size={24}
  379. color={textCancel}
  380. name='angle-right'/>
  381. </Button>
  382. <ShadowViewV2/>
  383. </>}
  384. <Button
  385. style={styles.cardView}
  386. viewStyle={styles.profileItem}
  387. onClick={() => startPage(PageList.about)}>
  388. <MaterialCommunityIcons
  389. style={styles.cardIcon}
  390. name="information-outline"
  391. color="#00638C"
  392. size={32}
  393. />
  394. <View style={styles.cardInfo}>
  395. <TextView style={styles.cardLabel}>{$t('drawer.about')}</TextView>
  396. </View>
  397. <FontAwesome
  398. size={24}
  399. color={textCancel}
  400. name='angle-right'/>
  401. </Button>
  402. <ShadowViewV2/>
  403. <Button
  404. style={styles.cardView}
  405. viewStyle={styles.profileItem}
  406. onClick={() => {
  407. this.deleteAccount();
  408. //startPage(PageList.deleteAccount)
  409. }}>
  410. <MaterialCommunityIcons
  411. style={styles.cardIcon}
  412. name="account-remove"
  413. size={32}
  414. color="#00638C"/>
  415. <View style={styles.cardInfo}>
  416. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  417. </View>
  418. <FontAwesome
  419. size={24}
  420. color={textCancel}
  421. name='angle-right'/>
  422. </Button>
  423. <ShadowViewV2/>
  424. {/* <Button
  425. style={styles.deleteButton}
  426. text="DELETE MY ACCOUNT"
  427. textColor={textButton}
  428. onClick={() => this.deleteAccount()}
  429. /> */}
  430. <Button
  431. style={styles.deleteButton}
  432. text={$t('profile.logout')}
  433. textColor={textLight}
  434. elevation={4}
  435. textSize={20}
  436. onClick={() => this.logout()}
  437. />
  438. </ScrollView>
  439. );
  440. }
  441. }
  442. const styles = StyleSheet.create({
  443. container: {
  444. flex: 1,
  445. backgroundColor: pageBackground
  446. },
  447. headerView: {
  448. paddingBottom: 72
  449. },
  450. background: {
  451. left: 0,
  452. right: 0,
  453. bottom: 0,
  454. height: $vw(62.4),
  455. alignItems: 'center',
  456. position: 'absolute'
  457. },
  458. profileView: {
  459. zIndex: 10,
  460. padding: 16,
  461. alignItems: 'center',
  462. flexDirection: 'row'
  463. },
  464. avatar: {
  465. width: 66,
  466. height: 66,
  467. borderWidth: 2,
  468. borderRadius: 80,
  469. borderColor: "#00638C"
  470. },
  471. infoContent: {
  472. flex: 1,
  473. paddingLeft: 16,
  474. },
  475. nickname: {
  476. color: '#000',
  477. fontSize: 20,
  478. fontWeight: 'bold',
  479. paddingTop: 1,
  480. paddingBottom: 1,
  481. },
  482. userText: {
  483. color: textPrimary,
  484. fontSize: 13,
  485. paddingTop: 1.5
  486. },
  487. cardView: {
  488. zIndex: 2,
  489. marginTop: 8,
  490. marginLeft: 16,
  491. marginRight: 16,
  492. borderRadius: 10,
  493. overflow: 'hidden',
  494. //...ElevationObject(5),
  495. alignItems: 'center',
  496. flexDirection: 'row',
  497. backgroundColor: colorLight,
  498. },
  499. profileItem: {
  500. ...$padding(24, 16),
  501. alignItems: 'center',
  502. flexDirection: 'row',
  503. justifyContent: 'center',
  504. },
  505. cardItem: {
  506. flex: 1,
  507. alignItems: 'center',
  508. flexDirection: 'row',
  509. justifyContent: 'center'
  510. },
  511. cardDivide: {
  512. borderLeftWidth: 1,
  513. borderLeftColor: '#EEE'
  514. },
  515. cardIcon: {
  516. width: 32,
  517. height: 32
  518. },
  519. cardInfo: {
  520. flex: 1,
  521. paddingLeft: 16,
  522. alignItems: 'flex-start',
  523. flexDirection: 'column'
  524. },
  525. cardPrimary: {
  526. color: textPrimary,
  527. fontSize: 16,
  528. paddingTop: 2
  529. },
  530. cardLabel: {
  531. color: textPrimary,
  532. fontSize: 16,
  533. fontWeight: 'bold'
  534. },
  535. titleView: {
  536. padding: 12,
  537. alignItems: 'center',
  538. flexDirection: 'row'
  539. },
  540. title: {
  541. flex: 1,
  542. padding: 8,
  543. color: '#000',
  544. fontSize: 16,
  545. },
  546. titleAdd: {
  547. padding: 8,
  548. color: textPrimary,
  549. alignItems: 'center',
  550. flexDirection: 'row'
  551. },
  552. verhicleList: {
  553. paddingLeft: 16,
  554. paddingRight: 16,
  555. marginBottom: -16
  556. },
  557. accountList: {
  558. paddingLeft: 16,
  559. paddingRight: 16,
  560. marginBottom: -16
  561. },
  562. notificationView: {
  563. marginLeft: 16,
  564. marginRight: 16,
  565. marginBottom: 20,
  566. borderRadius: 10,
  567. overflow: 'hidden',
  568. paddingLeft: 16,
  569. paddingRight: 16,
  570. borderColor: '#f5f5f5',
  571. borderWidth: 1,
  572. backgroundColor: colorLight,
  573. ...ElevationObject(1.5)
  574. },
  575. notificationItem: {
  576. paddingTop: 16,
  577. paddingBottom: 16,
  578. alignItems: 'center',
  579. flexDirection: 'row'
  580. },
  581. notiLabel: {
  582. flex: 1,
  583. color: textPrimary,
  584. fontSize: 14
  585. },
  586. divide: {
  587. borderTopWidth: 1,
  588. borderTopColor: '#eee'
  589. },
  590. deleteButton: {
  591. borderRadius: 4,
  592. ...$margin(16, 16, 24),
  593. backgroundColor: '#EA0A2A'
  594. },
  595. userTypeView: {
  596. paddingTop: 2,
  597. alignItems: 'center',
  598. flexDirection: 'row'
  599. },
  600. userTypeText: {
  601. color: textLight,
  602. fontSize: 8,
  603. marginRight: 4,
  604. borderRadius: 2,
  605. textAlign: "center",
  606. ...$padding(2, 4),
  607. backgroundColor: colorAccent
  608. }
  609. })