BottomSiteInfo.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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.flexc}>
  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. flex: 1,
  199. color: textPrimary,
  200. fontSize: 17,
  201. fontWeight: 'bold'
  202. },
  203. stationAddress: {
  204. flex: 1,
  205. color: textCancel,
  206. fontSize: 12
  207. },
  208. stationAvailable: {
  209. height: 45,
  210. paddingLeft: 8,
  211. paddingRight: 8,
  212. alignItems: 'center',
  213. justifyContent: 'space-between'
  214. },
  215. stationStatusView: {
  216. marginRight: 4,
  217. alignItems: 'center',
  218. flexDirection: 'row-reverse'
  219. },
  220. stationStatus: {
  221. fontSize: 10,
  222. ...$padding(2, 6)
  223. },
  224. siteTypes: {
  225. fontSize: 10,
  226. marginTop: 0,
  227. marginRight: 4,
  228. ...$padding(2, 6)
  229. },
  230. availableIcon: {
  231. width: 23,
  232. height: 23,
  233. },
  234. availableText: {
  235. color: textPrimary,
  236. fontSize: 13,
  237. textAlign: 'center'
  238. },
  239. directView: {
  240. zIndex: 1,
  241. height: 45,
  242. marginLeft: 8,
  243. marginRight: 4,
  244. alignItems: 'center',
  245. justifyContent: 'space-between'
  246. },
  247. distanceText: {
  248. color: textPrimary,
  249. fontSize: 12,
  250. },
  251. directIconView: {
  252. zIndex: 1,
  253. width: 42,
  254. height: 42,
  255. marginLeft: 8,
  256. marginRight: 4,
  257. borderRadius: 45,
  258. alignItems: 'center',
  259. justifyContent: 'center',
  260. backgroundColor: colorAccent,
  261. ...ElevationObject(2)
  262. },
  263. connectView: {
  264. flex: 1,
  265. paddingTop: 12,
  266. paddingBottom: 12,
  267. alignItems: 'center',
  268. flexDirection: 'row'
  269. },
  270. divideLine: {
  271. height: 1,
  272. backgroundColor: '#AEAEAE'
  273. },
  274. infoDetailsView: {
  275. flexDirection: 'row'
  276. },
  277. infoTitle: {
  278. color: '#000',
  279. fontSize: 12,
  280. fontWeight: 'bold',
  281. ...$padding(8, 0, 8)
  282. },
  283. infoView: {
  284. paddingBottom: 8
  285. },
  286. infoText: {
  287. color: '#444',
  288. fontSize: 10
  289. },
  290. closeIcon: {
  291. width: 30,
  292. height: 30,
  293. marginTop: -2,
  294. marginRight: -8,
  295. alignItems: 'center',
  296. justifyContent: 'center'
  297. },
  298. siteLabelsView: {
  299. marginBottom: 5,
  300. flexWrap: 'wrap',
  301. alignItems: 'center',
  302. flexDirection: 'row'
  303. },
  304. labelIcon: {
  305. width: 16,
  306. height: 16,
  307. marginRight: 6
  308. },
  309. upcomingIcon: {
  310. marginLeft: 8,
  311. opacity: .3
  312. },
  313. upcomingText: {
  314. color: colorAccent,
  315. fontSize: 10,
  316. opacity: .3,
  317. marginLeft: 8,
  318. marginTop: -3
  319. }
  320. })