BottomSiteInfo.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /**
  2. * 地图底部充电站信息组件
  3. * @邠心vbe on 2022/12/23
  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. import ConnectType from '../../search/ConnectType';
  12. import app from '../../../../app.json';
  13. import TextView from '../../../components/TextView';
  14. import SiteLabelView from '../../../components/SiteLabelView';
  15. export default BottomSiteInfo = ({
  16. stationInfo = {},
  17. onFavorite,
  18. onClose,
  19. style=styles.stationBarView
  20. }) => {
  21. const getAvailable = (type) => {
  22. const all = stationInfo.allConnector;
  23. if (all) {
  24. if (type == 'box') {
  25. return all.boxAvailable + '/' + all.boxAll;
  26. } else {
  27. return all.available + '/' + all.all;
  28. }
  29. } else {
  30. return '0/0';
  31. }
  32. }
  33. const getOperatingHours = () => {
  34. if (stationInfo.endlessService) {
  35. return "24/7";
  36. } else if (stationInfo.operatingHours) {
  37. return stationInfo.operatingHours;
  38. } else {
  39. return $t('charging.toBeUpdated');
  40. }
  41. }
  42. const getParkingFee = () => {
  43. if (stationInfo.parkingFeeFree) {
  44. return $t('charging.free');
  45. } else if (stationInfo.parkingFee) {
  46. return stationInfo.parkingFee;
  47. } else {
  48. return $t('charging.toBeUpdated');
  49. }
  50. }
  51. const toChargePage = () => {
  52. if (stationInfo.upcoming) {
  53. toastShort($t("home.upcoming"))
  54. } else {
  55. startPage(PageList.chargeDetailPage, {stationInfo: stationInfo, action: 'view', from: PageList.home});
  56. }
  57. }
  58. if (stationInfo.id) {
  59. return (
  60. <Pressable
  61. style={({pressed}) => [style, pressed ? styles.stationBarPresed : {}]}
  62. onPress={() => toChargePage()}>
  63. <View style={ui.flexcw}>
  64. <TextView
  65. ellipsizeMode='tail'
  66. numberOfLines={1}
  67. style={styles.stationTitle}>{stationInfo.name}</TextView>
  68. <Pressable
  69. style={styles.closeIcon}
  70. android_ripple={rippleLess}
  71. onPress={onClose}>
  72. <MaterialCommunityIcons
  73. name="close"
  74. size={22}
  75. color={textCancel}/>
  76. </Pressable>
  77. </View>
  78. <View style={{height: 4}}></View>
  79. <View style={ui.flexc}>
  80. <TextView
  81. style={styles.stationAddress}
  82. ellipsizeMode='tail'
  83. numberOfLines={3}>{stationInfo.address}</TextView>
  84. { stationInfo.upcoming
  85. ? <View style={[ui.center, $margin(0, 8)]}>
  86. <MaterialIcons
  87. name="upcoming"
  88. size={42}
  89. color={colorAccent}
  90. style={styles.upcomingIcon} />
  91. <TextView style={styles.upcomingText}>{$t("home.upcoming")}</TextView>
  92. </View>
  93. : <>
  94. { app.modules.bookmarks &&
  95. <Pressable
  96. style={[styles.directIconView, {backgroundColor: stationInfo.favorite ? colorPrimary : colorCancel}]}
  97. android_ripple={rippleLess}
  98. onPress={onFavorite}>
  99. <MaterialIcons
  100. name="star"
  101. size={26}
  102. color={colorLight}/>
  103. </Pressable>
  104. }
  105. <Pressable
  106. style={styles.directIconView}
  107. android_ripple={rippleLess}
  108. onPress={() => {
  109. utils.directMaps(stationInfo.latitude, stationInfo.longitude, stationInfo.address);
  110. }}>
  111. <MaterialCommunityIcons
  112. name="navigation-variant"
  113. size={25}
  114. color={colorLight}/>
  115. {/* <MaterialIcons
  116. name='directions'
  117. size={28}
  118. color={colorAccent}/>
  119. <Text style={styles.distanceText}>{stationInfo.distance}</Text> */}
  120. </Pressable>
  121. </> }
  122. </View>
  123. <View style={ui.flex}>
  124. <View style={styles.connectView}>
  125. <ConnectType {...stationInfo?.acConnector}/>
  126. <ConnectType {...stationInfo?.dcConnector}/>
  127. </View>
  128. <View style={styles.stationStatusView}>
  129. { (stationInfo.allConnector && stationInfo.allConnector.available > 0) &&
  130. <TextView style={[ChargeStyle.infoStatus, ChargeStyle.statusAvailable, styles.stationStatus]}>{$t("charging.statusAvailable")}</TextView>
  131. }
  132. <TextView style={[ChargeStyle.infoStatus, stationInfo.siteType == 'Public' ? ChargeStyle.statusAvailable : ChargeStyle.statusWarning, styles.siteTypes]}>{stationInfo.siteType}</TextView>
  133. </View>
  134. </View>
  135. { stationInfo?.labels?.length > 0 &&
  136. <View style={styles.siteLabelsView}>
  137. <Image
  138. style={styles.labelIcon}
  139. source={require('../../../images/maps/ic_marker_additional.png')}/>
  140. { stationInfo.labels.map((item, index) =>
  141. <SiteLabelView key={index} {...item}/>
  142. )}
  143. </View>
  144. }
  145. <View style={styles.divideLine}></View>
  146. <View style={styles.infoDetailsView}>
  147. <View style={ui.flex1}>
  148. <TextView style={styles.infoTitle}>{$t("charging.operatingHours")}</TextView>
  149. <View style={styles.infoView}>
  150. <TextView style={styles.infoText}>{getOperatingHours()}</TextView>
  151. </View>
  152. </View>
  153. <View style={{width: 4}}></View>
  154. <View style={ui.flex1}>
  155. <TextView style={styles.infoTitle}>{$t("charging.parkingFees")}</TextView>
  156. <View style={styles.infoView}>
  157. <TextView style={styles.infoText}>{getParkingFee()}</TextView>
  158. </View>
  159. </View>
  160. <View style={{width: 4}}></View>
  161. <View style={ui.flex1}>
  162. <TextView style={styles.infoTitle}>{$t("charging.additionalInfo")}</TextView>
  163. <View style={styles.infoView}>
  164. <TextView style={styles.infoText}>{stationInfo?.additionalNotes}</TextView>
  165. </View>
  166. </View>
  167. </View>
  168. </Pressable>
  169. );
  170. } else {
  171. return <></>;
  172. }
  173. }
  174. const styles = StyleSheet.create({
  175. stationBarView: {
  176. left: 16,
  177. right: 16,
  178. bottom: 48,
  179. zIndex: 10,
  180. borderRadius: 6,
  181. ...$padding(8, 16),
  182. position: 'absolute',
  183. backgroundColor: colorLight,
  184. ...ElevationObject(3)
  185. },
  186. stationBarPresed: {
  187. backgroundColor: "#F6F6F6",
  188. ...ElevationObject(5)
  189. },
  190. stationInfo: {
  191. flex: 1,
  192. height: 45,
  193. paddingLeft: 4,
  194. paddingRight: 8,
  195. justifyContent: 'space-around'
  196. },
  197. stationTitle: {
  198. color: '#000',
  199. fontSize: 17,
  200. fontWeight: 'bold'
  201. },
  202. stationAddress: {
  203. flex: 1,
  204. color: '#999',
  205. fontSize: 12
  206. },
  207. stationAvailable: {
  208. height: 45,
  209. paddingLeft: 8,
  210. paddingRight: 8,
  211. alignItems: 'center',
  212. justifyContent: 'space-between'
  213. },
  214. stationStatusView: {
  215. marginRight: 4,
  216. alignItems: 'center',
  217. flexDirection: 'row-reverse'
  218. },
  219. stationStatus: {
  220. fontSize: 10,
  221. ...$padding(2, 6)
  222. },
  223. siteTypes: {
  224. fontSize: 10,
  225. marginTop: 0,
  226. marginRight: 4,
  227. ...$padding(2, 6)
  228. },
  229. availableIcon: {
  230. width: 23,
  231. height: 23,
  232. },
  233. availableText: {
  234. color: textPrimary,
  235. fontSize: 13,
  236. textAlign: 'center'
  237. },
  238. directView: {
  239. zIndex: 1,
  240. height: 45,
  241. marginLeft: 8,
  242. marginRight: 4,
  243. alignItems: 'center',
  244. justifyContent: 'space-between'
  245. },
  246. distanceText: {
  247. color: textPrimary,
  248. fontSize: 12,
  249. },
  250. directIconView: {
  251. zIndex: 1,
  252. width: 42,
  253. height: 42,
  254. marginLeft: 8,
  255. marginRight: 4,
  256. borderRadius: 45,
  257. alignItems: 'center',
  258. justifyContent: 'center',
  259. backgroundColor: colorAccent,
  260. ...ElevationObject(2)
  261. },
  262. connectView: {
  263. flex: 1,
  264. paddingTop: 12,
  265. paddingBottom: 12,
  266. alignItems: 'center',
  267. flexDirection: 'row'
  268. },
  269. divideLine: {
  270. height: 1,
  271. backgroundColor: '#AEAEAE'
  272. },
  273. infoDetailsView: {
  274. flexDirection: 'row'
  275. },
  276. infoTitle: {
  277. color: '#000',
  278. fontSize: 12,
  279. fontWeight: 'bold',
  280. ...$padding(8, 0, 8)
  281. },
  282. infoView: {
  283. paddingBottom: 8
  284. },
  285. infoText: {
  286. color: '#444',
  287. fontSize: 10
  288. },
  289. closeIcon: {
  290. width: 30,
  291. height: 30,
  292. marginTop: -2,
  293. marginRight: -8,
  294. alignItems: 'center',
  295. justifyContent: 'center'
  296. },
  297. siteLabelsView: {
  298. marginBottom: 5,
  299. flexWrap: 'wrap',
  300. alignItems: 'center',
  301. flexDirection: 'row'
  302. },
  303. labelIcon: {
  304. width: 16,
  305. height: 16,
  306. marginRight: 6
  307. },
  308. upcomingIcon: {
  309. marginLeft: 8,
  310. opacity: .3
  311. },
  312. upcomingText: {
  313. color: colorAccent,
  314. fontSize: 10,
  315. opacity: .3,
  316. marginLeft: 8,
  317. marginTop: -3
  318. }
  319. })