TopInfo.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * 首页顶部充电站信息组件
  3. * @邠心vbe on 2021/08/13
  4. */
  5. import React from 'react';
  6. import { Pressable, StyleSheet, View, Text, Image } from 'react-native';
  7. import { ElevationObject } from '../../../components/Button';
  8. import utils from '../../../utils/utils';
  9. import { ChargeStyle } from '../../charge/Charging';
  10. import { PageList } from '../../Router';
  11. export default TopInfo = ({stationInfo = {}}) => {
  12. const getAvailable = (type) => {
  13. const all = stationInfo.allConnector;
  14. if (all) {
  15. if (type == 'box') {
  16. return all.boxAvailable + '/' + all.boxAll;
  17. } else {
  18. return all.available + '/' + all.all;
  19. }
  20. } else {
  21. return '0/0';
  22. }
  23. }
  24. if (stationInfo.id) {
  25. return (
  26. <View style={styles.stationBarView}>
  27. <Pressable
  28. style={styles.stationInfo}
  29. onPress={() => startPage(PageList.chargeDetail, {stationInfo: stationInfo, action: 'view'})}>
  30. <Text
  31. ellipsizeMode='tail'
  32. numberOfLines={1}
  33. style={styles.stationTitle}>{stationInfo.name}</Text>
  34. <Text
  35. style={styles.stationAddress}
  36. ellipsizeMode='tail'
  37. numberOfLines={2}>{stationInfo.address}</Text>
  38. </Pressable>
  39. <View style={styles.stationStatusView}>
  40. { stationInfo.allConnector && stationInfo.allConnector.available > 0 &&
  41. <Text style={[ChargeStyle.infoStatus, ChargeStyle.statusAvailable, styles.stationStatus]}>Available</Text>
  42. }
  43. <Text style={[ChargeStyle.infoStatus, stationInfo.siteType == 'Public' ? ChargeStyle.statusAvailable : ChargeStyle.statusWarning, styles.siteTypes]}>{stationInfo.siteType}</Text>
  44. </View>
  45. <View style={styles.stationAvailable}>
  46. <Image
  47. style={styles.availableIcon}
  48. source={require('../../../images/charge/icon-type-stops.png')}/>
  49. <Text style={styles.availableText}>{getAvailable('box')}</Text>
  50. </View>
  51. <View style={styles.stationAvailable}>
  52. <Image
  53. style={styles.availableIcon}
  54. source={require('../../../images/charge/icon-type-interfaces.png')}/>
  55. <Text style={styles.availableText}>{getAvailable('inc')}</Text>
  56. </View>
  57. <Pressable
  58. style={styles.directView}
  59. onPress={() => {
  60. utils.directMaps(stationInfo.latitude, stationInfo.longitude, stationInfo.address);
  61. }}>
  62. <MaterialIcons
  63. name='directions'
  64. size={27}
  65. color={colorAccent}/>
  66. <Text style={styles.distanceText}>{stationInfo.distance}</Text>
  67. </Pressable>
  68. </View>
  69. );
  70. } else {
  71. return <></>;
  72. }
  73. }
  74. const styles = StyleSheet.create({
  75. stationBarView: {
  76. top: 16,
  77. left: 16,
  78. right: 16,
  79. height: 69,
  80. zIndex: 10,
  81. borderRadius: 6,
  82. ...$padding(12, 9),
  83. position: 'absolute',
  84. alignItems: 'center',
  85. flexDirection: 'row',
  86. backgroundColor: colorLight,
  87. ...ElevationObject(1.5)
  88. },
  89. stationInfo: {
  90. flex: 1,
  91. height: 45,
  92. paddingLeft: 4,
  93. paddingRight: 8,
  94. justifyContent: 'space-around'
  95. },
  96. stationTitle: {
  97. color: '#000',
  98. fontSize: 16,
  99. paddingBottom: 2
  100. },
  101. stationAddress: {
  102. color: '#999',
  103. fontSize: 12,
  104. },
  105. stationAvailable: {
  106. height: 45,
  107. paddingLeft: 8,
  108. paddingRight: 8,
  109. alignItems: 'center',
  110. justifyContent: 'space-between'
  111. },
  112. stationStatusView: {
  113. marginRight: 4,
  114. alignItems: 'center',
  115. justifyContent: 'center'
  116. },
  117. stationStatus: {
  118. fontSize: 10,
  119. ...$padding(2, 6)
  120. },
  121. siteTypes: {
  122. fontSize: 10,
  123. marginTop: 4,
  124. ...$padding(2, 6)
  125. },
  126. availableIcon: {
  127. width: 23,
  128. height: 23,
  129. },
  130. availableText: {
  131. color: textPrimary,
  132. fontSize: 13,
  133. textAlign: 'center'
  134. },
  135. directView: {
  136. zIndex: 1,
  137. height: 45,
  138. marginLeft: 8,
  139. marginRight: 4,
  140. alignItems: 'center',
  141. justifyContent: 'space-between'
  142. },
  143. distanceText: {
  144. color: textPrimary,
  145. fontSize: 12,
  146. }
  147. })