ProfileV3.js 14 KB

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