ProfileV2.js 12 KB

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