ProfileV2.js 15 KB

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