ProfileV2.js 15 KB

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