/** * 新版充电结算页面 * @邠心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 TextView from '../../components/TextView'; import { MyRefreshProps } from '../../components/ThemesConfig'; import routeUtil from '../../utils/routeUtil'; 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(); //routeUtil.resetToHome(this.props); startPage(PageList.home); //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()} /> }> {$t('wallet.labelTransactionId')} {this.state.summaryInfo.transactionPk} {$t('wallet.labelReferenceId')} {this.state.summaryInfo.chargingPk} {$t('wallet.labelDateTime')} {this.state.summaryInfo.dateTime} {$t('wallet.labelYourStation')} {$t('wallet.labelStationId') + this.state.summaryInfo.chargeBoxPk} {this.state.summaryInfo?.boxAddress} {$t('wallet.labelYourConnector')} = 0 ? TypeImage.AC : TypeImage.DC}/> {this.state.summaryInfo.connectorType} {$t('charging.labelType')} {this.state.summaryInfo.connectorWattage} {$t('charging.labelPower')} {this.state.summaryInfo.connectorRate} {$t('charging.labelRate')} {$t('wallet.labelBreakdown')} {$t('wallet.labelReservationFee')} {currency}{this.state.summaryInfo.reservationFee ?? 0} { utils.isNotEmpty(this.state.summaryInfo.idleFee) && {$t('wallet.labelIdleFee')} {currency}{this.state.summaryInfo.idleFee} } {$t('wallet.labelChargeTime')} {utils.hour2HHmm(this.state.summaryInfo.chargeTime)} {$t('wallet.labelChargeDelivered')} {this.state.summaryInfo.chargeDelivered ?? 0}kWh {$t('wallet.labelChargeRates')} {currency}{this.state.summaryInfo.chargeRates ?? '0.0'} {$t('wallet.labelSubtotal')} {$t('wallet.labelPaymentMadeBy')} {this.state.summaryInfo.paymentType} {$t('wallet.labelPreviousBalance')} {this.getSummaryText(this.state.summaryInfo.previousBalance)} {$t('wallet.labelPayment')} {currency}{this.state.summaryInfo.payment ?? '0.0'} {$t('wallet.labelExchangeRate')} {this.getSummaryText(this.state.summaryInfo.exchangeRate)} {$t('wallet.labelFinalPayment')} {this.getSummaryText(this.state.summaryInfo.finalPayment)} {$t('wallet.labelResultingBalance')} {this.getSummaryText(this.state.summaryInfo.resultingBalance)} { this.state.isActully && startPage(PageList.feedback)}>{$t('wallet.linkSubmitFeedback')} {$t('wallet.tipsReceipt')}