TabInfos.js 3.8 KB

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