BottomSiteInfo.js 8.8 KB

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