TabInfos.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * V3版充电站信息页面
  3. * @邠心vbe on 2024/05/13
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, ScrollView, RefreshControl, Text } from 'react-native';
  7. import TextView from '../../components/TextView';
  8. import PagerUtil from '../chargeV2/PagerUtil';
  9. import { MyRefreshProps } from '../../components/ThemesConfig';
  10. import utils from '../../utils/utils';
  11. import SiteLabelView from '../../components/SiteLabelView';
  12. import { ConnectTypeV2 } from '../search/ConnectType';
  13. import { Pressable } from 'react-native';
  14. export default class TabInfosV3 extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. refreshing: false,
  19. stationInfo: {}
  20. };
  21. }
  22. componentDidMount() {
  23. PagerUtil.addOnRefresh(this);
  24. this.onRefresh();
  25. }
  26. onRefresh() {
  27. console.log("info刷新", this.props.route.name);
  28. this.setState({
  29. refreshing: false,
  30. stationInfo: PagerUtil.getStationInfo()
  31. });
  32. }
  33. onPullRefresh() {
  34. this.setState({
  35. refreshing: true
  36. })
  37. PagerUtil.setBackRefreshing();
  38. }
  39. getOperatingHours() {
  40. if (this.state.stationInfo?.endlessService) {
  41. return "24/7";
  42. } else if (this.state.stationInfo?.operatingHours) {
  43. return this.state.stationInfo?.operatingHours;
  44. } else {
  45. return $t('charging.toBeUpdated');
  46. }
  47. }
  48. getParkingFee() {
  49. if (this.state.stationInfo?.parkingFeeFree) {
  50. return $t('charging.free');
  51. } else if (this.state.stationInfo?.parkingFee) {
  52. return this.state.stationInfo.parkingFee;
  53. } else {
  54. return $t('charging.toBeUpdated');
  55. }
  56. }
  57. render() {
  58. return (
  59. <ScrollView
  60. style={styles.container}
  61. keyboardShouldPersistTaps={isIOS ? 'never' : 'handled'}
  62. contentContainerStyle={$padding(0, 16)}
  63. refreshControl={
  64. <RefreshControl
  65. {...MyRefreshProps()}
  66. refreshing={this.state.refreshing}
  67. onRefresh={() => this.onPullRefresh()}
  68. />
  69. }>
  70. <View style={styles.infoView}>
  71. <TextView style={styles.siteName}>{this.state.stationInfo?.name}</TextView>
  72. <View style={ui.flexc}>
  73. <TextView style={styles.siteTypes}>{this.state.stationInfo.siteType}</TextView>
  74. { (this.state.stationInfo.allConnector && this.state.stationInfo.allConnector.available > 0) &&
  75. <TextView style={styles.stationAvailable}>
  76. <MaterialCommunityIcons
  77. name="circle"
  78. size={10}
  79. color={colorAccent}/>
  80. <Text> </Text>
  81. {$t("charging.statusAvailable")}
  82. </TextView>
  83. }
  84. <ConnectTypeV2 {...this.state.stationInfo?.acConnector}/>
  85. <ConnectTypeV2 {...this.state.stationInfo?.dcConnector}/>
  86. </View>
  87. </View>
  88. <TextView style={styles.title}>{$t('charging.siteAddress')}</TextView>
  89. <View style={[styles.infoView, ui.flexc]}>
  90. <TextView style={[styles.infoText, ui.flex1]}>{this.state.stationInfo?.address}</TextView>
  91. <Pressable
  92. style={ui.center}
  93. android_ripple={rippleLess}
  94. onPress={() => {
  95. utils.directMaps(this.state.stationInfo.latitude, this.state.stationInfo.longitude, this.state.stationInfo.address);
  96. }}>
  97. <MaterialCommunityIcons
  98. name="directions"
  99. color={textPrimary}
  100. size={24}/>
  101. </Pressable>
  102. </View>
  103. <TextView style={styles.title}>{$t('charging.operatingHours')}</TextView>
  104. <View style={styles.infoView}>
  105. <TextView style={styles.infoText}>{this.getOperatingHours()}</TextView>
  106. </View>
  107. <TextView style={styles.title}>{$t('charging.parkingFees')}</TextView>
  108. <View style={styles.infoView}>
  109. <TextView style={styles.infoText}>{this.getParkingFee()}</TextView>
  110. </View>
  111. { utils.isNotEmpty(this.state.stationInfo?.additionalNotes) && <>
  112. <TextView style={styles.title}>{$t('charging.additionalInfo')}</TextView>
  113. <View style={styles.infoView}>
  114. <TextView style={styles.infoText}>{this.state.stationInfo?.additionalNotes}</TextView>
  115. </View>
  116. </>}
  117. { utils.isNotEmpty(this.state.stationInfo?.labels) && <>
  118. <TextView style={styles.title}>{$t('charging.labelTags')}</TextView>
  119. <View style={styles.labelRows}>
  120. <TextView style={styles.infoText}>
  121. {this.state.stationInfo?.labels.map((label, idx) =>
  122. (idx != 0 ? ", " : "") + label.label
  123. )}
  124. </TextView>
  125. </View>
  126. </>}
  127. </ScrollView>
  128. );
  129. }
  130. }
  131. const styles = StyleSheet.create({
  132. container: {
  133. flex: 1
  134. },
  135. siteName: {
  136. color: textPrimary,
  137. fontSize: 24,
  138. fontWeight: 'bold',
  139. paddingBottom: 4
  140. },
  141. title: {
  142. color: '#000',
  143. fontSize: 16,
  144. fontWeight: 'bold',
  145. paddingTop: 8,
  146. //borderBottomColor: '#eee',
  147. //borderBottomWidth: 1
  148. },
  149. infoView: {
  150. paddingTop: 4,
  151. paddingBottom: 8
  152. },
  153. infoText: {
  154. color: '#444',
  155. fontSize: 14
  156. },
  157. siteTypes: {
  158. color: textLight,
  159. height: 20,
  160. fontSize: 10,
  161. marginRight: 6,
  162. borderRadius: 30,
  163. ...$padding(0, 10),
  164. backgroundColor: textPrimary
  165. },
  166. stationAvailable: {
  167. color: textPrimary,
  168. height: 20,
  169. fontSize: 10,
  170. marginRight: 6,
  171. borderRadius: 30,
  172. borderWidth: 1,
  173. borderColor: colorAccent,
  174. ...$padding(0, 8, 0, 4)
  175. },
  176. labelRows: {
  177. flexWrap: 'wrap',
  178. alignItems: 'center',
  179. flexDirection: 'row'
  180. }
  181. })