TabInfos.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * 新版充电站信息页面
  3. * @邠心vbe on 2023/02/06
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, ScrollView, RefreshControl } from 'react-native';
  7. import TextView from '../../components/TextView';
  8. import PagerUtil from './PagerUtil';
  9. import { MyRefreshProps } from '../../components/ThemesConfig';
  10. import utils from '../../utils/utils';
  11. import SiteLabelView from '../../components/SiteLabelView';
  12. export default class TabInfos extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. refreshing: false,
  17. stationInfo: {}
  18. };
  19. }
  20. componentDidMount() {
  21. PagerUtil.addOnRefresh(this);
  22. this.onRefresh();
  23. }
  24. onRefresh() {
  25. console.log("info刷新", this.props.route.name);
  26. this.setState({
  27. refreshing: false,
  28. stationInfo: PagerUtil.getStationInfo()
  29. });
  30. }
  31. onPullRefresh() {
  32. this.setState({
  33. refreshing: true
  34. })
  35. PagerUtil.setBackRefreshing();
  36. }
  37. getOperatingHours() {
  38. if (this.state.stationInfo?.endlessService) {
  39. return "24/7";
  40. } else if (this.state.stationInfo?.operatingHours) {
  41. return this.state.stationInfo?.operatingHours;
  42. } else {
  43. return $t('charging.toBeUpdated');
  44. }
  45. }
  46. getParkingFee() {
  47. if (this.state.stationInfo?.parkingFeeFree) {
  48. return $t('charging.free');
  49. } else if (this.state.stationInfo?.parkingFee) {
  50. return this.state.stationInfo.parkingFee;
  51. } else {
  52. return $t('charging.toBeUpdated');
  53. }
  54. }
  55. render() {
  56. return (
  57. <ScrollView
  58. style={styles.container}
  59. keyboardShouldPersistTaps={isIOS ? 'never' : 'handled'}
  60. contentContainerStyle={$padding(0, 16)}
  61. refreshControl={
  62. <RefreshControl
  63. {...MyRefreshProps()}
  64. refreshing={this.state.refreshing}
  65. onRefresh={() => this.onPullRefresh()}
  66. />
  67. }>
  68. <TextView style={styles.title}>{$t('charging.siteName')}</TextView>
  69. <View style={styles.infoView}>
  70. <TextView style={styles.infoText}>{this.state.stationInfo?.name}</TextView>
  71. </View>
  72. <TextView style={styles.title}>{$t('charging.siteAddress')}</TextView>
  73. <View style={styles.infoView}>
  74. <TextView style={styles.infoText}>{this.state.stationInfo?.address}</TextView>
  75. </View>
  76. <TextView style={styles.title}>{$t('charging.parkingFees')}</TextView>
  77. <View style={styles.infoView}>
  78. <TextView style={styles.infoText}>{this.getParkingFee()}</TextView>
  79. </View>
  80. <TextView style={styles.title}>{$t('charging.operatingHours')}</TextView>
  81. <View style={styles.infoView}>
  82. <TextView style={styles.infoText}>{this.getOperatingHours()}</TextView>
  83. </View>
  84. <TextView style={styles.title}>{$t('charging.additionalInformation')}</TextView>
  85. <View style={styles.infoView}>
  86. <TextView style={styles.infoText}>{this.state.stationInfo?.additionalNotes}</TextView>
  87. <View style={styles.labelRows}>
  88. { utils.isNotEmpty(this.state.stationInfo?.labels) &&
  89. this.state.stationInfo?.labels.map((label, idx) =>
  90. <SiteLabelView key={idx} {...label}/>
  91. )
  92. }
  93. </View>
  94. </View>
  95. </ScrollView>
  96. );
  97. }
  98. }
  99. const styles = StyleSheet.create({
  100. container: {
  101. flex: 1
  102. },
  103. title: {
  104. color: '#000',
  105. fontSize: 14,
  106. fontWeight: 'bold',
  107. ...$padding(16, 0, 8),
  108. borderBottomColor: '#eee',
  109. borderBottomWidth: 1
  110. },
  111. infoView: {
  112. paddingTop: 8,
  113. paddingBottom: 16
  114. },
  115. infoText: {
  116. color: '#444',
  117. fontSize: 14
  118. },
  119. labelRows: {
  120. flexWrap: 'wrap',
  121. alignItems: 'center',
  122. flexDirection: 'row'
  123. }
  124. })