ProfileV2.js 16 KB

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