/**
* 充电中的页面组件
* @邠心vbe on 2021/04/13
*/
import React, { useRef, useEffect, useState } from 'react';
import { Animated, View, Easing, StyleSheet, Image, Text, ImageBackground, TextInput } from 'react-native';
import { RadialGradient } from 'react-native-gradients';
import Modal from 'react-native-modal';
import { ModalProps } from '../../components/BottomModal';
import Button, { ElevationObject, ViewHeight } from '../../components/Button';
import ChargeItemSelect from '../../icons/ChargeItemSelect';
import { DialogMaxWidth } from './InfoDialog';
import { QRResult } from '../charge/QRScan';
import Svg, { Defs, LinearGradient, Rect, Stop } from 'react-native-svg';
import utils from '../../utils/utils';
import TextView from '../../components/TextView';
export const circleSize = $vw(50.66) < 300 ? $vw(50.66) : 300;
const batterySize = 0.463 * circleSize;
const batteryWidth = 0.659*batterySize;
export const TypeImage = {
AC: require('../../images/charge/ic-type-ac.png'),
DC: require('../../images/charge/ic-type-dc.png'),
CHADEMO: require('../../images/charge/ic-type-chademo.png')
}
export const TypeImageList = [
{
name: 'AC',
key: 'AC',
icon: require('../../images/charge/ic-type-ac.png')
}, {
name: 'DC',
key: 'DC',
icon: require('../../images/charge/ic-type-dc.png')
}, /*{
name: 'Chademo',
key: 'CHADEMO',
icon: require('../../images/charge/ic-type-chademo.png')
}*/
]
export const getConnectTypeByKey = (key) => {
for (let item of TypeImageList) {
if (item.key == key) {
return item;
}
}
}
export const CircleAnimate = ({isStart = false}) => {
var rotate = useRef(new Animated.Value(0)).current;
const spins = () => {
Animated.timing(rotate, {
toValue: 1,
duration: 10000,
easing: Easing.linear,
useNativeDriver: true
}).start(() => {
rotate.setValue(0);
spins();
});
}
useEffect(() => {
if (isStart) {
spins();
}
}, [rotate]);
const spin = rotate.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
})
return (
{ isStart &&
}
);
}
export const BatteryView = ({soc, isPending, isCharging}) => {
var [powerPercent, setPercent] = useState(-1);
/*var [powerText, setText] = useState(0);
const autoCharge = () => {
setTimeout(() => {
const p = powerPercent + 0.001
setPercent(Number(p.toFixed(4)))
setText((powerPercent * 100).toFixed(0))
if (powerPercent >= 1) {
onComplete();
}
}, 50 + powerPercent * 100);
}
useEffect(() => {
if (run && powerPercent <= 1) {
autoCharge();
}
}, [powerPercent])*/
useEffect(() => {
if (isCharging) {
try {
var s = '-1' + soc;
var d = '' + parseInt(s);
d = d.replace('-1', '');
if (d) {
setPercent(parseInt(d))
} else {
setPercent(-1);
}
} catch (e) {
setPercent(-1);
}
}
}, [soc]);
const getOpacity = (unit) => {
var op = 1 * (powerPercent + unit);
return op < 1 ? op : 1;
}
const getHeight = () => {
if (powerPercent > 1) {
return batterySize * powerPercent / 100;
} else if (powerPercent > 0) {
return batterySize * powerPercent;
} else {
return 0
}
}
return (
isCharging
?
{ isPending
? {$t('charging.statusInitiating')}
: powerPercent != -1
? {powerPercent}%
: {$t('charging.statusInCharging')}
}
:
{$t('charging.tipsDisconnectConnector')}
);
}
export const DashboardView = ({isCharging=false, connectorInfo={}}) => {
if (isCharging) {
return (
{$t('charging.chargingInProgress')}
{utils.minutes2HHmm(connectorInfo?.timeElapsed ?? 0)}
{$t('charging.labelTimeElapsed')}
{utils.toFixed(connectorInfo?.totalKWhDelivered, 2) ?? "0"} kWh
{$t('charging.labelTotalkWh')}
{/* {currency} {utils.toFixed(connectorInfo?.totalCharges, 2) ?? "0.0"} */}
{connectorInfo?.totalCharges ?? "$0.0"}
{$t('charging.labelTotalCharges')}
)
} else {
return (
{$t('charging.pressStartToBegin')}
-
{$t('charging.labelTimeElapsed')}
-
{$t('charging.labelTotalkWh')}
-
{$t('charging.labelTotalCharges')}
)
}
}
export const EnterStationDialog = ({visible, stationId, onConfirm, onClose}) => {
var [inputStationId, setInput] = useState('')
var [iosKillDialog, killDialog] = useState(true)
const enterStatioinId= () => {
//console.log(inputStationId);
if (inputStationId) {
if (isIOS && iosKillDialog) {
onClose();
killDialog(false);
} else {
QRResult.applyInputStation(inputStationId, stationId, (success, err) => {
setInput('')
if (success) {
if (onConfirm) onConfirm()
} else if (err) {
toastShort(err)
}
if (onClose) onClose()
});
}
} else {
toastShort($t('charging.plsInputStationId'));
}
}
useEffect(() => {
if (!visible && !iosKillDialog) {
killDialog(true);
setTimeout(() => {
enterStatioinId();
}, 100);
}
}, [iosKillDialog])
return (
iosKillDialog
? onClose}
onBackButtonPress={() => onClose}>
{$t('charging.enterStationId')}
setInput(text)}
/>
: <>>
)
}
const styles = StyleSheet.create({
chargingView: {
width: circleSize,
height: circleSize,
flexDirection: 'row',
alignItems: 'center'
},
chargeCircle: {
top: 0,
left: 0,
zIndex: 10,
width: circleSize,
height: circleSize,
position: 'absolute',
alignItems: 'center',
borderRadius: circleSize
},
batteryView: {
paddingTop: 8,
paddingLeft: 12,
paddingRight: 12,
alignItems: 'center',
justifyContent: 'center'
},
batteryIcon: {
width: batteryWidth,
height: batterySize,
position: 'relative',
justifyContent: 'flex-end',
},
batteryLayer: {
left: 0,
right: 0,
height: 0,
width: batteryWidth,
overflow: 'hidden',
position: 'absolute',
justifyContent: 'flex-end',
},
batteryPercent: {
color: textPrimary,
fontSize: 22,
textAlign: 'center',
paddingTop: 10,
paddingBottom: 8
},
batterySoc: {
color: textPrimary,
fontSize: 18,
textAlign: 'center',
paddingTop: 10,
paddingBottom: 10
},
plusLeftView: {
flex: 1,
height: batterySize + 10,
marginBottom: 12,
alignItems: 'flex-end',
justifyContent: 'space-around'
},
plusRightView: {
flex: 1,
justifyContent: 'center'
},
plusLarge: {
width: 24,
height: 24
},
plusMiddle: {
width: 18,
height: 18
},
plusSmall: {
width: 12,
height: 12,
marginBottom: 8
},
selectView: {
position: 'relative'
},
selectIcon: {
width: 18,
height: 18
},
selectIconAbs: {
top: -2,
right: -4,
zIndex: 2,
position: 'absolute'
},
completeView: {
height: circleSize,
marginBottom: 16,
alignItems: 'center',
justifyContent: 'center'
},
disconnectIcon: {
width: 100,
height: 100
},
completeTip: {
width: circleSize,
color: textPrimary,
fontSize: 16,
paddingLeft: 16,
paddingRight: 16,
textAlign: 'center'
},
stationDialog: {
padding: 16,
marginLeft: 'auto',
marginRight: 'auto',
borderRadius: isIOS ? 20 : 3,
width: DialogMaxWidth,
backgroundColor: colorLight
},
stationInput: {
...$padding(4, 10),
minHeight: 40,
borderRadius: 3,
backgroundColor: '#F0F0F0'
},
stationInputTitle: {
fontSize: 15,
textAlign: 'center',
paddingBottom: 16
},
dialogButtons: {
paddingTop: 24,
paddingBottom: 8,
flexDirection: 'row'
},
buttonOK: {
flex: 1,
marginLeft: 12,
},
buttonCancel: {
flex: 1,
borderWidth: 1,
borderColor: colorCancel,
backgroundColor: pageBackground
},
dashboardGreyView: {
padding: 16,
marginTop: 16,
marginBottom: 16,
borderRadius: 6,
...ElevationObject(5),
backgroundColor: pageBackground
},
dashboardStartView: {
padding: 16,
marginTop: 16,
marginBottom: 16,
borderRadius: 6,
...ElevationObject(5)
},
dashboardGradientView: {
top: 0,
left: 0,
right: 0,
bottom: 0,
borderRadius: 6,
overflow: 'hidden',
position: "absolute",
},
dashboardTitle: {
color: textPrimary,
fontSize: 25,
fontWeight: 'bold',
textAlign: 'center',
paddingBottom: 16
},
dashboardTitleWhite: {
color: textLight,
fontSize: 25,
fontWeight: 'bold',
textAlign: 'center',
paddingBottom: 16
},
dashboardItemGroup: {
marginRight: -12,
marginBottom: -32,
alignItems: 'center',
flexDirection: 'row'
},
dashboardItemView: {
flex: 1,
marginRight: 12,
borderRadius: 6,
...$padding(10, 6, 14),
...ElevationObject(5),
backgroundColor: colorLight
},
dashboardItemTitle: {
color: textCancel,
fontSize: 12,
textAlign: 'center',
paddingTop: 2
},
dashboardItemValue: {
color: textPrimary,
fontSize: 14,
textAlign: 'center'
},
dashboardItemValueWeight: {
color: textPrimary,
fontSize: 14,
fontWeight: 'bold',
textAlign: 'center'
}
});
export const SelectableIcon = ({selected, children}) => {
return (
{selected &&
}
{children}
);
}
export const ChargeStyle = StyleSheet.create({
stationInfoView: {
padding: 12,
borderRadius: 10,
marginBottom: 12,
alignItems: 'center',
flexDirection: 'row',
...ElevationObject(5),
backgroundColor: colorLight,
justifyContent: 'space-between'
},
infoGroup: {
...$padding(4, 2),
alignItems: 'center'
},
infoTitle: {
color: '#999',
fontSize: 12,
paddingTop: 1
},
infoText: {
color: textPrimary,
fontSize: 13,
fontWeight: 'bold'
},
infoBoldNumber: {
color: textPrimary,
fontSize: 14,
paddingTop: 3,
fontWeight: 'bold'
},
infoStatus: {
fontSize: 14,
fontWeight: 'bold'
},
infoIcon: {
width: 38,
height: 38
},
itemDivide: {
borderTopWidth: 1,
borderTopColor: '#eee'
},
statusSelected: {
color: textPrimary,
...$padding(4, 11),
backgroundColor: colorAccent
},
statusAvailable: {
color: '#90DB0A'
},
statusUnavailable: {
color: '#666',
fontSize: 12,
paddingBottom: 1
},
statusAuthenticated: {
color: '#90DB0A',
fontSize: 12,
paddingBottom: 1
},
statusError: {
color: '#EF3340',
fontSize: 12,
paddingBottom: 1
},
statusWarning: {
color: textLight,
backgroundColor: colorAccent
},
rateText: {
color: textPrimary,
fontSize: 14,
},
ratePrice: {
color: '#000',
fontSize: 14,
},
authText: {
color: '#000',
fontSize: 12,
paddingTop: 2
}
});