/**
* 地图底部充电站信息组件
* @邠心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';
const 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 (
);
} else if (stationInfo.id) {
return (
[style, pressed ? styles.stationBarPresed : {}]}
onPress={() => toChargePage()}>
{stationInfo.name}
{stationInfo.address}
{ stationInfo.upcoming
?
{$t("home.upcoming")}
: <>
{ app.modules.bookmarks &&
}
{
utils.directMaps(stationInfo.latitude, stationInfo.longitude, stationInfo.address);
}}>
{/*
{stationInfo.distance} */}
> }
{ (stationInfo.allConnector && stationInfo.allConnector.available > 0) &&
{$t("charging.statusAvailable")}
}
{stationInfo.siteType}
{ stationInfo?.labels?.length > 0 &&
{ stationInfo.labels.map((item, index) =>
)}
}
{$t("charging.operatingHours")}
{getOperatingHours()}
{$t("charging.parkingFees")}
{getParkingFee()}
{$t("charging.additionalInfo")}
{stationInfo?.additionalNotes}
);
}
} else {
return <>>;
}
}
export default BottomSiteInfo;
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
}
})