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