ProfileV2.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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) {
  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/>
  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. {/* Wallet Info */}
  155. <Button
  156. style={styles.cardView}
  157. viewStyle={styles.profileItem}
  158. onClick={() => startPage(PageList.wallet)}>
  159. <Image
  160. style={styles.cardIcon}
  161. source={require('../../images/user/card-wallet.png')}/>
  162. <View style={styles.cardInfo}>
  163. <TextView style={styles.cardLabel}>{$t('wallet.creditWalletLabel')}</TextView>
  164. <TextView style={styles.cardPrimary}>{this.state.userInfo.creditStr}</TextView>
  165. </View>
  166. <FontAwesome
  167. size={24}
  168. color={textCancel}
  169. name='angle-right'/>
  170. </Button>
  171. <ShadowViewV2/>
  172. { utils.isNotEmpty(this.state.userInfo.groupWallet) && <>
  173. <Button
  174. style={styles.cardView}
  175. viewStyle={styles.profileItem}>
  176. <Image
  177. style={styles.cardIcon}
  178. source={require('../../images/user/card-wallet.png')}/>
  179. <View style={styles.cardInfo}>
  180. <TextView style={styles.cardLabel}>{this.state.userInfo.groupWallet.walletName}</TextView>
  181. <TextView style={styles.cardPrimary}>{this.state.userInfo.groupWallet.expireTime}</TextView>
  182. </View>
  183. </Button>
  184. <ShadowViewV2/>
  185. </>
  186. }
  187. {/* Vehicle Info */}
  188. { app.vehicle.enable && <>
  189. <Button
  190. style={styles.cardView}
  191. viewStyle={styles.profileItem}
  192. onClick={() => startPage(app.vehicle.newVersionPage ? PageList.vehiclesListV2 : PageList.myVehicles)}>
  193. <Image
  194. style={styles.cardIcon}
  195. source={require('../../images/user/card-vehicle.png')}/>
  196. <View style={styles.cardInfo}>
  197. <TextView style={styles.cardLabel}>{$t('profile.myVehicles')}</TextView>
  198. <TextView style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</TextView>
  199. </View>
  200. <FontAwesome
  201. size={24}
  202. color={textCancel}
  203. name='angle-right'/>
  204. </Button>
  205. <ShadowViewV2/>
  206. </>
  207. }
  208. {/* Vehicle List */}
  209. {/* <View style={styles.titleView}>
  210. <Text style={styles.title}>{$t('profile.myVehicles')}</Text>
  211. <Button
  212. style={{backgroundColor: colorLight}}
  213. borderRadius={3}
  214. viewStyle={styles.titleAdd}
  215. onClick={() => {
  216. startPage(PageList.addVehicle)
  217. }}>
  218. <Entypo name='plus' size={14} color={colorDark}/>
  219. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  220. </Button>
  221. </View> */}
  222. {/* <View style={styles.verhicleList}>
  223. <VehicleList
  224. refreshId={this.state.refreshId}
  225. onResult={count => {
  226. this.setState({
  227. totalVehicle: count
  228. })
  229. }}
  230. onDelete={id => this.removeVehicle(id)}
  231. />
  232. </View> */}
  233. {/* Account List */}
  234. {/* <View style={styles.titleView}>
  235. <Text style={styles.title}>My Cards</Text>
  236. <Button
  237. textColor={textPrimary}
  238. style={styles.titleAdd}
  239. onClick={() => {
  240. startPage(PageList.addCard)
  241. }}>
  242. <Entypo name='plus' size={14} color={colorDark}/>
  243. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  244. </Button>
  245. </View>
  246. <View style={styles.accountList}>
  247. <CardList refreshId={this.state.refreshId}/>
  248. </View> */}
  249. <Button
  250. style={styles.cardView}
  251. viewStyle={styles.profileItem}
  252. onClick={() => this.deleteAccount()}>
  253. <MaterialCommunityIcons
  254. style={styles.cardIcon}
  255. name="account-remove"
  256. size={32}
  257. color="#00638C"/>
  258. <View style={styles.cardInfo}>
  259. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  260. </View>
  261. <FontAwesome
  262. size={24}
  263. color={textCancel}
  264. name='angle-right'/>
  265. </Button>
  266. <ShadowViewV2/>
  267. <Button
  268. style={styles.cardView}
  269. viewStyle={styles.profileItem}
  270. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  271. <Image
  272. style={styles.cardIcon}
  273. source={require('../../images/user/card-account.png')}/>
  274. <View style={styles.cardInfo}>
  275. <TextView style={styles.cardLabel}>{$t('route.changePassword')}</TextView>
  276. </View>
  277. <FontAwesome
  278. size={24}
  279. color={textCancel}
  280. name='angle-right'/>
  281. </Button>
  282. <ShadowViewV2/>
  283. {/* Notifications */}
  284. { !app.v3.drawer && <>
  285. <Button
  286. style={styles.cardView}
  287. viewStyle={styles.profileItem}
  288. onClick={() => startPage(PageList.settings)}>
  289. <Image
  290. style={styles.cardIcon}
  291. source={require('../../images/user/card-notification.png')}/>
  292. <View style={styles.cardInfo}>
  293. <TextView style={styles.cardLabel}>{$t('profile.notificationSettings')}</TextView>
  294. </View>
  295. <FontAwesome
  296. size={24}
  297. color={textCancel}
  298. name='angle-right'/>
  299. </Button>
  300. <ShadowViewV2/>
  301. </>
  302. }
  303. { (app.modules.apply_phv && this.state.userInfo.userType.toLowerCase() == "public") && <>
  304. <Button
  305. style={styles.cardView}
  306. viewStyle={styles.profileItem}
  307. onClick={() => startPage(PageList.registerFleet)}>
  308. <MaterialCommunityIcons
  309. style={styles.cardIcon}
  310. name="credit-card-edit"
  311. size={32}
  312. color="#00638C"/>
  313. <View style={styles.cardInfo}>
  314. <TextView style={styles.cardLabel}>{$t('profile.apply2Fleet')}</TextView>
  315. </View>
  316. <FontAwesome
  317. size={24}
  318. color={textCancel}
  319. name='angle-right'/>
  320. </Button>
  321. <ShadowViewV2/>
  322. </>
  323. }
  324. { app.v3.drawer && <>
  325. <Button
  326. style={styles.cardView}
  327. viewStyle={styles.profileItem}
  328. onClick={() => startPage(PageList.feedback)}>
  329. <MaterialCommunityIcons
  330. style={styles.cardIcon}
  331. name="message-alert-outline"
  332. color="#00638C"
  333. size={32}
  334. />
  335. <View style={styles.cardInfo}>
  336. <TextView style={styles.cardLabel}>{$t('drawer.feedback')}</TextView>
  337. </View>
  338. <FontAwesome
  339. size={24}
  340. color={textCancel}
  341. name='angle-right'/>
  342. </Button>
  343. <ShadowViewV2/>
  344. <Button
  345. style={styles.cardView}
  346. viewStyle={styles.profileItem}
  347. onClick={() => startPage(PageList.settings)}>
  348. <MaterialIcons
  349. style={styles.cardIcon}
  350. name="settings"
  351. color="#00638C"
  352. size={32}
  353. />
  354. <View style={styles.cardInfo}>
  355. <TextView style={styles.cardLabel}>{$t('drawer.settings')}</TextView>
  356. </View>
  357. <FontAwesome
  358. size={24}
  359. color={textCancel}
  360. name='angle-right'/>
  361. </Button>
  362. <ShadowViewV2/>
  363. <Button
  364. style={styles.cardView}
  365. viewStyle={styles.profileItem}
  366. onClick={() => startPage(PageList.about)}>
  367. <MaterialCommunityIcons
  368. style={styles.cardIcon}
  369. name="information-outline"
  370. color="#00638C"
  371. size={32}
  372. />
  373. <View style={styles.cardInfo}>
  374. <TextView style={styles.cardLabel}>{$t('drawer.about')}</TextView>
  375. </View>
  376. <FontAwesome
  377. size={24}
  378. color={textCancel}
  379. name='angle-right'/>
  380. </Button>
  381. <ShadowViewV2/>
  382. </>}
  383. {/* <Button
  384. style={styles.deleteButton}
  385. text="DELETE MY ACCOUNT"
  386. textColor={textButton}
  387. onClick={() => this.deleteAccount()}
  388. /> */}
  389. <Button
  390. style={styles.deleteButton}
  391. text={$t('profile.logout')}
  392. textColor={textLight}
  393. elevation={16}
  394. onClick={() => this.logout()}
  395. />
  396. </ScrollView>
  397. );
  398. }
  399. }
  400. const styles = StyleSheet.create({
  401. container: {
  402. flex: 1,
  403. backgroundColor: pageBackground
  404. },
  405. headerView: {
  406. paddingBottom: 72
  407. },
  408. background: {
  409. left: 0,
  410. right: 0,
  411. bottom: 0,
  412. height: $vw(62.4),
  413. alignItems: 'center',
  414. position: 'absolute'
  415. },
  416. profileView: {
  417. zIndex: 10,
  418. padding: 16,
  419. alignItems: 'center',
  420. flexDirection: 'row'
  421. },
  422. avatar: {
  423. width: 66,
  424. height: 66,
  425. borderWidth: 2,
  426. borderRadius: 80,
  427. borderColor: "#00638C"
  428. },
  429. infoContent: {
  430. flex: 1,
  431. paddingLeft: 16,
  432. },
  433. nickname: {
  434. color: '#000',
  435. fontSize: 20,
  436. fontWeight: 'bold',
  437. paddingTop: 1,
  438. paddingBottom: 1,
  439. },
  440. userText: {
  441. color: textPrimary,
  442. fontSize: 13,
  443. paddingTop: 1.5
  444. },
  445. cardView: {
  446. zIndex: 2,
  447. marginTop: 0,
  448. marginLeft: 16,
  449. marginRight: 16,
  450. borderRadius: 10,
  451. overflow: 'hidden',
  452. ...ElevationObject(5),
  453. alignItems: 'center',
  454. flexDirection: 'row',
  455. backgroundColor: colorLight,
  456. },
  457. profileItem: {
  458. ...$padding(24, 16),
  459. alignItems: 'center',
  460. flexDirection: 'row',
  461. justifyContent: 'center',
  462. },
  463. cardItem: {
  464. flex: 1,
  465. alignItems: 'center',
  466. flexDirection: 'row',
  467. justifyContent: 'center'
  468. },
  469. cardDivide: {
  470. borderLeftWidth: 1,
  471. borderLeftColor: '#EEE'
  472. },
  473. cardIcon: {
  474. width: 32,
  475. height: 32
  476. },
  477. cardInfo: {
  478. flex: 1,
  479. paddingLeft: 16,
  480. alignItems: 'flex-start',
  481. flexDirection: 'column'
  482. },
  483. cardPrimary: {
  484. color: textPrimary,
  485. fontSize: 16,
  486. paddingTop: 2
  487. },
  488. cardLabel: {
  489. color: textPrimary,
  490. fontSize: 16,
  491. fontWeight: 'bold'
  492. },
  493. titleView: {
  494. padding: 12,
  495. alignItems: 'center',
  496. flexDirection: 'row'
  497. },
  498. title: {
  499. flex: 1,
  500. padding: 8,
  501. color: '#000',
  502. fontSize: 16,
  503. },
  504. titleAdd: {
  505. padding: 8,
  506. color: textPrimary,
  507. alignItems: 'center',
  508. flexDirection: 'row'
  509. },
  510. verhicleList: {
  511. paddingLeft: 16,
  512. paddingRight: 16,
  513. marginBottom: -16
  514. },
  515. accountList: {
  516. paddingLeft: 16,
  517. paddingRight: 16,
  518. marginBottom: -16
  519. },
  520. notificationView: {
  521. marginLeft: 16,
  522. marginRight: 16,
  523. marginBottom: 20,
  524. borderRadius: 10,
  525. overflow: 'hidden',
  526. paddingLeft: 16,
  527. paddingRight: 16,
  528. borderColor: '#f5f5f5',
  529. borderWidth: 1,
  530. backgroundColor: colorLight,
  531. ...ElevationObject(1.5)
  532. },
  533. notificationItem: {
  534. paddingTop: 16,
  535. paddingBottom: 16,
  536. alignItems: 'center',
  537. flexDirection: 'row'
  538. },
  539. notiLabel: {
  540. flex: 1,
  541. color: textPrimary,
  542. fontSize: 14
  543. },
  544. divide: {
  545. borderTopWidth: 1,
  546. borderTopColor: '#eee'
  547. },
  548. deleteButton: {
  549. borderRadius: 4,
  550. ...$margin(4, 16, 16),
  551. backgroundColor: '#EA0A2A'
  552. },
  553. userTypeView: {
  554. paddingTop: 2,
  555. alignItems: 'center',
  556. flexDirection: 'row'
  557. },
  558. userTypeText: {
  559. color: textLight,
  560. fontSize: 8,
  561. marginRight: 4,
  562. borderRadius: 2,
  563. textAlign: "center",
  564. ...$padding(2, 4),
  565. backgroundColor: colorAccent
  566. }
  567. })