BottomSiteInfo.js 12 KB

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