ProfileV3.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /**
  2. * V3版本Profile页面
  3. * @邠心vbe on 2024/05/30
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, Image, ScrollView, StatusBar, Pressable } from 'react-native';
  7. import Button, { ElevationObject } from '../../components/Button';
  8. import TextView from '../../components/TextView';
  9. import Dialog from '../../components/Dialog';
  10. import apiUser from '../../api/apiUser';
  11. import { setAccessToken } from '../../api/http';
  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 Svg, { Defs, Ellipse, G, LinearGradient, Path, Rect, Stop } from 'react-native-svg';
  17. import ShadowView from '../../components/ShadowView';
  18. import MyStatusBar from '../../components/MyStatusBar';
  19. export default class ProfileV3 extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. isHide: false,
  24. userInfo: userInfo,
  25. totalVehicle: 0
  26. };
  27. }
  28. componentDidMount() {
  29. this.init();
  30. this.props.navigation.addListener('focus', () => {
  31. this.init();
  32. this.setState({
  33. isHide: false
  34. }, () => {
  35. setTimeout(() => {
  36. MyStatusBar.setStatusBarTheme(MyStatusBar.LIGHT_STYLE);
  37. }, 100);
  38. });
  39. });
  40. this.props.navigation.addListener('blur', () => {
  41. this.setState({
  42. isHide: true
  43. })
  44. MyStatusBar.setStatusBarTheme(MyStatusBar.DARK_STYLE);
  45. });
  46. }
  47. init() {
  48. getUserInfo(info => {
  49. this.setState({
  50. userInfo: info
  51. });
  52. }, true);
  53. }
  54. deleteAccount() {
  55. Dialog.showDialog({
  56. title: $t('profile.deleteAccount'),
  57. message: $t('profile.confirmDeleteAccount'),
  58. ok: $t('nav.confirm'),
  59. callback: button => {
  60. if (button == Dialog.BUTTON_OK) {
  61. this.deleteMyAccount();
  62. }
  63. }
  64. })
  65. }
  66. deleteMyAccount() {
  67. Dialog.showProgressDialog();
  68. apiUser.deleteAccount().then(res => {
  69. toastShort($t('profile.deleteAccountSuccess'))
  70. Dialog.dismissLoading();
  71. this.requestLogout();
  72. /*setTimeout(() => {
  73. startPage(PageList.login);
  74. }, 500);*/
  75. }).catch(err => {
  76. Dialog.dismissLoading();
  77. //toastShort(err)
  78. setTimeout(() => {
  79. Dialog.showResultDialog(err.msg);
  80. }, 500);
  81. })
  82. }
  83. logout() {
  84. Dialog.showDialog({
  85. title: $t('profile.signOut'),
  86. message: $t('profile.tipSignOut'),
  87. callback: btn => {
  88. if (btn == Dialog.BUTTON_OK) {
  89. Dialog.showProgressDialog();
  90. setTimeout(() => {
  91. this.requestLogout();
  92. }, 500);
  93. }
  94. }
  95. })
  96. }
  97. async requestLogout() {
  98. const data = await getStorageJsonSync('loginData');
  99. if (data && data.email) {
  100. delete data.password
  101. setStorageJson('loginData', data);
  102. setStorage('RegisterTokenDate', "");
  103. }
  104. global.userInfo = {}
  105. /*this.setState({
  106. isLogin: false,
  107. userInfo: {}
  108. });*/
  109. setAccessToken('');
  110. goBack();
  111. Dialog.dismissLoading();
  112. }
  113. render() {
  114. return (
  115. <ScrollView style={styles.container} stickyHeaderIndices={[0]}>
  116. {/* <StatusBar backgroundColor={this.state.isHide ? colorLight : colorPrimary} /> */}
  117. <View style={styles.headerView}>
  118. <Pressable
  119. style={styles.titleBar}
  120. onPress={() => goBack()}>
  121. <MaterialIcons
  122. name={'arrow-back-ios'}
  123. size={20}
  124. color={textLight} />
  125. <TextView style={styles.titleText}>Profile</TextView>
  126. </Pressable>
  127. <View style={styles.profileHeader}>
  128. {this.state.userInfo.photoUrl
  129. ? <Image
  130. style={styles.avatarImage}
  131. source={{ uri: utils.getImageUrl(this.state.userInfo.photoUrl) }} />
  132. : <Image
  133. style={styles.avatarImage}
  134. source={require('../../images/user/ic-avatar-default.png')} />
  135. }
  136. <View style={styles.infoContent}>
  137. <View style={ui.flexc}>
  138. <TextView
  139. style={styles.nickname}
  140. ellipsizeMode='tail'
  141. numberOfLines={1}>{this.state.userInfo.nickName}</TextView>
  142. <TextView
  143. style={styles.countryLabel}>Singapore</TextView>
  144. </View>
  145. <TextView style={styles.userText}>{this.state.userInfo.email}</TextView>
  146. <View style={ui.flex}>
  147. <Button
  148. text={"Edit"}
  149. textSize={12}
  150. textColor={colorPrimary}
  151. style={styles.editButton}
  152. viewStyle={styles.editButtonView}
  153. iconRight={
  154. <Feather
  155. name="edit-3"
  156. size={14}
  157. color={colorPrimary} />
  158. }
  159. onClick={() => startPage(PageList.editProfile)}
  160. />
  161. </View>
  162. </View>
  163. </View>
  164. </View>
  165. <View style={styles.circleButtomView}>
  166. <Svg width={$vw(100)} height={$vw(42.13)} viewBox="0 0 375 158" fill="none">
  167. <Ellipse cx={187.5} cy={79} rx={238.5} ry={79} fill={colorPrimary} />
  168. </Svg>
  169. </View>
  170. <Pressable
  171. style={styles.walletView}
  172. onPress={() => startPage(PageList.transaction)}>
  173. <Image
  174. style={styles.walletIcon}
  175. source={require("../../images/wallet/lumi-logo.png")}/>
  176. <View style={styles.walletContent}>
  177. <TextView style={styles.walletTitle}>Available Credits:</TextView>
  178. <TextView style={styles.walletAmount}>{this.state.userInfo?.creditStr}</TextView>
  179. </View>
  180. <Button
  181. text={"Buy"}
  182. textSize={12}
  183. textColor={textLight}
  184. style={styles.topupButton}
  185. viewStyle={styles.topupButtonView}
  186. iconRight={
  187. <MaterialIcons
  188. name="chevron-right"
  189. size={16}
  190. color={textLight} />
  191. }
  192. onClick={() => startPage(PageList.topupNew)}/>
  193. </Pressable>
  194. <ShadowView/>
  195. <Button
  196. style={styles.cardView}
  197. viewStyle={styles.cardItem}
  198. onClick={() => startPage(app.vehicle.newVersionPage ? PageList.vehiclesListV2 : PageList.myVehicles)}>
  199. {/* <Image
  200. style={styles.cardIcon}
  201. source={require('../../images/user/card-vehicle.png')}/> */}
  202. <View style={styles.cardInfo}>
  203. <TextView style={styles.cardLabel}>{$t('profile.myVehicles')}</TextView>
  204. {/* <TextView style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</TextView> */}
  205. </View>
  206. <FontAwesome
  207. size={24}
  208. color={textPrimary}
  209. name='angle-right'/>
  210. </Button>
  211. {/* <ShadowView/> */}
  212. <Button
  213. style={styles.cardView}
  214. viewStyle={styles.cardItem}
  215. onClick={() => {}}>
  216. <View style={styles.cardInfo}>
  217. <TextView style={styles.cardLabel}>{"Saved Cards"}</TextView>
  218. </View>
  219. <FontAwesome
  220. size={24}
  221. color={textPrimary}
  222. name='angle-right'/>
  223. </Button>
  224. {/* <ShadowView/> */}
  225. <Button
  226. style={styles.cardView}
  227. viewStyle={styles.cardItem}
  228. onClick={() => startPage(PageList.settings)}>
  229. <View style={styles.cardInfo}>
  230. <TextView style={styles.cardLabel}>{"App Settings"}</TextView>
  231. </View>
  232. <FontAwesome
  233. size={24}
  234. color={textPrimary}
  235. name='angle-right'/>
  236. </Button>
  237. {/* <ShadowView/> */}
  238. <Button
  239. style={styles.cardView}
  240. viewStyle={styles.profileItem}
  241. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  242. {/* <Image
  243. style={styles.cardIcon}
  244. source={require('../../images/user/card-account.png')}/> */}
  245. <View style={styles.cardInfo}>
  246. <TextView style={styles.cardLabel}>{$t('route.changePassword')}</TextView>
  247. </View>
  248. <FontAwesome
  249. size={24}
  250. color={textPrimary}
  251. name='angle-right'/>
  252. </Button>
  253. {/* <ShadowView/> */}
  254. <Button
  255. style={styles.cardView}
  256. viewStyle={styles.profileItem}
  257. onClick={() => startPage(PageList.feedback)}>
  258. {/* <MaterialCommunityIcons
  259. style={styles.cardIcon}
  260. name="message-alert-outline"
  261. color="#00638C"
  262. size={32}
  263. /> */}
  264. <View style={styles.cardInfo}>
  265. <TextView style={styles.cardLabel}>{$t('drawer.feedback')}</TextView>
  266. </View>
  267. <FontAwesome
  268. size={24}
  269. color={textPrimary}
  270. name='angle-right'/>
  271. </Button>
  272. {/* <ShadowView/> */}
  273. <Button
  274. style={styles.cardView}
  275. viewStyle={styles.cardItem}
  276. onClick={() => {}}>
  277. <View style={styles.cardInfo}>
  278. <TextView style={styles.cardLabel}>{"Contact Us"}</TextView>
  279. </View>
  280. <FontAwesome
  281. size={24}
  282. color={textPrimary}
  283. name='angle-right'/>
  284. </Button>
  285. {/* <ShadowView/> */}
  286. <Button
  287. style={styles.cardView}
  288. viewStyle={styles.profileItem}
  289. onClick={() => startPage(PageList.about)}>
  290. {/* <MaterialCommunityIcons
  291. style={styles.cardIcon}
  292. name="information-outline"
  293. color="#00638C"
  294. size={32}
  295. /> */}
  296. <View style={styles.cardInfo}>
  297. <TextView style={styles.cardLabel}>{$t('drawer.about')}</TextView>
  298. </View>
  299. <FontAwesome
  300. size={24}
  301. color={textPrimary}
  302. name='angle-right'/>
  303. </Button>
  304. {/* <ShadowView/> */}
  305. <Button
  306. style={styles.cardView}
  307. viewStyle={styles.cardItem}
  308. onClick={() => startPage(PageList.profile)}>
  309. <View style={styles.cardInfo}>
  310. <TextView style={styles.cardLabel}>{"Check For Updates"}</TextView>
  311. </View>
  312. <FontAwesome
  313. size={24}
  314. color={textPrimary}
  315. name='angle-right'/>
  316. </Button>
  317. {/* <ShadowView/> */}
  318. <Button
  319. style={styles.cardView}
  320. viewStyle={styles.profileItem}
  321. onClick={() => this.deleteAccount()}>
  322. {/* <MaterialCommunityIcons
  323. style={styles.cardIcon}
  324. name="account-remove"
  325. size={32}
  326. color="#00638C"/> */}
  327. <View style={styles.cardInfo}>
  328. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  329. </View>
  330. <FontAwesome
  331. size={24}
  332. color={textPrimary}
  333. name='angle-right'/>
  334. </Button>
  335. {/* <ShadowView/> */}
  336. <Button
  337. style={styles.deleteButton}
  338. text={'LOGOUT'}
  339. textColor={textLight}
  340. onClick={() => this.logout()}
  341. />
  342. <ShadowView/>
  343. <EndView/><EndView/>
  344. </ScrollView>
  345. );
  346. }
  347. }
  348. const styles = StyleSheet.create({
  349. container: {
  350. flex: 1,
  351. backgroundColor: pageBackground
  352. },
  353. headerView: {
  354. zIndex: 2,
  355. paddingTop: statusHeight,
  356. backgroundColor: colorPrimary
  357. },
  358. titleBar: {
  359. padding: 16,
  360. alignItems: 'center',
  361. flexDirection: 'row'
  362. },
  363. titleText: {
  364. color: textLight,
  365. fontSize: 20,
  366. fontWeight: 'bold'
  367. },
  368. profileHeader: {
  369. padding: 16,
  370. alignItems: 'center',
  371. flexDirection: 'row'
  372. },
  373. avatarImage: {
  374. width: 80,
  375. height: 80,
  376. borderWidth: 2,
  377. borderRadius: 80,
  378. borderColor: colorLight,
  379. backgroundColor: colorLight
  380. },
  381. infoContent: {
  382. flex: 1,
  383. paddingLeft: 16
  384. },
  385. nickname: {
  386. color: textLight,
  387. fontSize: 20,
  388. fontWeight: 'bold',
  389. paddingTop: 1,
  390. paddingBottom: 1
  391. },
  392. userText: {
  393. color: textLight,
  394. fontSize: 13,
  395. paddingTop: 4
  396. },
  397. countryLabel: {
  398. color: textLight,
  399. fontSize: 10,
  400. ...$padding(2, 8),
  401. marginLeft: 8,
  402. borderRadius: 4,
  403. backgroundColor: "#f8a300"
  404. },
  405. editButton: {
  406. marginTop: 8,
  407. borderRadius: 4,
  408. backgroundColor: colorLight
  409. },
  410. editButtonView: {
  411. width: 65,
  412. ...$padding(4, 10),
  413. alignItems: 'center',
  414. flexDirection: 'row'
  415. },
  416. circleButtomView: {
  417. zIndex: 1,
  418. marginTop: -$vw(30)
  419. },
  420. walletView: {
  421. zIndex: 2,
  422. padding: 12,
  423. paddingRight: 6,
  424. marginTop: -$vw(12),
  425. marginLeft: 16,
  426. marginRight: 16,
  427. borderWidth: 2,
  428. borderColor: colorPrimary,
  429. borderRadius: 6,
  430. alignItems: "center",
  431. flexDirection: "row",
  432. backgroundColor: colorLight,
  433. },
  434. walletIcon: {
  435. width: 48,
  436. height: 48
  437. },
  438. walletContent: {
  439. flex: 1,
  440. paddingLeft: 8
  441. },
  442. walletTitle: {
  443. color: textPrimary,
  444. fontSize: 14,
  445. paddingTop: 3
  446. },
  447. walletAmount: {
  448. color: colorPrimary,
  449. fontSize: 20,
  450. fontWeight: "bold",
  451. paddingTop: 2
  452. },
  453. topupButton: {
  454. marginTop: 8,
  455. borderRadius: 4,
  456. backgroundColor: colorPrimary
  457. },
  458. topupButtonView: {
  459. width: 65,
  460. alignItems: 'center',
  461. flexDirection: 'row',
  462. ...$padding(4, 8, 4, 10)
  463. },
  464. cardView: {
  465. zIndex: 2,
  466. //padding: 16,
  467. marginTop: 8,
  468. marginLeft: 16,
  469. marginRight: 16,
  470. borderRadius: 10,
  471. overflow: 'hidden',
  472. alignItems: 'center',
  473. flexDirection: 'row',
  474. borderWidth: 1,
  475. borderColor: "#DADADA",
  476. //...ElevationObject(2),
  477. backgroundColor: colorLight
  478. },
  479. cardItem: {
  480. padding: 16,
  481. alignItems: 'center',
  482. flexDirection: 'row',
  483. justifyContent: 'center',
  484. },
  485. cardIcon: {
  486. width: 32,
  487. height: 32
  488. },
  489. cardInfo: {
  490. flex: 1,
  491. //paddingLeft: 16,
  492. alignItems: 'center',
  493. flexDirection: 'row'
  494. },
  495. cardLabel: {
  496. color: textPrimary,
  497. fontSize: 12
  498. },
  499. deleteButton: {
  500. zIndex: 2,
  501. borderRadius: 4,
  502. backgroundColor: '#EA0A2A',
  503. ...$margin(16, 16, 0)
  504. }
  505. })