/** * 充电页面 * @邠心vbe on 2021/04/12 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, ImageBackground, Image, TextInput } 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, EnterStationDialog, TypeImage } from './Charging'; import Payment from '../wallet/Payment'; import QRResult from './QRResult'; import { ErrorDialog } from './InfoDialog'; import utils from '../../utils/utils'; import TextView from '../../components/TextView'; import { PaymentDefault, PAYTYPE } from '../payment/PaymentConfig'; export default class Charge extends Component { constructor(props) { super(props); this.state = { available: false, isPrivate: false, refreshId: 0, isStart: false, isPending: false, isCharging: false, isAuthentic: false, rateList: [], 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; if (this.props.stationInfo) { this.setState({ rateList: this.props.stationInfo.rateList ?? [], stationInfo: this.props.stationInfo }, () => { this.refreshAvailable(); this.checkIsCharge(); }); } } componentDidUpdate() { if (this.props.visible && this.props.refreshId != this.state.refreshId) { this.onMethodChanged(); this.setState({ refreshId: this.props.refreshId, rateList: this.props.stationInfo.rateList ?? [], stationInfo: this.props.stationInfo }, () => this.refreshAvailable()); if (QRResult.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) { this.checkIsCharge(); } else { 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(); } } 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} Type {this.state.connectorInfo.chargeType}{this.state.connectorInfo.wattage} Power {this.state.connectorInfo.wattage}kW{/*this.state.connectorInfo.rateType*/} Rate {currency}{this.state.connectorInfo.rate}/{this.state.connectorInfo.rateType} { this.state.connectorInfo.isCheckThrough ? Authenticated : Not Connected } ); } //扫码之前-站点信息Section-end //扫码之后-选择的站点信息Section UseStationInfo() { return ( {this.state.connectorInfo.connectorId} Type {this.state.connectorInfo.chargeType}{this.state.connectorInfo.wattage} Power {this.state.connectorInfo.wattage}kW Rate {currency}{this.state.connectorInfo.rate}/{this.state.connectorInfo.rateType} In Use Time Elapsed {this.state.connectorInfo.timeElapsed?.toFixed(0) ?? 0} Minutes Total kWh Delivered {this.state.connectorInfo.totalKWhDelivered ?? 0} kWh Total Charges {currency} {this.state.connectorInfo.totalCharges?.toFixed(2) ?? '0.0'} ); } //扫码之后-选择的站点信息Section-end //初始页面-扫码认证之前 StepRateView() { return ( <> Rates { this.state.rateList.length > 0 ? this.state.rateList.map((item, index) => { return ( 0 ? ChargeStyle.itemDivide : {}]}> = 0 ? TypeImage.AC : TypeImage.DC}/> Type {item.type} Power {item.power} Rate {item.rates} { item?.connectorCount?.available > 0 ? Available : Unavailable } ); }) : No Rates } { this.state.isPrivate && NOTE: The charging stations are for private usage. }