BottomSiteCard.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. <View style={styles.stationBarView}>
  74. <TextView
  75. ellipsizeMode='tail'
  76. numberOfLines={1}
  77. style={styles.stationTitle}>{stationInfo.name}</TextView>
  78. <View style={ui.flexc}>
  79. <TextView style={styles.siteTypes}>{stationInfo.siteType}</TextView>
  80. { (stationInfo.allConnector && stationInfo.allConnector.available > 0) &&
  81. <TextView style={styles.stationAvailable}>
  82. <MaterialCommunityIcons
  83. name="circle"
  84. size={10}
  85. color={colorAccent}/>
  86. <Text> </Text>
  87. {$t("charging.statusAvailable")}
  88. </TextView>
  89. }
  90. <ConnectTypeV2 {...stationInfo?.acConnector}/>
  91. <ConnectTypeV2 {...stationInfo?.dcConnector}/>
  92. </View>
  93. <TextView
  94. style={styles.stationAddress}
  95. ellipsizeMode='tail'
  96. numberOfLines={3}>{stationInfo.address}</TextView>
  97. <View style={ui.flexc}>
  98. { stationInfo.upcoming
  99. ? <View style={[ui.center, $margin(0, 8)]}>
  100. <MaterialIcons
  101. name="upcoming"
  102. size={42}
  103. color={colorAccent}
  104. style={styles.upcomingIcon} />
  105. <TextView style={styles.upcomingText}>{$t("home.upcoming")}</TextView>
  106. </View>
  107. : <>
  108. <Pressable
  109. style={styles.directIconView}
  110. onPress={() => {
  111. utils.directMaps(stationInfo.latitude, stationInfo.longitude, stationInfo.address);
  112. }}>
  113. <MaterialCommunityIcons
  114. name="directions"
  115. size={18}
  116. color={textPrimary}/>
  117. <TextView style={styles.directText}>Directions</TextView>
  118. </Pressable>
  119. { app.modules.bookmarks &&
  120. <Pressable
  121. style={[styles.directIconView, stationInfo.favorite ? styles.bookmarked : {}]}
  122. onPress={onFavorite}>
  123. <MaterialIcons
  124. name="star"
  125. size={18}
  126. color={stationInfo.favorite ? textLight : textPrimary}/>
  127. <TextView style={[styles.directText, stationInfo.favorite ? styles.bookmarked : {}]}>
  128. {stationInfo.favorite ? "Saved" : "Save"}
  129. </TextView>
  130. </Pressable>
  131. }
  132. {/* <Pressable
  133. style={styles.directIconView}
  134. onPress={() => {
  135. startPage(PageList.scanqr, {actionDetail: true});
  136. }}>
  137. <MaterialCommunityIcons
  138. name="qrcode-scan"
  139. size={12}
  140. color={textPrimary}
  141. style={$padding(3)}/>
  142. <TextView style={styles.directText}>Scan</TextView>
  143. </Pressable> */}
  144. <Pressable
  145. style={styles.directIconView}
  146. onPress={() => toChargePage()}>
  147. <MaterialCommunityIcons
  148. name="information-variant"
  149. size={17}
  150. color={textPrimary}/>
  151. <TextView style={styles.directText}>More Info</TextView>
  152. </Pressable>
  153. </> }
  154. </View>
  155. {/* stationInfo?.labels?.length > 0 &&
  156. <View style={styles.siteLabelsView}>
  157. <Image
  158. style={styles.labelIcon}
  159. source={require('../../../images/maps/ic_marker_additional.png')}/>
  160. { stationInfo.labels.map((item, index) =>
  161. <SiteLabelView key={index} {...item}/>
  162. )}
  163. </View>
  164. */}
  165. </View>
  166. </BottomModal>
  167. )
  168. }
  169. const styles = StyleSheet.create({
  170. stationBarView: {
  171. padding: 16
  172. },
  173. stationBarPresed: {
  174. backgroundColor: "#F6F6F6",
  175. ...ElevationObject(5)
  176. },
  177. stationInfo: {
  178. flex: 1,
  179. height: 45,
  180. paddingLeft: 4,
  181. paddingRight: 8,
  182. justifyContent: 'space-around'
  183. },
  184. stationTitle: {
  185. color: textPrimary,
  186. fontSize: 24,
  187. fontWeight: 'bold',
  188. paddingBottom: 4
  189. },
  190. stationAddress: {
  191. color: textSecondary,
  192. fontSize: 12,
  193. paddingTop: 4,
  194. paddingBottom: 6
  195. },
  196. siteTypes: {
  197. color: textLight,
  198. height: 20,
  199. fontSize: 8,
  200. marginRight: 6,
  201. borderRadius: 30,
  202. ...$padding(0, 10),
  203. backgroundColor: textPrimary
  204. },
  205. stationAvailable: {
  206. color: textPrimary,
  207. height: 20,
  208. fontSize: 8,
  209. marginRight: 6,
  210. borderRadius: 30,
  211. borderWidth: 1,
  212. borderColor: colorAccent,
  213. ...$padding(0, 8, 0, 4)
  214. },
  215. directView: {
  216. zIndex: 1,
  217. height: 45,
  218. marginLeft: 8,
  219. marginRight: 4,
  220. alignItems: 'center',
  221. justifyContent: 'space-between'
  222. },
  223. distanceText: {
  224. color: textPrimary,
  225. fontSize: 12,
  226. },
  227. directIconView: {
  228. zIndex: 1,
  229. marginRight: 10,
  230. borderWidth: 1,
  231. borderRadius: 30,
  232. borderColor: textPrimary,
  233. alignItems: 'center',
  234. flexDirection: 'row',
  235. justifyContent: 'center',
  236. ...$padding(2, 8, 2, 4)
  237. },
  238. bookmarked: {
  239. color: textLight,
  240. borderColor: colorAccent,
  241. backgroundColor: colorAccent
  242. },
  243. directText: {
  244. color: textPrimary,
  245. fontSize: 12,
  246. paddingLeft: 4
  247. },
  248. connectView: {
  249. flex: 1,
  250. paddingTop: 12,
  251. paddingBottom: 12,
  252. alignItems: 'center',
  253. flexDirection: 'row'
  254. },
  255. divideLine: {
  256. height: 1,
  257. backgroundColor: '#AEAEAE'
  258. },
  259. infoDetailsView: {
  260. flexDirection: 'row'
  261. },
  262. infoTitle: {
  263. color: '#000',
  264. fontSize: 12,
  265. fontWeight: 'bold',
  266. ...$padding(8, 0, 8)
  267. },
  268. infoView: {
  269. paddingBottom: 8
  270. },
  271. infoText: {
  272. color: '#444',
  273. fontSize: 10
  274. },
  275. closeIcon: {
  276. width: 30,
  277. height: 30,
  278. marginTop: -2,
  279. marginRight: -8,
  280. alignItems: 'center',
  281. justifyContent: 'center'
  282. },
  283. siteLabelsView: {
  284. marginBottom: 5,
  285. flexWrap: 'wrap',
  286. alignItems: 'center',
  287. flexDirection: 'row'
  288. },
  289. labelIcon: {
  290. width: 16,
  291. height: 16,
  292. marginRight: 6
  293. },
  294. upcomingIcon: {
  295. marginLeft: 8,
  296. opacity: .3
  297. },
  298. upcomingText: {
  299. color: colorAccent,
  300. fontSize: 10,
  301. opacity: .3,
  302. marginLeft: 8,
  303. marginTop: -3
  304. }
  305. })