ProfileV2.js 15 KB

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