/**
* 充电桩详情页
* @邠心vbe on 2021/03/24
*/
import React, { Component } from 'react';
import { Image, Pressable, RefreshControl, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import Modal from 'react-native-modal';
import apiStation from '../../api/apiStation';
import { ModalProps } from '../../components/BottomModal';
import { MyRefreshProps } from '../../components/ThemesConfig';
import { StationBack } from '../../components/Toolbar';
import utils from '../../utils/utils';
import Charge from './Charge';
import Explore from './Explore';
import { LoginDialog } from './InfoDialog';
import Provider from './Provider';
import { QRResult } from './QRScan';
import Reserve from './Reserve';
import SiteInfo from './SiteInfo';
export default class Details extends Component {
constructor(props) {
super(props);
this.state = {
showTab: true,
tabIndex: 1,
tabView: [{
title: 'Site Information'
}, {
title: 'Charge'
}, {
title: 'Reserve'
}],
refreshId: 0,
refreshing: false,
showContent: false,
showLoginDialog: false,
stationInfo: {}
}
}
componentDidMount() {
this.props.navigation.addListener('beforeRemove', (e) => {
this.hideDialog();
});
this.props.navigation.addListener('focus', () => {
if (this.isHide && this.state.showContent) {
this.updateStationInfo();
} else {
//this.canShowLoginDialog();
}
this.isHide = false;
});
this.props.navigation.addListener('blur', () => {
this.isHide = true;
});
const params = this.props.route.params;
if (params.action && params.stationInfo) {
this.action = params.action
this.setState({
stationInfo: params.stationInfo
});
this.canShowLoginDialog();
}
}
componentDidUpdate() {
var act = this.props.route.params.action;
if (act !== this.state.action) {
this.setState({
action: act,
refreshId: this.state.refreshId + 1
});
if (act == 'qr') {
this.setState({
tabIndex: 1
})
}
}
}
componentWillUnmount() {
QRResult.clearResult();
}
canShowLoginDialog() {
if (isLogin()) {
this.setState({
showContent: true
});
//if (this.action !== 'view')
this.updateStationInfo();
if (this.action == 'qr') {
this.setState({
tabIndex: 1
})
}
} else {
this.setState({
showLoginDialog: true
});
}
}
hideDialog(close) {
this.setState({
showLoginDialog: false
});
if (close) {
goBack();
}
}
updateStationInfo() {
navigator.geolocation.getCurrentPosition(location => {
let params = {
lat: location.coords.latitude,
lng: location.coords.longitude,
sitePk: this.state.stationInfo.id
}
apiStation.getStationRate(params).then(res => {
if (res.data.sitePk) {
var info = utils.getSiteInfo(res.data);
this.setState({
refreshing: false,
stationInfo: info,
refreshId: this.state.refreshId + 1
});
}
}).catch((err) => {
toastLong(err);
this.setState({
refreshing: false
})
});
});
}
getAvailable(type) {
const all = this.state.stationInfo.allConnector;
if (all) {
if (type == 'box') {
return all.boxAvailable + '/' + all.boxAll;
} else {
return all.available + '/' + all.all;
}
} else {
return '0/0';
}
}
onRefresh() {
this.setState({
refreshing: true
});
this.updateStationInfo();
}
onEnterStation() {
this.setState({
refreshId: this.state.refreshId + 1
}, () => this.changeTab(1));
}
changeTab(index) {
this.setState({
tabIndex: index
});
}
render() {
return (
<>
this.onRefresh()}
/>
}>
{this.state.stationInfo?.name}
{/* {this.state.stationInfo?.address} */}
{
utils.directMaps(this.state.stationInfo.latitude, this.state.stationInfo.longitude, this.state.stationInfo.address);
}}>
{this.state.stationInfo.distance}
Available {this.getAvailable('box')}
Available {this.getAvailable('inc')}
{ this.state.showContent &&
<>
{ this.state.showTab &&
{ this.state.tabView.map((view, index) => {
return (
{
this.changeTab(index)
}}
android_ripple={ripple}>
0 ? 1 : 0 }
]}
numberOfLines={1}>{view.title}
);
})
}
}
this.setState({
tabIndex: 1
})
}/>
{ this.state.stationInfo.rateList !== undefined &&
this.updateStationInfo()}
onReserve={() => this.changeTab(2)}
onEnterStation={() => this.onEnterStation()}
/>
}
{/* */}
>
}
this.hideDialog(true)}
onBackdropPress={() => this.hideDialog()}
{...ModalProps}>
this.hideDialog()}
onClose={() => this.hideDialog(true)} />
>
)
}
}
const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
backgroundColor: colorLight
},
headerView: {
paddingTop: 16,
paddingLeft: 16,
paddingRight: 16,
paddingBottom: 32,
backgroundColor: colorThemes
},
summaryView: {
paddingBottom: 16,
flexDirection: 'row',
},
stationInfo: {
flex: 1,
paddingLeft: 16,
paddingRight: 16
},
stationName: {
color: textPrimary,
fontSize: 20,
fontWeight: 'bold',
paddingBottom: 2
},
stationAddress: {
color: textPrimary,
fontSize: 12,
},
directView: {
zIndex: 2,
paddingTop: 4,
alignItems: 'center',
},
lengthText: {
color: textPrimary,
fontSize: 12,
paddingTop: 2
},
chargingInfo: {
zIndex: 2,
alignItems: 'center',
borderColor: colorLight,
borderTopWidth: 1,
flexDirection: 'row'
},
available: {
flex: 1,
padding: 16,
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'center'
},
available2: {
color: textPrimary,
fontSize: 14,
borderLeftWidth: 1.5,
borderLeftColor: colorLight,
},
tabContainer: {
flex: 1,
paddingTop: 14,
marginTop: -32,
backgroundColor: colorLight,
borderTopLeftRadius: 20,
borderTopRightRadius: 20
},
tabView: {
marginTop: 8,
marginLeft: 16,
marginRight: 16,
borderRadius: 8,
overflow: 'hidden',
alignItems: 'center',
flexDirection: 'row',
borderWidth: 1,
borderColor: '#eee',
borderBottomWidth: 2
},
tabPress: {
flex: 1,
paddingTop: 12,
paddingBottom: 12,
marginRight: 1
},
tabPress0: {
flex: 1.2
},
tabText: {
color: textPrimary,
fontSize: 15,
marginLeft: -1,
textAlign: 'center',
borderLeftColor: '#eee'
},
active: {
color: textLight,
backgroundColor: colorPrimary
},
tabContent: {
flex: 1
},
tabActive: {
display: 'flex'
},
tabInactive: {
display: 'none'
}
})