BottomSiteInfo.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. export default 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. const styles = StyleSheet.create({
  256. stationBarView: {
  257. left: 16,
  258. right: 16,
  259. bottom: 48,
  260. zIndex: 10,
  261. borderRadius: 6,
  262. ...$padding(8, 16),
  263. position: 'absolute',
  264. backgroundColor: colorLight,
  265. ...ElevationObject(3)
  266. },
  267. stationBarPresed: {
  268. backgroundColor: "#F6F6F6",
  269. ...ElevationObject(5)
  270. },
  271. stationInfo: {
  272. flex: 1,
  273. height: 45,
  274. paddingLeft: 4,
  275. paddingRight: 8,
  276. justifyContent: 'space-around'
  277. },
  278. stationTitle: {
  279. flex: 1,
  280. color: textPrimary,
  281. fontSize: 17,
  282. fontWeight: 'bold'
  283. },
  284. stationAddress: {
  285. flex: 1,
  286. color: textCancel,
  287. fontSize: 12
  288. },
  289. stationAvailable: {
  290. height: 45,
  291. paddingLeft: 8,
  292. paddingRight: 8,
  293. alignItems: 'center',
  294. justifyContent: 'space-between'
  295. },
  296. stationStatusView: {
  297. marginRight: 4,
  298. alignItems: 'center',
  299. flexDirection: 'row-reverse'
  300. },
  301. stationStatus: {
  302. fontSize: 10,
  303. ...$padding(2, 6)
  304. },
  305. siteTypes: {
  306. fontSize: 10,
  307. marginTop: 0,
  308. marginRight: 4,
  309. ...$padding(2, 6)
  310. },
  311. availableIcon: {
  312. width: 23,
  313. height: 23,
  314. },
  315. availableText: {
  316. color: textPrimary,
  317. fontSize: 13,
  318. textAlign: 'center'
  319. },
  320. directView: {
  321. zIndex: 1,
  322. height: 45,
  323. marginLeft: 8,
  324. marginRight: 4,
  325. alignItems: 'center',
  326. justifyContent: 'space-between'
  327. },
  328. distanceText: {
  329. color: textPrimary,
  330. fontSize: 12,
  331. },
  332. directIconView: {
  333. zIndex: 1,
  334. width: 42,
  335. height: 42,
  336. marginLeft: 8,
  337. marginRight: 4,
  338. borderRadius: 45,
  339. alignItems: 'center',
  340. justifyContent: 'center',
  341. backgroundColor: colorAccent,
  342. ...ElevationObject(2)
  343. },
  344. connectView: {
  345. flex: 1,
  346. paddingTop: 12,
  347. paddingBottom: 12,
  348. alignItems: 'center',
  349. flexDirection: 'row'
  350. },
  351. divideLine: {
  352. height: 1,
  353. backgroundColor: '#AEAEAE'
  354. },
  355. infoDetailsView: {
  356. flexDirection: 'row'
  357. },
  358. infoTitle: {
  359. color: '#000',
  360. fontSize: 12,
  361. fontWeight: 'bold',
  362. ...$padding(8, 0, 8)
  363. },
  364. infoView: {
  365. paddingBottom: 8
  366. },
  367. infoText: {
  368. color: '#444',
  369. fontSize: 10
  370. },
  371. closeIcon: {
  372. width: 30,
  373. height: 30,
  374. marginTop: -2,
  375. marginRight: -8,
  376. alignItems: 'center',
  377. justifyContent: 'center'
  378. },
  379. siteLabelsView: {
  380. marginBottom: 5,
  381. flexWrap: 'wrap',
  382. alignItems: 'center',
  383. flexDirection: 'row'
  384. },
  385. labelIcon: {
  386. width: 16,
  387. height: 16,
  388. marginRight: 6
  389. },
  390. upcomingIcon: {
  391. marginLeft: 8,
  392. opacity: .3
  393. },
  394. upcomingText: {
  395. color: colorAccent,
  396. fontSize: 10,
  397. opacity: .3,
  398. marginLeft: 8,
  399. marginTop: -3
  400. }
  401. })