ProfileV2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /**
  2. * Profile Settings页面
  3. * @邠心vbe on 2021/04/27
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, 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 { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
  12. import utils from '../../utils/utils';
  13. import { PageList } from '../Router';
  14. export default class ProfileV2 extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. userInfo: userInfo,
  19. refreshId: 0,
  20. totalVehicle: 0
  21. };
  22. }
  23. componentDidMount() {
  24. this.init();
  25. this.props.navigation.addListener('focus', () => {
  26. this.init();
  27. });
  28. }
  29. init() {
  30. getUserInfo(info => {
  31. this.setState({
  32. userInfo: info,
  33. refreshId: this.state.refreshId + 1
  34. });
  35. }, true);
  36. }
  37. deleteAccount() {
  38. Dialog.showDialog({
  39. title: $t('profile.deleteAccount'),
  40. message: $t('profile.confirmDeleteAccount'),
  41. ok: $t('nav.confirm'),
  42. callback: button => {
  43. if (button == Dialog.BUTTON_OK) {
  44. this.deleteMyAccount();
  45. }
  46. }
  47. })
  48. }
  49. deleteMyAccount() {
  50. Dialog.showProgressDialog();
  51. apiUser.deleteAccount().then(res => {
  52. toastShort($t('profile.deleteAccountSuccess'))
  53. Dialog.dismissLoading();
  54. this.requestLogout();
  55. /*setTimeout(() => {
  56. startPage(PageList.login);
  57. }, 500);*/
  58. }).catch(err => {
  59. Dialog.dismissLoading();
  60. toastShort(err)
  61. })
  62. }
  63. logout() {
  64. Dialog.showDialog({
  65. title: $t('profile.signOut'),
  66. message: $t('profile.tipSignOut'),
  67. callback: btn => {
  68. if (btn == Dialog.BUTTON_OK) {
  69. Dialog.showProgressDialog();
  70. setTimeout(() => {
  71. this.requestLogout();
  72. }, 500);
  73. }
  74. }
  75. })
  76. }
  77. async requestLogout() {
  78. const data = await getStorageJsonSync('loginData');
  79. if (data && data.email) {
  80. delete data.password
  81. setStorageJson('loginData', data);
  82. setStorage('RegisterTokenDate', "");
  83. }
  84. global.userInfo = {}
  85. /*this.setState({
  86. isLogin: false,
  87. userInfo: {}
  88. });*/
  89. setAccessToken('');
  90. goBack();
  91. Dialog.dismissLoading();
  92. }
  93. render() {
  94. return (
  95. <ScrollView style={styles.container}>
  96. {/* Profile Info */}
  97. <Button
  98. style={styles.cardView}
  99. viewStyle={styles.profileView}
  100. android_ripple={ripple}
  101. onClick={() => startPage(PageList.editProfile)}>
  102. { this.state.userInfo.photoUrl
  103. ? <Image
  104. style={styles.avatar}
  105. source={{uri: host + this.state.userInfo.photoUrl}}/>
  106. : <Image
  107. style={styles.avatar}
  108. source={require('../../images/user/ic-avatar-default.png')}/>
  109. }
  110. <View style={styles.infoContent}>
  111. <Text
  112. style={styles.nickname}
  113. ellipsizeMode='tail'
  114. numberOfLines={1}>{this.state.userInfo.nickName}</Text>
  115. <Text style={styles.userText}>{this.state.userInfo.email}</Text>
  116. <Text style={styles.userText}>{(utils.isNotEmpty(this.state.userInfo.callingCode) && "+" + this.state.userInfo.callingCode + " ") + this.state.userInfo.phone}</Text>
  117. </View>
  118. <FontAwesome
  119. size={34}
  120. color={textCancel}
  121. name='angle-right'/>
  122. </Button>
  123. {/* Wallet Info */}
  124. <Button
  125. style={styles.cardView}
  126. viewStyle={styles.profileItem}
  127. onClick={() => startPage(PageList.wallet)}>
  128. <Image
  129. style={styles.cardIcon}
  130. source={require('../../images/user/card-wallet.png')}/>
  131. <View style={styles.cardInfo}>
  132. <Text style={styles.cardLabel}>{$t('wallet.creditWalletLabel')}</Text>
  133. <Text style={styles.cardPrimary}>{currency}{this.state.userInfo.credit}</Text>
  134. </View>
  135. <FontAwesome
  136. size={28}
  137. color={textCancel}
  138. name='angle-right'/>
  139. </Button>
  140. {/* Vehicle Info */}
  141. <Button
  142. style={styles.cardView}
  143. viewStyle={styles.profileItem}
  144. onClick={() => startPage(PageList.myVehicles)}>
  145. <Image
  146. style={styles.cardIcon}
  147. source={require('../../images/user/card-vehicle.png')}/>
  148. <View style={styles.cardInfo}>
  149. <Text style={styles.cardLabel}>{$t('profile.myVehicles')}</Text>
  150. <Text style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</Text>
  151. </View>
  152. <FontAwesome
  153. size={28}
  154. color={textCancel}
  155. name='angle-right'/>
  156. </Button>
  157. {/* Vehicle List */}
  158. {/* <View style={styles.titleView}>
  159. <Text style={styles.title}>{$t('profile.myVehicles')}</Text>
  160. <Button
  161. style={{backgroundColor: colorLight}}
  162. borderRadius={3}
  163. viewStyle={styles.titleAdd}
  164. onClick={() => {
  165. startPage(PageList.addVehicle)
  166. }}>
  167. <Entypo name='plus' size={14} color={colorDark}/>
  168. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  169. </Button>
  170. </View> */}
  171. {/* <View style={styles.verhicleList}>
  172. <VehicleList
  173. refreshId={this.state.refreshId}
  174. onResult={count => {
  175. this.setState({
  176. totalVehicle: count
  177. })
  178. }}
  179. onDelete={id => this.removeVehicle(id)}
  180. />
  181. </View> */}
  182. {/* Account List */}
  183. {/* <View style={styles.titleView}>
  184. <Text style={styles.title}>My Cards</Text>
  185. <Button
  186. textColor={textPrimary}
  187. style={styles.titleAdd}
  188. onClick={() => {
  189. startPage(PageList.addCard)
  190. }}>
  191. <Entypo name='plus' size={14} color={colorDark}/>
  192. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  193. </Button>
  194. </View>
  195. <View style={styles.accountList}>
  196. <CardList refreshId={this.state.refreshId}/>
  197. </View> */}
  198. <Button
  199. style={styles.cardView}
  200. viewStyle={styles.profileItem}
  201. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  202. <Image
  203. style={styles.cardIcon}
  204. source={require('../../images/user/card-account.png')}/>
  205. <View style={styles.cardInfo}>
  206. <Text style={styles.cardLabel}>{$t('route.changePassword')}</Text>
  207. </View>
  208. <FontAwesome
  209. size={28}
  210. color={textCancel}
  211. name='angle-right'/>
  212. </Button>
  213. {/* Notifications */}
  214. <Button
  215. style={styles.cardView}
  216. viewStyle={styles.profileItem}
  217. onClick={() => startPage(PageList.settings)}>
  218. <Image
  219. style={styles.cardIcon}
  220. source={require('../../images/user/card-notification.png')}/>
  221. <View style={styles.cardInfo}>
  222. <Text style={styles.cardLabel}>{$t('profile.notificationSettings')}</Text>
  223. </View>
  224. <FontAwesome
  225. size={28}
  226. color={textCancel}
  227. name='angle-right'/>
  228. </Button>
  229. {/* this.state.userInfo.userType == "Public" &&
  230. <Button
  231. style={styles.cardView}
  232. viewStyle={styles.profileItem}
  233. onClick={() => startPage(PageList.registerFleet)}>
  234. <MaterialCommunityIcons
  235. style={styles.cardIcon}
  236. name="credit-card-edit"
  237. size={32}
  238. color="#00638C"/>
  239. <View style={styles.cardInfo}>
  240. <Text style={styles.cardLabel}>{$t('profile.apply2Fleet')}</Text>
  241. </View>
  242. <FontAwesome
  243. size={28}
  244. color={textCancel}
  245. name='angle-right'/>
  246. </Button>
  247. */}
  248. <Button
  249. style={styles.cardView}
  250. viewStyle={styles.profileItem}
  251. onClick={() => this.deleteAccount()}>
  252. <MaterialCommunityIcons
  253. style={styles.cardIcon}
  254. name="account-remove"
  255. size={32}
  256. color="#00638C"/>
  257. <View style={styles.cardInfo}>
  258. <Text style={styles.cardLabel}>{$t('profile.deleteAccount')}</Text>
  259. </View>
  260. <FontAwesome
  261. size={28}
  262. color={textCancel}
  263. name='angle-right'/>
  264. </Button>
  265. {/* <Button
  266. style={styles.deleteButton}
  267. text="DELETE MY ACCOUNT"
  268. textColor={textButton}
  269. onClick={() => this.deleteAccount()}
  270. /> */}
  271. <Button
  272. style={styles.deleteButton}
  273. text={$t('profile.logout')}
  274. textColor={textButton}
  275. onClick={() => this.logout()}
  276. />
  277. </ScrollView>
  278. );
  279. }
  280. }
  281. const styles = StyleSheet.create({
  282. container: {
  283. flex: 1,
  284. backgroundColor: pageBackground
  285. },
  286. headerView: {
  287. paddingBottom: 72
  288. },
  289. background: {
  290. left: 0,
  291. right: 0,
  292. bottom: 0,
  293. height: $vw(62.4),
  294. alignItems: 'center',
  295. position: 'absolute'
  296. },
  297. profileView: {
  298. zIndex: 10,
  299. padding: 16,
  300. alignItems: 'center',
  301. flexDirection: 'row'
  302. },
  303. avatar: {
  304. width: 66,
  305. height: 66,
  306. borderWidth: 2,
  307. borderRadius: 80,
  308. borderColor: "#00638C"
  309. },
  310. infoContent: {
  311. flex: 1,
  312. paddingLeft: 16,
  313. },
  314. nickname: {
  315. color: '#000',
  316. fontSize: 20,
  317. fontWeight: 'bold',
  318. paddingTop: 1,
  319. paddingBottom: 1,
  320. },
  321. userText: {
  322. color: textPrimary,
  323. fontSize: 13,
  324. paddingTop: 1.5
  325. },
  326. cardView: {
  327. //padding: 16,
  328. marginTop: 16,
  329. marginLeft: 16,
  330. marginRight: 16,
  331. borderRadius: 10,
  332. overflow: 'hidden',
  333. ...ElevationObject(5),
  334. alignItems: 'center',
  335. flexDirection: 'row',
  336. backgroundColor: colorLight,
  337. },
  338. profileItem: {
  339. padding: 16,
  340. alignItems: 'center',
  341. flexDirection: 'row',
  342. justifyContent: 'center',
  343. },
  344. cardItem: {
  345. flex: 1,
  346. alignItems: 'center',
  347. flexDirection: 'row',
  348. justifyContent: 'center'
  349. },
  350. cardDivide: {
  351. borderLeftWidth: 1,
  352. borderLeftColor: '#EEE'
  353. },
  354. cardIcon: {
  355. width: 32,
  356. height: 32
  357. },
  358. cardInfo: {
  359. flex: 1,
  360. paddingLeft: 16,
  361. alignItems: 'center',
  362. flexDirection: 'row'
  363. },
  364. cardPrimary: {
  365. color: textPrimary,
  366. fontSize: 18,
  367. paddingBottom: 2
  368. },
  369. cardLabel: {
  370. color: textPrimary,
  371. fontSize: 16,
  372. fontWeight: 'bold'
  373. },
  374. titleView: {
  375. padding: 12,
  376. alignItems: 'center',
  377. flexDirection: 'row'
  378. },
  379. title: {
  380. flex: 1,
  381. padding: 8,
  382. color: '#000',
  383. fontSize: 16,
  384. },
  385. titleAdd: {
  386. padding: 8,
  387. color: textPrimary,
  388. alignItems: 'center',
  389. flexDirection: 'row'
  390. },
  391. verhicleList: {
  392. paddingLeft: 16,
  393. paddingRight: 16,
  394. marginBottom: -16
  395. },
  396. accountList: {
  397. paddingLeft: 16,
  398. paddingRight: 16,
  399. marginBottom: -16
  400. },
  401. notificationView: {
  402. marginLeft: 16,
  403. marginRight: 16,
  404. marginBottom: 20,
  405. borderRadius: 10,
  406. overflow: 'hidden',
  407. paddingLeft: 16,
  408. paddingRight: 16,
  409. borderColor: '#f5f5f5',
  410. borderWidth: 1,
  411. backgroundColor: colorLight,
  412. ...ElevationObject(1.5)
  413. },
  414. notificationItem: {
  415. paddingTop: 16,
  416. paddingBottom: 16,
  417. alignItems: 'center',
  418. flexDirection: 'row'
  419. },
  420. notiLabel: {
  421. flex: 1,
  422. color: textPrimary,
  423. fontSize: 14
  424. },
  425. divide: {
  426. borderTopWidth: 1,
  427. borderTopColor: '#eee'
  428. },
  429. deleteButton: {
  430. ...$margin(48, 16, 16),
  431. backgroundColor: '#EA0A2A'
  432. }
  433. })