/** * 新版充电结算页面 * @邠心vbe on 2023/02/08 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, Image, ScrollView, RefreshControl } from 'react-native'; import apiCharge from '../../api/apiCharge'; import Button from '../../components/Button'; import Dialog from '../../components/Dialog'; import { MyRefreshProps } from '../../components/ThemesConfig'; import utils from '../../utils/utils'; import { PageList } from '../Router'; import { ChargeStyle, TypeImage } from './Charging'; export default class Summary extends Component { constructor(props) { super(props); this.state = { isActully: true, refreshing: false, summaryInfo: {}, stationInfo: {} }; this.canBack = false; } componentDidMount() { const params = this.props.route.params; if (params.chargingPk) { Dialog.showProgressDialog(); if (params.name && params.address) { this.setState({ chargingPk: params.chargingPk, stationInfo: { id: params.id, name: params.name, address: params.address } }); setTimeout(() => { this.getSummaryData(params.chargingPk); }, 5000); } else if (params.action && params.action == "view") { this.setState({ isActully: false, chargingPk: params.chargingPk }); this.getSummaryData(params.chargingPk); } } this.props.navigation.addListener('focus', e => { this.canBack = false; }); /*this.props.navigation.addListener('beforeRemove', e => { if (this.state.isActully && !this.canBack) { this.toRating(); e.preventDefault(); } });*/ } getSummaryData(chargingPk) { apiCharge.getChargeSummary({ chargingPk: chargingPk }).then(res => { Dialog.dismissLoading(); if (res.data) { this.setState({ refreshing: false, summaryInfo: res.data }); } }).catch(err => { Dialog.dismissLoading(); toastShort(err); this.setState({ refreshing: false }); }); } onRefresh() { if (this.state.chargingPk) { this.setState({ refreshing: true }); this.getSummaryData(this.state.chargingPk); } } toRating() { this.canBack = true; goBack(); //startPage(PageList.rating, this.state.stationInfo); } getSummaryText(data) { if (this.state.summaryInfo?.paymentType == 'Fleet Credit') { return '-'; } else { return currency + '' + (data ?? '0'); } } render() { return ( this.onRefresh()} /> }> Transation ID: {this.state.summaryInfo.transactionPk} Reference ID: {this.state.summaryInfo.chargingPk} Date Time: {this.state.summaryInfo.dateTime} Your Station Station ID: {this.state.summaryInfo.chargeBoxPk} {this.state.summaryInfo.boxAddress} Your Connector = 0 ? TypeImage.AC : TypeImage.DC}/> {this.state.summaryInfo.connectorType} Type {this.state.summaryInfo.connectorWattage} Power {this.state.summaryInfo.connectorRate} Rates Breakdown Reservation Fee: {currency}{this.state.summaryInfo.reservationFee ?? 0} { utils.isNotEmpty(this.state.summaryInfo.idleFee) && Idle Fee: {currency}{this.state.summaryInfo.idleFee} } Charge Time: {utils.hour2HHmm(this.state.summaryInfo.chargeTime)} Charge Delivered: {this.state.summaryInfo.chargeDelivered ?? 0}kWh Charge Rates (GST Inclusive): {currency}{this.state.summaryInfo.chargeRates ?? '0.0'} Subtotal Payment Made By: {this.state.summaryInfo.paymentType} Previous Balance: {this.getSummaryText(this.state.summaryInfo.previousBalance)} Payment (GST Inclusive): {currency}{this.state.summaryInfo.payment ?? '0.0'} Resulting Balance: {this.getSummaryText(this.state.summaryInfo.resultingBalance)} { this.state.isActully && startPage(PageList.feedback)}>Submit Your Feedback A Receipt Will Be Sent To Your Email