ProfileV2.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. {/* Vehicle List */}
  166. {/* <View style={styles.titleView}>
  167. <Text style={styles.title}>{$t('profile.myVehicles')}</Text>
  168. <Button
  169. style={{backgroundColor: colorLight}}
  170. borderRadius={3}
  171. viewStyle={styles.titleAdd}
  172. onClick={() => {
  173. startPage(PageList.addVehicle)
  174. }}>
  175. <Entypo name='plus' size={14} color={colorDark}/>
  176. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  177. </Button>
  178. </View> */}
  179. {/* <View style={styles.verhicleList}>
  180. <VehicleList
  181. refreshId={this.state.refreshId}
  182. onResult={count => {
  183. this.setState({
  184. totalVehicle: count
  185. })
  186. }}
  187. onDelete={id => this.removeVehicle(id)}
  188. />
  189. </View> */}
  190. {/* Account List */}
  191. {/* <View style={styles.titleView}>
  192. <Text style={styles.title}>My Cards</Text>
  193. <Button
  194. textColor={textPrimary}
  195. style={styles.titleAdd}
  196. onClick={() => {
  197. startPage(PageList.addCard)
  198. }}>
  199. <Entypo name='plus' size={14} color={colorDark}/>
  200. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  201. </Button>
  202. </View>
  203. <View style={styles.accountList}>
  204. <CardList refreshId={this.state.refreshId}/>
  205. </View> */}
  206. <Button
  207. style={styles.cardView}
  208. viewStyle={styles.profileItem}
  209. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  210. <Image
  211. style={styles.cardIcon}
  212. source={require('../../images/user/card-account.png')}/>
  213. <View style={styles.cardInfo}>
  214. <TextView style={styles.cardLabel}>{$t('route.changePassword')}</TextView>
  215. </View>
  216. <FontAwesome
  217. size={28}
  218. color={textCancel}
  219. name='angle-right'/>
  220. </Button>
  221. {/* Notifications */}
  222. { !app.v3.drawer &&
  223. <Button
  224. style={styles.cardView}
  225. viewStyle={styles.profileItem}
  226. onClick={() => startPage(PageList.settings)}>
  227. <Image
  228. style={styles.cardIcon}
  229. source={require('../../images/user/card-notification.png')}/>
  230. <View style={styles.cardInfo}>
  231. <TextView style={styles.cardLabel}>{$t('profile.notificationSettings')}</TextView>
  232. </View>
  233. <FontAwesome
  234. size={28}
  235. color={textCancel}
  236. name='angle-right'/>
  237. </Button>
  238. }
  239. { (app.modules.apply_phv && this.state.userInfo.userType.toLowerCase() == "public") &&
  240. <Button
  241. style={styles.cardView}
  242. viewStyle={styles.profileItem}
  243. onClick={() => startPage(PageList.registerFleet)}>
  244. <MaterialCommunityIcons
  245. style={styles.cardIcon}
  246. name="credit-card-edit"
  247. size={32}
  248. color="#00638C"/>
  249. <View style={styles.cardInfo}>
  250. <TextView style={styles.cardLabel}>{$t('profile.apply2Fleet')}</TextView>
  251. </View>
  252. <FontAwesome
  253. size={28}
  254. color={textCancel}
  255. name='angle-right'/>
  256. </Button>
  257. }
  258. <Button
  259. style={styles.cardView}
  260. viewStyle={styles.profileItem}
  261. onClick={() => this.deleteAccount()}>
  262. <MaterialCommunityIcons
  263. style={styles.cardIcon}
  264. name="account-remove"
  265. size={32}
  266. color="#00638C"/>
  267. <View style={styles.cardInfo}>
  268. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  269. </View>
  270. <FontAwesome
  271. size={28}
  272. color={textCancel}
  273. name='angle-right'/>
  274. </Button>
  275. { app.v3.drawer && <>
  276. <Button
  277. style={styles.cardView}
  278. viewStyle={styles.profileItem}
  279. onClick={() => startPage(PageList.feedback)}>
  280. <MaterialCommunityIcons
  281. style={styles.cardIcon}
  282. name="message-alert-outline"
  283. color="#00638C"
  284. size={32}
  285. />
  286. <View style={styles.cardInfo}>
  287. <TextView style={styles.cardLabel}>{$t('drawer.feedback')}</TextView>
  288. </View>
  289. <FontAwesome
  290. size={28}
  291. color={textCancel}
  292. name='angle-right'/>
  293. </Button>
  294. <Button
  295. style={styles.cardView}
  296. viewStyle={styles.profileItem}
  297. onClick={() => startPage(PageList.settings)}>
  298. <MaterialIcons
  299. style={styles.cardIcon}
  300. name="settings"
  301. color="#00638C"
  302. size={32}
  303. />
  304. <View style={styles.cardInfo}>
  305. <TextView style={styles.cardLabel}>{$t('drawer.settings')}</TextView>
  306. </View>
  307. <FontAwesome
  308. size={28}
  309. color={textCancel}
  310. name='angle-right'/>
  311. </Button>
  312. <Button
  313. style={styles.cardView}
  314. viewStyle={styles.profileItem}
  315. onClick={() => startPage(PageList.about)}>
  316. <MaterialCommunityIcons
  317. style={styles.cardIcon}
  318. name="information-outline"
  319. color="#00638C"
  320. size={32}
  321. />
  322. <View style={styles.cardInfo}>
  323. <TextView style={styles.cardLabel}>{$t('drawer.about')}</TextView>
  324. </View>
  325. <FontAwesome
  326. size={28}
  327. color={textCancel}
  328. name='angle-right'/>
  329. </Button>
  330. </>}
  331. {/* <Button
  332. style={styles.deleteButton}
  333. text="DELETE MY ACCOUNT"
  334. textColor={textButton}
  335. onClick={() => this.deleteAccount()}
  336. /> */}
  337. <Button
  338. style={styles.deleteButton}
  339. text={$t('profile.logout')}
  340. textColor={textLight}
  341. onClick={() => this.logout()}
  342. />
  343. </ScrollView>
  344. );
  345. }
  346. }
  347. const styles = StyleSheet.create({
  348. container: {
  349. flex: 1,
  350. backgroundColor: pageBackground
  351. },
  352. headerView: {
  353. paddingBottom: 72
  354. },
  355. background: {
  356. left: 0,
  357. right: 0,
  358. bottom: 0,
  359. height: $vw(62.4),
  360. alignItems: 'center',
  361. position: 'absolute'
  362. },
  363. profileView: {
  364. zIndex: 10,
  365. padding: 16,
  366. alignItems: 'center',
  367. flexDirection: 'row'
  368. },
  369. avatar: {
  370. width: 66,
  371. height: 66,
  372. borderWidth: 2,
  373. borderRadius: 80,
  374. borderColor: "#00638C"
  375. },
  376. infoContent: {
  377. flex: 1,
  378. paddingLeft: 16,
  379. },
  380. nickname: {
  381. color: '#000',
  382. fontSize: 20,
  383. fontWeight: 'bold',
  384. paddingTop: 1,
  385. paddingBottom: 1,
  386. },
  387. userText: {
  388. color: textPrimary,
  389. fontSize: 13,
  390. paddingTop: 1.5
  391. },
  392. cardView: {
  393. //padding: 16,
  394. marginTop: 16,
  395. marginLeft: 16,
  396. marginRight: 16,
  397. borderRadius: 10,
  398. overflow: 'hidden',
  399. ...ElevationObject(5),
  400. alignItems: 'center',
  401. flexDirection: 'row',
  402. backgroundColor: colorLight,
  403. },
  404. profileItem: {
  405. padding: 16,
  406. alignItems: 'center',
  407. flexDirection: 'row',
  408. justifyContent: 'center',
  409. },
  410. cardItem: {
  411. flex: 1,
  412. alignItems: 'center',
  413. flexDirection: 'row',
  414. justifyContent: 'center'
  415. },
  416. cardDivide: {
  417. borderLeftWidth: 1,
  418. borderLeftColor: '#EEE'
  419. },
  420. cardIcon: {
  421. width: 32,
  422. height: 32
  423. },
  424. cardInfo: {
  425. flex: 1,
  426. paddingLeft: 16,
  427. alignItems: 'center',
  428. flexDirection: 'row'
  429. },
  430. cardPrimary: {
  431. color: textPrimary,
  432. fontSize: 18
  433. },
  434. cardLabel: {
  435. color: textPrimary,
  436. fontSize: 16,
  437. fontWeight: 'bold'
  438. },
  439. titleView: {
  440. padding: 12,
  441. alignItems: 'center',
  442. flexDirection: 'row'
  443. },
  444. title: {
  445. flex: 1,
  446. padding: 8,
  447. color: '#000',
  448. fontSize: 16,
  449. },
  450. titleAdd: {
  451. padding: 8,
  452. color: textPrimary,
  453. alignItems: 'center',
  454. flexDirection: 'row'
  455. },
  456. verhicleList: {
  457. paddingLeft: 16,
  458. paddingRight: 16,
  459. marginBottom: -16
  460. },
  461. accountList: {
  462. paddingLeft: 16,
  463. paddingRight: 16,
  464. marginBottom: -16
  465. },
  466. notificationView: {
  467. marginLeft: 16,
  468. marginRight: 16,
  469. marginBottom: 20,
  470. borderRadius: 10,
  471. overflow: 'hidden',
  472. paddingLeft: 16,
  473. paddingRight: 16,
  474. borderColor: '#f5f5f5',
  475. borderWidth: 1,
  476. backgroundColor: colorLight,
  477. ...ElevationObject(1.5)
  478. },
  479. notificationItem: {
  480. paddingTop: 16,
  481. paddingBottom: 16,
  482. alignItems: 'center',
  483. flexDirection: 'row'
  484. },
  485. notiLabel: {
  486. flex: 1,
  487. color: textPrimary,
  488. fontSize: 14
  489. },
  490. divide: {
  491. borderTopWidth: 1,
  492. borderTopColor: '#eee'
  493. },
  494. deleteButton: {
  495. ...$margin(48, 16, 16),
  496. backgroundColor: '#EA0A2A'
  497. },
  498. userTypeView: {
  499. paddingTop: 2,
  500. alignItems: 'center',
  501. flexDirection: 'row'
  502. },
  503. userTypeText: {
  504. color: textLight,
  505. fontSize: 8,
  506. marginRight: 4,
  507. borderRadius: 2,
  508. textAlign: "center",
  509. ...$padding(2, 4),
  510. backgroundColor: colorAccent
  511. }
  512. })