ProfileV2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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 { host, 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: host + 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(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. <Button
  223. style={styles.cardView}
  224. viewStyle={styles.profileItem}
  225. onClick={() => startPage(PageList.settings)}>
  226. <Image
  227. style={styles.cardIcon}
  228. source={require('../../images/user/card-notification.png')}/>
  229. <View style={styles.cardInfo}>
  230. <TextView style={styles.cardLabel}>{$t('profile.notificationSettings')}</TextView>
  231. </View>
  232. <FontAwesome
  233. size={28}
  234. color={textCancel}
  235. name='angle-right'/>
  236. </Button>
  237. { (!app.modules.membership && this.state.userInfo.userType.toLowerCase() == "public") &&
  238. <Button
  239. style={styles.cardView}
  240. viewStyle={styles.profileItem}
  241. onClick={() => startPage(PageList.registerFleet)}>
  242. <MaterialCommunityIcons
  243. style={styles.cardIcon}
  244. name="credit-card-edit"
  245. size={32}
  246. color="#00638C"/>
  247. <View style={styles.cardInfo}>
  248. <TextView style={styles.cardLabel}>{$t('profile.apply2Fleet')}</TextView>
  249. </View>
  250. <FontAwesome
  251. size={28}
  252. color={textCancel}
  253. name='angle-right'/>
  254. </Button>
  255. }
  256. <Button
  257. style={styles.cardView}
  258. viewStyle={styles.profileItem}
  259. onClick={() => this.deleteAccount()}>
  260. <MaterialCommunityIcons
  261. style={styles.cardIcon}
  262. name="account-remove"
  263. size={32}
  264. color="#00638C"/>
  265. <View style={styles.cardInfo}>
  266. <TextView style={styles.cardLabel}>{$t('profile.deleteAccount')}</TextView>
  267. </View>
  268. <FontAwesome
  269. size={28}
  270. color={textCancel}
  271. name='angle-right'/>
  272. </Button>
  273. {/* <Button
  274. style={styles.deleteButton}
  275. text="DELETE MY ACCOUNT"
  276. textColor={textButton}
  277. onClick={() => this.deleteAccount()}
  278. /> */}
  279. <Button
  280. style={styles.deleteButton}
  281. text={$t('profile.logout')}
  282. textColor={textButton}
  283. onClick={() => this.logout()}
  284. />
  285. </ScrollView>
  286. );
  287. }
  288. }
  289. const styles = StyleSheet.create({
  290. container: {
  291. flex: 1,
  292. backgroundColor: pageBackground
  293. },
  294. headerView: {
  295. paddingBottom: 72
  296. },
  297. background: {
  298. left: 0,
  299. right: 0,
  300. bottom: 0,
  301. height: $vw(62.4),
  302. alignItems: 'center',
  303. position: 'absolute'
  304. },
  305. profileView: {
  306. zIndex: 10,
  307. padding: 16,
  308. alignItems: 'center',
  309. flexDirection: 'row'
  310. },
  311. avatar: {
  312. width: 66,
  313. height: 66,
  314. borderWidth: 2,
  315. borderRadius: 80,
  316. borderColor: "#00638C"
  317. },
  318. infoContent: {
  319. flex: 1,
  320. paddingLeft: 16,
  321. },
  322. nickname: {
  323. color: '#000',
  324. fontSize: 20,
  325. fontWeight: 'bold',
  326. paddingTop: 1,
  327. paddingBottom: 1,
  328. },
  329. userText: {
  330. color: textPrimary,
  331. fontSize: 13,
  332. paddingTop: 1.5
  333. },
  334. cardView: {
  335. //padding: 16,
  336. marginTop: 16,
  337. marginLeft: 16,
  338. marginRight: 16,
  339. borderRadius: 10,
  340. overflow: 'hidden',
  341. ...ElevationObject(5),
  342. alignItems: 'center',
  343. flexDirection: 'row',
  344. backgroundColor: colorLight,
  345. },
  346. profileItem: {
  347. padding: 16,
  348. alignItems: 'center',
  349. flexDirection: 'row',
  350. justifyContent: 'center',
  351. },
  352. cardItem: {
  353. flex: 1,
  354. alignItems: 'center',
  355. flexDirection: 'row',
  356. justifyContent: 'center'
  357. },
  358. cardDivide: {
  359. borderLeftWidth: 1,
  360. borderLeftColor: '#EEE'
  361. },
  362. cardIcon: {
  363. width: 32,
  364. height: 32
  365. },
  366. cardInfo: {
  367. flex: 1,
  368. paddingLeft: 16,
  369. alignItems: 'center',
  370. flexDirection: 'row'
  371. },
  372. cardPrimary: {
  373. color: textPrimary,
  374. fontSize: 18
  375. },
  376. cardLabel: {
  377. color: textPrimary,
  378. fontSize: 16,
  379. fontWeight: 'bold'
  380. },
  381. titleView: {
  382. padding: 12,
  383. alignItems: 'center',
  384. flexDirection: 'row'
  385. },
  386. title: {
  387. flex: 1,
  388. padding: 8,
  389. color: '#000',
  390. fontSize: 16,
  391. },
  392. titleAdd: {
  393. padding: 8,
  394. color: textPrimary,
  395. alignItems: 'center',
  396. flexDirection: 'row'
  397. },
  398. verhicleList: {
  399. paddingLeft: 16,
  400. paddingRight: 16,
  401. marginBottom: -16
  402. },
  403. accountList: {
  404. paddingLeft: 16,
  405. paddingRight: 16,
  406. marginBottom: -16
  407. },
  408. notificationView: {
  409. marginLeft: 16,
  410. marginRight: 16,
  411. marginBottom: 20,
  412. borderRadius: 10,
  413. overflow: 'hidden',
  414. paddingLeft: 16,
  415. paddingRight: 16,
  416. borderColor: '#f5f5f5',
  417. borderWidth: 1,
  418. backgroundColor: colorLight,
  419. ...ElevationObject(1.5)
  420. },
  421. notificationItem: {
  422. paddingTop: 16,
  423. paddingBottom: 16,
  424. alignItems: 'center',
  425. flexDirection: 'row'
  426. },
  427. notiLabel: {
  428. flex: 1,
  429. color: textPrimary,
  430. fontSize: 14
  431. },
  432. divide: {
  433. borderTopWidth: 1,
  434. borderTopColor: '#eee'
  435. },
  436. deleteButton: {
  437. ...$margin(48, 16, 16),
  438. backgroundColor: '#EA0A2A'
  439. },
  440. userTypeView: {
  441. paddingTop: 2,
  442. alignItems: 'center',
  443. flexDirection: 'row'
  444. },
  445. userTypeText: {
  446. color: textLight,
  447. fontSize: 8,
  448. marginRight: 4,
  449. borderRadius: 2,
  450. textAlign: "center",
  451. ...$padding(2, 4),
  452. backgroundColor: colorAccent
  453. }
  454. })