ProfileV3.js 14 KB

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