/** * 新版充电页面 * @邠心vbe on 2023/02/06 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, ImageBackground, Image, ScrollView } from 'react-native'; import apiCharge from '../../api/apiCharge'; import Button from '../../components/Button'; import Dialog from '../../components/Dialog'; import { PageList } from '../Router'; import { BatteryView, ChargeStyle, circleSize, DashboardView, EnterStationDialog, TypeImage } from './Charging'; import Payment, { PaymentDefault, PAYTYPE } from '../wallet/Payment'; import { QRResult } from '../charge/QRScan'; import { ErrorDialog } from './InfoDialog'; import utils from '../../utils/utils'; import PagerUtil from './PagerUtil'; import { PaymentList } from './Payment'; import BadgeSelectItem from '../../components/BadgeSelectItem'; export default class TabCharge extends Component { constructor(props) { super(props); this.state = { available: false, isPrivate: false, refreshId: 0, isStart: false, isPending: false, isCharging: false, isAuthentic: false, selectRate: '', connectorInfo: {}, stationInfo: {}, lastUpdated: '', errorCode: 'A9', errorMessage: '', showErrorDialog: false, showStationDialog: false, curerntPerUser: undefined, //currentPayment: PAYTYPE.CREDIT_WALLET, //currentPaytype: "Credit Wallet", currentPayment: PaymentDefault.DEFAULT.payType, currentPaytype: PaymentDefault.DEFAULT.payName }; this.changeMethod = false; this.canAutoRefresh = false; this.inputStationId = ''; } componentDidMount() { this.canAutoRefresh = true; PagerUtil.addOnRefresh(this); this.onRefresh(); } onRefresh() { console.log("Charge刷新", this.props.route.name); const info = PagerUtil.getStationInfo(); this.setState({ stationInfo: info }, () => { this.init(); //console.log("站点信息", this.state.stationInfo); //this.checkIsCharge(); }); } init() { console.log("Charge刷新", "init"); this.onMethodChanged(); this.refreshAvailable(); if (QRResult.haveResult()) { console.log("Charge刷新", "haveResult"); const info = QRResult.getResult() console.log('QRResult', info); this.setState({ isAuthentic: true, connectorInfo: info //soc: info.chargeType == 'AC' ? 0 : 'In Charging' }); this.checkChargeStatus(); } else if (this.state.isStart) { console.log("Charge刷新", "isStart"); this.checkIsCharge(); } else { console.log("Charge刷新", "noStart"); this.getConnectorInfo(); //this.checkChargeStatus(); } } componentWillUnmount() { this.canAutoRefresh = false; } //刷新可用充电接口 refreshAvailable() { const info = this.state.stationInfo const all = info?.allConnector; if (info.siteType == 'Private') { this.setState({ isPrivate: true }) } if (all) { this.setState({ available: !all.available > 0 }); } } enterStatioinId() { if (QRResult.haveResult()) { const info = QRResult.getResult() console.log('EnterResult', info); this.setState({ isAuthentic: true, connectorInfo: info //soc: info.chargeType == 'AC' ? 0 : 'In Charging' }); this.checkChargeStatus(); } } onPaymentMethodChanged(payment) { this.setState({ currentPayment: payment }) } onMethodChange() { this.changeMethod = true; startPage(PageList.paymentMethod, {info: this.state.connectorInfo, type: this.state.currentPayment}); } onMethodChanged() { if (this.changeMethod) { this.changeMethod = false; if (global.paymentOption?.title) { this.setState({ curerntPerUser: global.paymentOption.amount, currentPayment: global.paymentOption.value, currentPaytype: global.paymentOption.title }, () => { global.paymentOption= {} }) } } } //扫码之前和扫码之后的站点信息Section StationInfo() { return ( {/* {this.state.connectorInfo.connectorId} */} = 0 ? TypeImage.AC : TypeImage.DC}/> {this.state.connectorInfo.chargeType}{this.state.connectorInfo.wattage} Type {currency}{this.state.connectorInfo.rate}/{this.state.connectorInfo.rateType} Rate {this.state.connectorInfo.wattage}kW{/*this.state.connectorInfo.rateType*/} Power { this.state.isCharging ? (this.state.isPending ? ( Preparing ) : ( Charging ) ) : (this.state.connectorInfo.isCheckThrough ? ( Authenticated ) : ( Not Connected ) ) } Status ); } //扫码之前-站点信息Section-end //初始页面-扫码认证之前 StepRateView() { return ( All rates Include 8% GST AC Chargers ({this.state.stationInfo?.acConnector?.available ?? "0"} available) { this.state.stationInfo.acRates?.length > 0 ? this.state.stationInfo.acRates.map((item, index) => { return ( {item.type} Type {item.rates} Rate {item.power} Power { item?.connectorCount?.available > 0 ? Available : Unavailable } Status ); }) : No Rates } DC Chargers ({this.state.stationInfo?.dcConnector?.available ?? "0"} available) { this.state.stationInfo.dcRates?.length > 0 ? this.state.stationInfo.dcRates.map((item, index) => { return ( {item.type} Type {item.rates} Rate {item.power} Power { item?.connectorCount?.available > 0 ? Available : Unavailable } Status ); }) : No Rates } { this.state.isPrivate && NOTE: The charging stations are for private usage. } {/* */}