ProfileV2.js 17 KB

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