ProfileV2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. 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. <Button
  123. style={styles.cardView}
  124. viewStyle={styles.profileView}
  125. onClick={() => 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. </Button>
  147. {/* Wallet Info */}
  148. <Button
  149. style={styles.cardView}
  150. viewStyle={styles.profileView}
  151. onClick={() => 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. </Button>
  164. {/* Vehicle Info */}
  165. <Button
  166. style={styles.cardView}
  167. viewStyle={styles.profileView}
  168. onClick={() => startPage(PageList.myVehicles)}>
  169. <Image
  170. style={styles.cardIcon}
  171. source={require('../../images/user/card-vehicle.png')}/>
  172. <View style={styles.cardInfo}>
  173. <Text style={styles.cardLabel}>My Vehicles: </Text>
  174. <Text style={styles.cardPrimary}>{this.state.userInfo.countVehicle}</Text>
  175. </View>
  176. <FontAwesome
  177. size={28}
  178. color={textCancel}
  179. name='angle-right'/>
  180. </Button>
  181. {/* Vehicle List */}
  182. {/* <View style={styles.titleView}>
  183. <Text style={styles.title}>My Vehicles</Text>
  184. <Button
  185. style={{backgroundColor: colorLight}}
  186. borderRadius={3}
  187. viewStyle={styles.titleAdd}
  188. onClick={() => {
  189. startPage(PageList.addVehicle)
  190. }}>
  191. <Entypo name='plus' size={14} color={colorDark}/>
  192. <Text style={{fontSize: 12, paddingLeft: 1, color: textPrimary}}>Add Vehicle</Text>
  193. </Button>
  194. </View> */}
  195. {/* <View style={styles.verhicleList}>
  196. <VehicleList
  197. refreshId={this.state.refreshId}
  198. onResult={count => {
  199. this.setState({
  200. totalVehicle: count
  201. })
  202. }}
  203. onDelete={id => this.removeVehicle(id)}
  204. />
  205. </View> */}
  206. {/* Account List */}
  207. {/* <View style={styles.titleView}>
  208. <Text style={styles.title}>My Cards</Text>
  209. <Button
  210. textColor={textPrimary}
  211. style={styles.titleAdd}
  212. onClick={() => {
  213. startPage(PageList.addCard)
  214. }}>
  215. <Entypo name='plus' size={14} color={colorDark}/>
  216. <Text style={{fontSize: 12, paddingLeft: 1}}>Add Card</Text>
  217. </Button>
  218. </View>
  219. <View style={styles.accountList}>
  220. <CardList refreshId={this.state.refreshId}/>
  221. </View> */}
  222. <Button
  223. style={styles.cardView}
  224. viewStyle={styles.profileView}
  225. onClick={() => startPage(PageList.changePassword, {action: "change"})}>
  226. <Image
  227. style={styles.cardIcon}
  228. source={require('../../images/user/card-account.png')}/>
  229. <View style={styles.cardInfo}>
  230. <Text style={styles.cardLabel}>Account Security</Text>
  231. </View>
  232. <FontAwesome
  233. size={28}
  234. color={textCancel}
  235. name='angle-right'/>
  236. </Button>
  237. {/* Notifications */}
  238. <Button
  239. style={styles.cardView}
  240. viewStyle={styles.profileView}
  241. onClick={() => startPage(PageList.settings)}>
  242. <Image
  243. style={styles.cardIcon}
  244. source={require('../../images/user/card-notification.png')}/>
  245. <View style={styles.cardInfo}>
  246. <Text style={styles.cardLabel}>Notification Settings</Text>
  247. </View>
  248. <FontAwesome
  249. size={28}
  250. color={textCancel}
  251. name='angle-right'/>
  252. </Button>
  253. { this.state.userInfo.userType == "Public" &&
  254. <Button
  255. style={styles.cardView}
  256. viewStyle={styles.profileView}
  257. onClick={() => startPage(PageList.registerFleet)}>
  258. <MaterialCommunityIcons
  259. style={styles.cardIcon}
  260. name="credit-card-edit"
  261. size={32}
  262. color="#00638C"/>
  263. <View style={styles.cardInfo}>
  264. <Text style={styles.cardLabel}>Apply as PHV/Fleet</Text>
  265. </View>
  266. <FontAwesome
  267. size={28}
  268. color={textCancel}
  269. name='angle-right'/>
  270. </Button>
  271. }
  272. <Button
  273. style={styles.cardView}
  274. viewStyle={styles.profileView}
  275. onClick={() => this.deleteAccount()}>
  276. <MaterialCommunityIcons
  277. style={styles.cardIcon}
  278. name="account-remove"
  279. size={32}
  280. color="#00638C"/>
  281. <View style={styles.cardInfo}>
  282. <Text style={styles.cardLabel}>Delete Account</Text>
  283. </View>
  284. <FontAwesome
  285. size={28}
  286. color={textCancel}
  287. name='angle-right'/>
  288. </Button>
  289. {/* <Button
  290. style={styles.deleteButton}
  291. text="DELETE MY ACCOUNT"
  292. textColor={textButton}
  293. onClick={() => this.deleteAccount()}
  294. /> */}
  295. <Button
  296. style={styles.deleteButton}
  297. text="Logout"
  298. textColor={textButton}
  299. onClick={() => this.logout()}
  300. />
  301. </ScrollView>
  302. );
  303. }
  304. }
  305. const styles = StyleSheet.create({
  306. container: {
  307. flex: 1,
  308. backgroundColor: pageBackground
  309. },
  310. headerView: {
  311. paddingBottom: 72
  312. },
  313. background: {
  314. left: 0,
  315. right: 0,
  316. bottom: 0,
  317. height: $vw(62.4),
  318. alignItems: 'center',
  319. position: 'absolute'
  320. },
  321. profileView: {
  322. zIndex: 10,
  323. padding: 16,
  324. alignItems: 'center',
  325. flexDirection: 'row'
  326. },
  327. avatar: {
  328. width: 66,
  329. height: 66,
  330. borderWidth: 2,
  331. borderRadius: 80,
  332. borderColor: "#00638C"
  333. },
  334. infoContent: {
  335. flex: 1,
  336. paddingLeft: 16,
  337. },
  338. nickname: {
  339. color: '#000',
  340. fontSize: 20,
  341. fontWeight: 'bold',
  342. paddingTop: 1,
  343. paddingBottom: 1,
  344. },
  345. userText: {
  346. color: textPrimary,
  347. fontSize: 13,
  348. paddingTop: 1.5
  349. },
  350. cardView: {
  351. //padding: 16,
  352. marginTop: 16,
  353. marginLeft: 16,
  354. marginRight: 16,
  355. borderRadius: 10,
  356. ...ElevationObject(5),
  357. alignItems: 'center',
  358. flexDirection: 'row',
  359. backgroundColor: colorLight,
  360. },
  361. cardItem: {
  362. flex: 1,
  363. alignItems: 'center',
  364. flexDirection: 'row',
  365. justifyContent: 'center'
  366. },
  367. cardDivide: {
  368. borderLeftWidth: 1,
  369. borderLeftColor: '#EEE'
  370. },
  371. cardIcon: {
  372. width: 32,
  373. height: 32
  374. },
  375. cardInfo: {
  376. flex: 1,
  377. paddingLeft: 16,
  378. alignItems: 'center',
  379. flexDirection: 'row'
  380. },
  381. cardPrimary: {
  382. color: textPrimary,
  383. fontSize: 18,
  384. paddingBottom: 2
  385. },
  386. cardLabel: {
  387. color: textPrimary,
  388. fontSize: 16,
  389. fontWeight: 'bold'
  390. },
  391. titleView: {
  392. padding: 12,
  393. alignItems: 'center',
  394. flexDirection: 'row'
  395. },
  396. title: {
  397. flex: 1,
  398. padding: 8,
  399. color: '#000',
  400. fontSize: 16,
  401. },
  402. titleAdd: {
  403. padding: 8,
  404. color: textPrimary,
  405. alignItems: 'center',
  406. flexDirection: 'row'
  407. },
  408. verhicleList: {
  409. paddingLeft: 16,
  410. paddingRight: 16,
  411. marginBottom: -16
  412. },
  413. accountList: {
  414. paddingLeft: 16,
  415. paddingRight: 16,
  416. marginBottom: -16
  417. },
  418. notificationView: {
  419. marginLeft: 16,
  420. marginRight: 16,
  421. marginBottom: 20,
  422. borderRadius: 10,
  423. overflow: 'hidden',
  424. paddingLeft: 16,
  425. paddingRight: 16,
  426. borderColor: '#f5f5f5',
  427. borderWidth: 1,
  428. backgroundColor: colorLight,
  429. ...ElevationObject(1.5)
  430. },
  431. notificationItem: {
  432. paddingTop: 16,
  433. paddingBottom: 16,
  434. alignItems: 'center',
  435. flexDirection: 'row'
  436. },
  437. notiLabel: {
  438. flex: 1,
  439. color: textPrimary,
  440. fontSize: 14
  441. },
  442. divide: {
  443. borderTopWidth: 1,
  444. borderTopColor: '#eee'
  445. },
  446. deleteButton: {
  447. ...$margin(48, 16, 16),
  448. backgroundColor: '#EA0A2A'
  449. }
  450. })