ProfileV2.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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 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. <Button
  382. style={styles.cardView}
  383. viewStyle={styles.profileItem}
  384. onClick={() => startPage(PageList.about)}>
  385. <MaterialCommunityIcons
  386. style={styles.cardIcon}
  387. name="information-outline"
  388. color="#00638C"
  389. size={32}
  390. />
  391. <View style={styles.cardInfo}>
  392. <TextView style={styles.cardLabel}>{$t('drawer.about')}</TextView>
  393. </View>
  394. <FontAwesome
  395. size={24}
  396. color={textCancel}
  397. name='angle-right'/>
  398. </Button>
  399. <ShadowViewV2/>
  400. </>}
  401. {/* <Button
  402. style={styles.deleteButton}
  403. text="DELETE MY ACCOUNT"
  404. textColor={textButton}
  405. onClick={() => this.deleteAccount()}
  406. /> */}
  407. <Button
  408. style={styles.deleteButton}
  409. text={$t('profile.logout')}
  410. textColor={textLight}
  411. elevation={4}
  412. textSize={20}
  413. onClick={() => this.logout()}
  414. />
  415. </ScrollView>
  416. );
  417. }
  418. }
  419. const styles = StyleSheet.create({
  420. container: {
  421. flex: 1,
  422. backgroundColor: pageBackground
  423. },
  424. headerView: {
  425. paddingBottom: 72
  426. },
  427. background: {
  428. left: 0,
  429. right: 0,
  430. bottom: 0,
  431. height: $vw(62.4),
  432. alignItems: 'center',
  433. position: 'absolute'
  434. },
  435. profileView: {
  436. zIndex: 10,
  437. padding: 16,
  438. alignItems: 'center',
  439. flexDirection: 'row'
  440. },
  441. avatar: {
  442. width: 66,
  443. height: 66,
  444. borderWidth: 2,
  445. borderRadius: 80,
  446. borderColor: "#00638C"
  447. },
  448. infoContent: {
  449. flex: 1,
  450. paddingLeft: 16,
  451. },
  452. nickname: {
  453. color: '#000',
  454. fontSize: 20,
  455. fontWeight: 'bold',
  456. paddingTop: 1,
  457. paddingBottom: 1,
  458. },
  459. userText: {
  460. color: textPrimary,
  461. fontSize: 13,
  462. paddingTop: 1.5
  463. },
  464. cardView: {
  465. zIndex: 2,
  466. marginTop: 8,
  467. marginLeft: 16,
  468. marginRight: 16,
  469. borderRadius: 10,
  470. overflow: 'hidden',
  471. ...ElevationObject(5),
  472. alignItems: 'center',
  473. flexDirection: 'row',
  474. backgroundColor: colorLight,
  475. },
  476. profileItem: {
  477. ...$padding(24, 16),
  478. alignItems: 'center',
  479. flexDirection: 'row',
  480. justifyContent: 'center',
  481. },
  482. cardItem: {
  483. flex: 1,
  484. alignItems: 'center',
  485. flexDirection: 'row',
  486. justifyContent: 'center'
  487. },
  488. cardDivide: {
  489. borderLeftWidth: 1,
  490. borderLeftColor: '#EEE'
  491. },
  492. cardIcon: {
  493. width: 32,
  494. height: 32
  495. },
  496. cardInfo: {
  497. flex: 1,
  498. paddingLeft: 16,
  499. alignItems: 'flex-start',
  500. flexDirection: 'column'
  501. },
  502. cardPrimary: {
  503. color: textPrimary,
  504. fontSize: 16,
  505. paddingTop: 2
  506. },
  507. cardLabel: {
  508. color: textPrimary,
  509. fontSize: 16,
  510. fontWeight: 'bold'
  511. },
  512. titleView: {
  513. padding: 12,
  514. alignItems: 'center',
  515. flexDirection: 'row'
  516. },
  517. title: {
  518. flex: 1,
  519. padding: 8,
  520. color: '#000',
  521. fontSize: 16,
  522. },
  523. titleAdd: {
  524. padding: 8,
  525. color: textPrimary,
  526. alignItems: 'center',
  527. flexDirection: 'row'
  528. },
  529. verhicleList: {
  530. paddingLeft: 16,
  531. paddingRight: 16,
  532. marginBottom: -16
  533. },
  534. accountList: {
  535. paddingLeft: 16,
  536. paddingRight: 16,
  537. marginBottom: -16
  538. },
  539. notificationView: {
  540. marginLeft: 16,
  541. marginRight: 16,
  542. marginBottom: 20,
  543. borderRadius: 10,
  544. overflow: 'hidden',
  545. paddingLeft: 16,
  546. paddingRight: 16,
  547. borderColor: '#f5f5f5',
  548. borderWidth: 1,
  549. backgroundColor: colorLight,
  550. ...ElevationObject(1.5)
  551. },
  552. notificationItem: {
  553. paddingTop: 16,
  554. paddingBottom: 16,
  555. alignItems: 'center',
  556. flexDirection: 'row'
  557. },
  558. notiLabel: {
  559. flex: 1,
  560. color: textPrimary,
  561. fontSize: 14
  562. },
  563. divide: {
  564. borderTopWidth: 1,
  565. borderTopColor: '#eee'
  566. },
  567. deleteButton: {
  568. borderRadius: 4,
  569. ...$margin(16, 16, 24),
  570. backgroundColor: '#EA0A2A'
  571. },
  572. userTypeView: {
  573. paddingTop: 2,
  574. alignItems: 'center',
  575. flexDirection: 'row'
  576. },
  577. userTypeText: {
  578. color: textLight,
  579. fontSize: 8,
  580. marginRight: 4,
  581. borderRadius: 2,
  582. textAlign: "center",
  583. ...$padding(2, 4),
  584. backgroundColor: colorAccent
  585. }
  586. })