ProfileV2.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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. export default class ProfileV2 extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. userInfo: userInfo,
  21. refreshId: 0,
  22. totalVehicle: 0
  23. };
  24. }
  25. componentDidMount() {
  26. this.init();
  27. this.props.navigation.addListener('focus', () => {
  28. this.init();
  29. });
  30. }
  31. init() {
  32. getUserInfo(info => {
  33. this.setState({
  34. userInfo: info,
  35. refreshId: this.state.refreshId + 1
  36. });
  37. }, true);
  38. }
  39. deleteAccount() {
  40. Dialog.showDialog({
  41. title: $t('profile.deleteAccount'),
  42. message: $t('profile.confirmDeleteAccount'),
  43. ok: $t('nav.confirm'),
  44. callback: button => {
  45. if (button == Dialog.BUTTON_OK) {
  46. this.deleteMyAccount();
  47. }
  48. }
  49. })
  50. }
  51. deleteMyAccount() {
  52. Dialog.showProgressDialog();
  53. apiUser.deleteAccount().then(res => {
  54. toastShort($t('profile.deleteAccountSuccess'))
  55. Dialog.dismissLoading();
  56. this.requestLogout();
  57. /*setTimeout(() => {
  58. startPage(PageList.login);
  59. }, 500);*/
  60. }).catch(err => {
  61. Dialog.dismissLoading();
  62. toastShort(err)
  63. })
  64. }
  65. logout() {
  66. Dialog.showDialog({
  67. title: $t('profile.signOut'),
  68. message: $t('profile.tipSignOut'),
  69. callback: btn => {
  70. if (btn == Dialog.BUTTON_OK) {
  71. Dialog.showProgressDialog();
  72. setTimeout(() => {
  73. this.requestLogout();
  74. }, 500);
  75. }
  76. }
  77. })
  78. }
  79. async requestLogout() {
  80. const data = await getStorageJsonSync('loginData');
  81. if (data && data.email) {
  82. delete data.password
  83. setStorageJson('loginData', data);
  84. setStorage('RegisterTokenDate', "");
  85. }
  86. global.userInfo = {}
  87. /*this.setState({
  88. isLogin: false,
  89. userInfo: {}
  90. });*/
  91. setAccessToken('');
  92. goBack();
  93. Dialog.dismissLoading();
  94. }
  95. render() {
  96. return (
  97. <ScrollView style={styles.container}>
  98. {/* Profile Info */}
  99. <Button
  100. style={styles.cardView}
  101. viewStyle={styles.profileView}
  102. android_ripple={ripple}
  103. onClick={() => startPage(PageList.editProfile)}>
  104. { this.state.userInfo.photoUrl
  105. ? <Image
  106. style={styles.avatar}
  107. source={{uri: utils.getImageUrl(this.state.userInfo.photoUrl)}}/>
  108. : <Image
  109. style={styles.avatar}
  110. source={require('../../images/user/ic-avatar-default.png')}/>
  111. }
  112. <View style={styles.infoContent}>
  113. <TextView
  114. style={styles.nickname}
  115. ellipsizeMode='tail'
  116. numberOfLines={1}>{this.state.userInfo.nickName}</TextView>
  117. <TextView style={styles.userText}>{this.state.userInfo.email}</TextView>
  118. <TextView style={styles.userText}>{(utils.isNotEmpty(this.state.userInfo.callingCode) && "+" + this.state.userInfo.callingCode + " ") + this.state.userInfo.phone}</TextView>
  119. <View style={styles.userTypeView}>
  120. { this.state.userInfo.userType?.split(";").map((item, index) => {
  121. return <TextView key={index} style={styles.userTypeText}>{item}</TextView>
  122. })
  123. }
  124. </View>
  125. </View>
  126. <FontAwesome
  127. size={34}
  128. color={textCancel}
  129. name='angle-right'/>
  130. </Button>
  131. {/* Wallet Info */}
  132. <Button
  133. style={styles.cardView}
  134. viewStyle={styles.profileItem}
  135. onClick={() => startPage(PageList.wallet)}>
  136. <Image
  137. style={styles.cardIcon}
  138. source={require('../../images/user/card-wallet.png')}/>
  139. <View style={styles.cardInfo}>
  140. <TextView style={styles.cardLabel}>{$t('wallet.creditWalletLabel')}</TextView>
  141. <TextView style={styles.cardPrimary}>{this.state.userInfo.creditStr}</TextView>
  142. </View>
  143. <FontAwesome
  144. size={28}
  145. color={textCancel}
  146. name='angle-right'/>
  147. </Button>
  148. {/* Vehicle Info */}
  149. <Button
  150. style={styles.cardView}
  151. viewStyle={styles.profileItem}
  152. onClick={() => startPage(app.vehicle.newVersionPage ? PageList.vehiclesListV2 : PageList.myVehicles)}>
  153. <Image
  154. style={styles.cardIcon}
  155. source={require('../../images/user/card-vehicle.png')}/>
  156. <View style={styles.cardInfo}>
  157. <TextView style={styles.cardLabel}>{$t('profile.myVehicles')}</TextView>
  158. <TextView style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</TextView>
  159. </View>
  160. <FontAwesome
  161. size={28}
  162. color={textCancel}
  163. name='angle-right'/>
  164. </Button>
  165. { app.modules.vouchers &&
  166. <Button
  167. style={styles.cardView}
  168. viewStyle={styles.profileItem}
  169. onClick={() => startPage(PageList.myVoucher)}>
  170. <MaterialIcons
  171. style={styles.cardIcon}
  172. name="discount"
  173. size={32}
  174. color="#00638C"/>
  175. <View style={styles.cardInfo}>
  176. <TextView style={styles.cardLabel}>{$t('voucher.myVouchers')}</TextView>
  177. </View>
  178. <FontAwesome
  179. size={28}
  180. color={textCancel}
  181. name='angle-right'/>
  182. </Button>
  183. }
  184. {/* Vehicle List */}
  185. {/* <View style={styles.titleView}>
  186. <Text style={styles.title}>{$t('profile.myVehicles')}</Text>
  187. <Button
  188. style={{backgroundColor: colorLight}}
  189. borderRadius={3}
  190. viewStyle={styles.titleAdd}
  191. onClick={() => {
  192. startPage(PageList.addVehicle)
  193. }}>
  194. <Entypo name='plus' size={14} color={colorDark}/>
  195. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  196. </Button>
  197. </View> */}
  198. {/* <View style={styles.verhicleList}>
  199. <VehicleList
  200. refreshId={this.state.refreshId}
  201. onResult={count => {
  202. this.setState({
  203. totalVehicle: count
  204. })
  205. }}
  206. onDelete={id => this.removeVehicle(id)}
  207. />
  208. </View> */}
  209. {/* Account List */}
  210. {/* <View style={styles.titleView}>
  211. <Text style={styles.title}>My Cards</Text>
  212. <Button
  213. textColor={textPrimary}
  214. style={styles.titleAdd}
  215. onClick={() => {
  216. startPage(PageList.addCard)
  217. }}>
  218. <Entypo name='plus' size={14} color={colorDark}/>
  219. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  220. </Button>
  221. </View>
  222. <View style={styles.accountList}>
  223. <CardList refreshId={this.state.refreshId}/>
  224. </View> */}
  225. <Button
  226. style={styles.cardView}
  227. viewStyle={styles.profileItem}
  228. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  229. <Image
  230. style={styles.cardIcon}
  231. source={require('../../images/user/card-account.png')}/>
  232. <View style={styles.cardInfo}>
  233. <TextView style={styles.cardLabel}>{$t('route.changePassword')}</TextView>
  234. </View>
  235. <FontAwesome
  236. size={28}
  237. color={textCancel}
  238. name='angle-right'/>
  239. </Button>
  240. {/* Notifications */}
  241. { !app.v3.drawer &&
  242. <Button
  243. style={styles.cardView}
  244. viewStyle={styles.profileItem}
  245. onClick={() => startPage(PageList.settings)}>
  246. <Image
  247. style={styles.cardIcon}
  248. source={require('../../images/user/card-notification.png')}/>
  249. <View style={styles.cardInfo}>
  250. <TextView style={styles.cardLabel}>{$t('profile.notificationSettings')}</TextView>
  251. </View>
  252. <FontAwesome
  253. size={28}
  254. color={textCancel}
  255. name='angle-right'/>
  256. </Button>
  257. }
  258. { (app.modules.apply_phv && this.state.userInfo.userType.toLowerCase() == "public") &&
  259. <Button
  260. style={styles.cardView}
  261. viewStyle={styles.profileItem}
  262. onClick={() => startPage(PageList.registerFleet)}>
  263. <MaterialCommunityIcons
  264. style={styles.cardIcon}
  265. name="credit-card-edit"
  266. size={32}
  267. color="#00638C"/>
  268. <View style={styles.cardInfo}>
  269. <TextView style={styles.cardLabel}>{$t('profile.apply2Fleet')}</TextView>
  270. </View>
  271. <FontAwesome
  272. size={28}
  273. color={textCancel}
  274. name='angle-right'/>
  275. </Button>
  276. }
  277. <Button
  278. style={styles.cardView}
  279. viewStyle={styles.profileItem}
  280. onClick={() => this.deleteAccount()}>
  281. <MaterialCommunityIcons
  282. style={styles.cardIcon}
  283. name="account-remove"
  284. size={32}
  285. color="#00638C"/>
  286. <View style={styles.cardInfo}>
  287. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  288. </View>
  289. <FontAwesome
  290. size={28}
  291. color={textCancel}
  292. name='angle-right'/>
  293. </Button>
  294. { app.v3.drawer && <>
  295. <Button
  296. style={styles.cardView}
  297. viewStyle={styles.profileItem}
  298. onClick={() => startPage(PageList.feedback)}>
  299. <MaterialCommunityIcons
  300. style={styles.cardIcon}
  301. name="message-alert-outline"
  302. color="#00638C"
  303. size={32}
  304. />
  305. <View style={styles.cardInfo}>
  306. <TextView style={styles.cardLabel}>{$t('drawer.feedback')}</TextView>
  307. </View>
  308. <FontAwesome
  309. size={28}
  310. color={textCancel}
  311. name='angle-right'/>
  312. </Button>
  313. <Button
  314. style={styles.cardView}
  315. viewStyle={styles.profileItem}
  316. onClick={() => startPage(PageList.settings)}>
  317. <MaterialIcons
  318. style={styles.cardIcon}
  319. name="settings"
  320. color="#00638C"
  321. size={32}
  322. />
  323. <View style={styles.cardInfo}>
  324. <TextView style={styles.cardLabel}>{$t('drawer.settings')}</TextView>
  325. </View>
  326. <FontAwesome
  327. size={28}
  328. color={textCancel}
  329. name='angle-right'/>
  330. </Button>
  331. <Button
  332. style={styles.cardView}
  333. viewStyle={styles.profileItem}
  334. onClick={() => startPage(PageList.about)}>
  335. <MaterialCommunityIcons
  336. style={styles.cardIcon}
  337. name="information-outline"
  338. color="#00638C"
  339. size={32}
  340. />
  341. <View style={styles.cardInfo}>
  342. <TextView style={styles.cardLabel}>{$t('drawer.about')}</TextView>
  343. </View>
  344. <FontAwesome
  345. size={28}
  346. color={textCancel}
  347. name='angle-right'/>
  348. </Button>
  349. </>}
  350. {/* <Button
  351. style={styles.deleteButton}
  352. text="DELETE MY ACCOUNT"
  353. textColor={textButton}
  354. onClick={() => this.deleteAccount()}
  355. /> */}
  356. <Button
  357. style={styles.deleteButton}
  358. text={$t('profile.logout')}
  359. textColor={textLight}
  360. onClick={() => this.logout()}
  361. />
  362. </ScrollView>
  363. );
  364. }
  365. }
  366. const styles = StyleSheet.create({
  367. container: {
  368. flex: 1,
  369. backgroundColor: pageBackground
  370. },
  371. headerView: {
  372. paddingBottom: 72
  373. },
  374. background: {
  375. left: 0,
  376. right: 0,
  377. bottom: 0,
  378. height: $vw(62.4),
  379. alignItems: 'center',
  380. position: 'absolute'
  381. },
  382. profileView: {
  383. zIndex: 10,
  384. padding: 16,
  385. alignItems: 'center',
  386. flexDirection: 'row'
  387. },
  388. avatar: {
  389. width: 66,
  390. height: 66,
  391. borderWidth: 2,
  392. borderRadius: 80,
  393. borderColor: "#00638C"
  394. },
  395. infoContent: {
  396. flex: 1,
  397. paddingLeft: 16,
  398. },
  399. nickname: {
  400. color: '#000',
  401. fontSize: 20,
  402. fontWeight: 'bold',
  403. paddingTop: 1,
  404. paddingBottom: 1,
  405. },
  406. userText: {
  407. color: textPrimary,
  408. fontSize: 13,
  409. paddingTop: 1.5
  410. },
  411. cardView: {
  412. //padding: 16,
  413. marginTop: 16,
  414. marginLeft: 16,
  415. marginRight: 16,
  416. borderRadius: 10,
  417. overflow: 'hidden',
  418. ...ElevationObject(5),
  419. alignItems: 'center',
  420. flexDirection: 'row',
  421. backgroundColor: colorLight,
  422. },
  423. profileItem: {
  424. padding: 16,
  425. alignItems: 'center',
  426. flexDirection: 'row',
  427. justifyContent: 'center',
  428. },
  429. cardItem: {
  430. flex: 1,
  431. alignItems: 'center',
  432. flexDirection: 'row',
  433. justifyContent: 'center'
  434. },
  435. cardDivide: {
  436. borderLeftWidth: 1,
  437. borderLeftColor: '#EEE'
  438. },
  439. cardIcon: {
  440. width: 32,
  441. height: 32
  442. },
  443. cardInfo: {
  444. flex: 1,
  445. paddingLeft: 16,
  446. alignItems: 'center',
  447. flexDirection: 'row'
  448. },
  449. cardPrimary: {
  450. color: textPrimary,
  451. fontSize: 18
  452. },
  453. cardLabel: {
  454. color: textPrimary,
  455. fontSize: 16,
  456. fontWeight: 'bold'
  457. },
  458. titleView: {
  459. padding: 12,
  460. alignItems: 'center',
  461. flexDirection: 'row'
  462. },
  463. title: {
  464. flex: 1,
  465. padding: 8,
  466. color: '#000',
  467. fontSize: 16,
  468. },
  469. titleAdd: {
  470. padding: 8,
  471. color: textPrimary,
  472. alignItems: 'center',
  473. flexDirection: 'row'
  474. },
  475. verhicleList: {
  476. paddingLeft: 16,
  477. paddingRight: 16,
  478. marginBottom: -16
  479. },
  480. accountList: {
  481. paddingLeft: 16,
  482. paddingRight: 16,
  483. marginBottom: -16
  484. },
  485. notificationView: {
  486. marginLeft: 16,
  487. marginRight: 16,
  488. marginBottom: 20,
  489. borderRadius: 10,
  490. overflow: 'hidden',
  491. paddingLeft: 16,
  492. paddingRight: 16,
  493. borderColor: '#f5f5f5',
  494. borderWidth: 1,
  495. backgroundColor: colorLight,
  496. ...ElevationObject(1.5)
  497. },
  498. notificationItem: {
  499. paddingTop: 16,
  500. paddingBottom: 16,
  501. alignItems: 'center',
  502. flexDirection: 'row'
  503. },
  504. notiLabel: {
  505. flex: 1,
  506. color: textPrimary,
  507. fontSize: 14
  508. },
  509. divide: {
  510. borderTopWidth: 1,
  511. borderTopColor: '#eee'
  512. },
  513. deleteButton: {
  514. ...$margin(48, 16, 16),
  515. backgroundColor: '#EA0A2A'
  516. },
  517. userTypeView: {
  518. paddingTop: 2,
  519. alignItems: 'center',
  520. flexDirection: 'row'
  521. },
  522. userTypeText: {
  523. color: textLight,
  524. fontSize: 8,
  525. marginRight: 4,
  526. borderRadius: 2,
  527. textAlign: "center",
  528. ...$padding(2, 4),
  529. backgroundColor: colorAccent
  530. }
  531. })