ProfileV3.js 14 KB

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