BottomSiteInfo.js 8.9 KB

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