BottomSiteCard.js 9.6 KB

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