| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- /**
- * 充电桩详情页
- * @邠心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 './QRResult';
- 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) => {
- QRResult.clearResult();
- 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 (
- <>
- <ScrollView
- style={styles.container}
- keyboardShouldPersistTaps={isIOS ? 'never' : 'handled'}
- refreshControl={
- <RefreshControl
- {...MyRefreshProps()}
- refreshing={this.state.refreshing}
- onRefresh={() => this.onRefresh()}
- />
- }>
- <View style={styles.headerView}>
- <StationBack />
- <View style={styles.summaryView}>
- <Image
- style={{
- width: 50,
- height: 50,
- marginTop: 8
- }}
- source={require('../../images/charge/icon-station-no.png')}/>
- <View style={styles.stationInfo}>
- <Text
- style={styles.stationName}
- ellipsizeMode='tail'
- numberOfLines={1}>{this.state.stationInfo?.name}</Text>
- {/* <Text style={styles.stationAddress}>{this.state.stationInfo?.address}</Text> */}
- <Provider
- color={textPrimary}
- providers={this.state.stationInfo?.serviceProvider}/>
- </View>
- <TouchableOpacity
- style={styles.directView}
- onPress={() => {
- utils.directMaps(this.state.stationInfo.latitude, this.state.stationInfo.longitude, this.state.stationInfo.address);
- }}>
- <MaterialIcons
- name='directions'
- size={32}
- color={colorPrimary}/>
- <Text style={styles.lengthText}>{this.state.stationInfo.distance}</Text>
- </TouchableOpacity>
- </View>
- <View style={styles.chargingInfo}>
- <View style={styles.available}>
- <Image
- style={{
- width: 16,
- height: 16,
- marginRight: 8
- }}
- source={require('../../images/charge/icon-type-stops.png')}/>
- <Text style={{
- color: textPrimary,
- fontSize: 14
- }}>Available {this.getAvailable('box')}</Text>
- </View>
- <Text style={styles.available2}/>
- <View style={styles.available}>
- <Image
- style={{
- width: 17,
- height: 17,
- marginRight: 8
- }}
- source={require('../../images/charge/icon-type-interfaces.png')}/>
- <Text style={{
- color: textPrimary,
- fontSize: 14
- }}>Available {this.getAvailable('inc')}</Text>
- </View>
- </View>
- </View>
- <View style={styles.tabContainer}>
- { this.state.showContent &&
- <>
- { this.state.showTab &&
- <View style={styles.tabView}>
- { this.state.tabView.map((view, index) => {
- return (
- <Pressable
- key={index}
- style={[
- styles.tabPress,
- index == 0 && styles.tabPress0,
- index == this.state.tabIndex && styles.active
- ]}
- onPress={() => {
- this.changeTab(index)
- }}
- android_ripple={ripple}>
- <Text
- style={[
- styles.tabText,
- index == this.state.tabIndex && styles.active,
- { borderLeftWidth: index > 0 ? 1 : 0 }
- ]}
- numberOfLines={1}>{view.title}</Text>
- </Pressable>
- );
- })
- }
- </View>
- }
- <View style={styles.tabContent}>
- <SiteInfo
- style={this.state.tabIndex == 0 ? styles.tabActive : styles.tabInactive}
- stationInfo={this.state.stationInfo}
- refreshId={this.state.refreshId}/>
- <Charge
- style={this.state.tabIndex == 1 ? styles.tabActive : styles.tabInactive}
- visible={this.state.tabIndex == 1}
- stationInfo={this.state.stationInfo}
- refreshId={this.state.refreshId}
- onCharge={() =>
- this.setState({
- tabIndex: 1
- })
- }/>
- { this.state.stationInfo.rateList !== undefined &&
- <Reserve
- style={this.state.tabIndex == 2 ? styles.tabActive : styles.tabInactive}
- visible={this.state.tabIndex == 2}
- refreshId={this.state.refreshId}
- stationInfo={this.state.stationInfo}
- onRefresh={() => this.updateStationInfo()}
- onReserve={() => this.changeTab(2)}
- onEnterStation={() => this.onEnterStation()}
- />
- }
- {/* <Explore style={this.state.tabIndex == 2 ? styles.tabActive : styles.tabInactive}/> */}
- </View>
- </>
- }
- </View>
- </ScrollView>
- <Modal
- isVisible={this.state.showLoginDialog}
- onBackButtonPress={() => this.hideDialog(true)}
- onBackdropPress={() => this.hideDialog()}
- {...ModalProps}>
- <LoginDialog
- onHide={() => this.hideDialog()}
- onClose={() => this.hideDialog(true)} />
- </Modal>
- </>
- )
- }
- }
- 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'
- }
- })
|