| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- /**
- * 地图底部充电站信息组件
- * @邠心vbe on 2022/12/23
- */
- import React, { useEffect, useState } from 'react';
- import { Pressable, StyleSheet, View, Text, Image } from 'react-native';
- import { ElevationObject } from '../../../components/Button';
- import utils from '../../../utils/utils';
- import { ChargeStyle } from '../../charge/Charging';
- import { PageList } from '../../Router';
- import ConnectType from '../../search/ConnectType';
- import app from '../../../../app.json';
- import TextView from '../../../components/TextView';
- import SiteLabelView from '../../../components/SiteLabelView';
- import VbeSkeleton from '../../../components/VbeSkeleton';
- export default BottomSiteInfo = ({
- visible=false,
- stationInfo = {},
- onFavorite,
- onClose,
- style=styles.stationBarView
- }) => {
- const [loading, showLoading] = useState(true);
- useEffect(() => {
- if (stationInfo.id) {
- showLoading(false)
- } else {
- showLoading(true)
- }
- }, [stationInfo]);
- useEffect(() => {
- showLoading(true);
- }, [visible]);
- const getAvailable = (type) => {
- const all = stationInfo.allConnector;
- if (all) {
- if (type == 'box') {
- return all.boxAvailable + '/' + all.boxAll;
- } else {
- return all.available + '/' + all.all;
- }
- } else {
- return '0/0';
- }
- }
- const getOperatingHours = () => {
- if (stationInfo.endlessService) {
- return "24/7";
- } else if (stationInfo.operatingHours) {
- return stationInfo.operatingHours;
- } else {
- return $t('charging.toBeUpdated');
- }
- }
- const getParkingFee = () => {
- if (stationInfo.parkingFeeFree) {
- return $t('charging.free');
- } else if (stationInfo.parkingFee) {
- return stationInfo.parkingFee;
- } else {
- return $t('charging.toBeUpdated');
- }
- }
- const toChargePage = () => {
- if (stationInfo.upcoming) {
- toastShort($t("home.upcoming"))
- } else {
- utils.toChargeDetailPage(stationInfo.id, 'view', PageList.home);
- //startPage(PageList.chargeDetailPage, {stationInfo: stationInfo, action: 'view', from: PageList.home});
- }
- }
- if (visible) {
- if (loading) {
- return (
- <View style={style}>
- <View style={ui.flex}>
- <VbeSkeleton
- style={ui.flex1}
- layout={[
- {width: '60%', height: 20, marginTop: 4}
- ]}
- animationDirection={"horizontalRight"}
- />
- <Pressable
- style={styles.closeIcon}
- android_ripple={rippleLess}
- onPress={onClose}>
- <MaterialCommunityIcons
- name="close"
- size={22}
- color={textCancel}/>
- </Pressable>
- </View>
- <EndView half/>
- <View style={ui.flexc}>
- <VbeSkeleton
- style={ui.flex1}
- layout={[
- {width: '100%', height: 15, marginTop: 4},
- {width: '60%', height: 15, marginTop: 4}
- ]}
- animationDirection={"horizontalRight"}
- />
- <VbeSkeleton
- style={ui.flexc}
- layout={[
- {width: 42, height: 42, marginLeft: 16, borderRadius: 48},
- {width: 42, height: 42, marginLeft: 8, borderRadius: 48}
- ]}
- animationDirection={"horizontalRight"}
- />
- </View>
- <EndView/>
- <View style={ui.flex}>
- <VbeSkeleton
- style={[ui.flexc, ui.flex1]}
- viewStyle={ui.flex1}
- layout={[
- {width: '16%', height: 20, marginRight: 8, borderRadius: 30},
- {width: '16%', height: 20, marginRight: 8, borderRadius: 30},
- {width: '16%', height: 20, marginRight: 8, borderRadius: 30}
- ]}
- animationDirection={"horizontalRight"}
- />
- </View>
- <EndView/>
- <VbeSkeleton
- style={ui.flex1}
- layout={[
- {width: '100%', height: 12},
- {width: '60%', height: 12, marginTop: 4}
- ]}
- animationDirection={"horizontalRight"}
- />
- <EndView/>
- </View>
- );
- } else if (stationInfo.id) {
- return (
- <Pressable
- style={({pressed}) => [style, pressed ? styles.stationBarPresed : {}]}
- onPress={() => toChargePage()}>
- <View style={ui.flexc}>
- <TextView
- ellipsizeMode='tail'
- numberOfLines={1}
- style={styles.stationTitle}>{stationInfo.name}</TextView>
- <Pressable
- style={styles.closeIcon}
- android_ripple={rippleLess}
- onPress={onClose}>
- <MaterialCommunityIcons
- name="close"
- size={22}
- color={textCancel}/>
- </Pressable>
- </View>
- <View style={{height: 4}}></View>
- <View style={ui.flexc}>
- <TextView
- style={styles.stationAddress}
- ellipsizeMode='tail'
- numberOfLines={3}>{stationInfo.address}</TextView>
- { stationInfo.upcoming
- ? <View style={[ui.center, $margin(0, 8)]}>
- <MaterialIcons
- name="upcoming"
- size={42}
- color={colorAccent}
- style={styles.upcomingIcon} />
- <TextView style={styles.upcomingText}>{$t("home.upcoming")}</TextView>
- </View>
- : <>
- { app.modules.bookmarks &&
- <Pressable
- style={[styles.directIconView, {backgroundColor: stationInfo.favorite ? colorPrimary : colorCancel}]}
- android_ripple={rippleLess}
- onPress={onFavorite}>
- <MaterialIcons
- name="star"
- size={26}
- color={colorLight}/>
- </Pressable>
- }
- <Pressable
- style={styles.directIconView}
- android_ripple={rippleLess}
- onPress={() => {
- utils.directMaps(stationInfo.latitude, stationInfo.longitude, stationInfo.address);
- }}>
- <MaterialCommunityIcons
- name="navigation-variant"
- size={25}
- color={colorLight}/>
- {/* <MaterialIcons
- name='directions'
- size={28}
- color={colorAccent}/>
- <Text style={styles.distanceText}>{stationInfo.distance}</Text> */}
- </Pressable>
- </> }
- </View>
- <View style={ui.flex}>
- <View style={styles.connectView}>
- <ConnectType {...stationInfo?.acConnector}/>
- <ConnectType {...stationInfo?.dcConnector}/>
- </View>
- <View style={styles.stationStatusView}>
- { (stationInfo.allConnector && stationInfo.allConnector.available > 0) &&
- <TextView style={[ChargeStyle.infoStatus, ChargeStyle.statusAvailable, styles.stationStatus]}>{$t("charging.statusAvailable")}</TextView>
- }
- <TextView style={[ChargeStyle.infoStatus, stationInfo.siteType == 'Public' ? ChargeStyle.statusAvailable : ChargeStyle.statusWarning, styles.siteTypes]}>{stationInfo.siteType}</TextView>
- </View>
- </View>
- { stationInfo?.labels?.length > 0 &&
- <View style={styles.siteLabelsView}>
- <Image
- style={styles.labelIcon}
- source={require('../../../images/maps/ic_marker_additional.png')}/>
- { stationInfo.labels.map((item, index) =>
- <SiteLabelView key={index} {...item}/>
- )}
- </View>
- }
- <View style={styles.divideLine}></View>
- <View style={styles.infoDetailsView}>
- <View style={ui.flex1}>
- <TextView style={styles.infoTitle}>{$t("charging.operatingHours")}</TextView>
- <View style={styles.infoView}>
- <TextView style={styles.infoText}>{getOperatingHours()}</TextView>
- </View>
- </View>
- <View style={{width: 4}}></View>
- <View style={ui.flex1}>
- <TextView style={styles.infoTitle}>{$t("charging.parkingFees")}</TextView>
- <View style={styles.infoView}>
- <TextView style={styles.infoText} numberOfLines={3}>{getParkingFee()}</TextView>
- </View>
- </View>
- <View style={{width: 4}}></View>
- <View style={ui.flex1}>
- <TextView style={styles.infoTitle}>{$t("charging.additionalInfo")}</TextView>
- <View style={styles.infoView}>
- <TextView style={styles.infoText} numberOfLines={3}>{stationInfo?.additionalNotes}</TextView>
- </View>
- </View>
- </View>
- </Pressable>
- );
- }
- } else {
- return <></>;
- }
- }
- const styles = StyleSheet.create({
- stationBarView: {
- left: 16,
- right: 16,
- bottom: 48,
- zIndex: 10,
- borderRadius: 6,
- ...$padding(8, 16),
- position: 'absolute',
- backgroundColor: colorLight,
- ...ElevationObject(3)
- },
- stationBarPresed: {
- backgroundColor: "#F6F6F6",
- ...ElevationObject(5)
- },
- stationInfo: {
- flex: 1,
- height: 45,
- paddingLeft: 4,
- paddingRight: 8,
- justifyContent: 'space-around'
- },
- stationTitle: {
- flex: 1,
- color: textPrimary,
- fontSize: 17,
- fontWeight: 'bold'
- },
- stationAddress: {
- flex: 1,
- color: textCancel,
- fontSize: 12
- },
- stationAvailable: {
- height: 45,
- paddingLeft: 8,
- paddingRight: 8,
- alignItems: 'center',
- justifyContent: 'space-between'
- },
- stationStatusView: {
- marginRight: 4,
- alignItems: 'center',
- flexDirection: 'row-reverse'
- },
- stationStatus: {
- fontSize: 10,
- ...$padding(2, 6)
- },
- siteTypes: {
- fontSize: 10,
- marginTop: 0,
- marginRight: 4,
- ...$padding(2, 6)
- },
- availableIcon: {
- width: 23,
- height: 23,
- },
- availableText: {
- color: textPrimary,
- fontSize: 13,
- textAlign: 'center'
- },
- directView: {
- zIndex: 1,
- height: 45,
- marginLeft: 8,
- marginRight: 4,
- alignItems: 'center',
- justifyContent: 'space-between'
- },
- distanceText: {
- color: textPrimary,
- fontSize: 12,
- },
- directIconView: {
- zIndex: 1,
- width: 42,
- height: 42,
- marginLeft: 8,
- marginRight: 4,
- borderRadius: 45,
- alignItems: 'center',
- justifyContent: 'center',
- backgroundColor: colorAccent,
- ...ElevationObject(2)
- },
- connectView: {
- flex: 1,
- paddingTop: 12,
- paddingBottom: 12,
- alignItems: 'center',
- flexDirection: 'row'
- },
- divideLine: {
- height: 1,
- backgroundColor: '#AEAEAE'
- },
- infoDetailsView: {
- flexDirection: 'row'
- },
- infoTitle: {
- color: '#000',
- fontSize: 12,
- fontWeight: 'bold',
- ...$padding(8, 0, 8)
- },
- infoView: {
- paddingBottom: 8
- },
- infoText: {
- color: '#444',
- fontSize: 10
- },
- closeIcon: {
- width: 30,
- height: 30,
- marginTop: -2,
- marginRight: -8,
- alignItems: 'center',
- justifyContent: 'center'
- },
- siteLabelsView: {
- marginBottom: 5,
- flexWrap: 'wrap',
- alignItems: 'center',
- flexDirection: 'row'
- },
- labelIcon: {
- width: 16,
- height: 16,
- marginRight: 6
- },
- upcomingIcon: {
- marginLeft: 8,
- opacity: .3
- },
- upcomingText: {
- color: colorAccent,
- fontSize: 10,
- opacity: .3,
- marginLeft: 8,
- marginTop: -3
- }
- })
|