/**
* 新版充电结算页面
* @邠心vbe on 2023/02/08
*/
import React, { Component } from 'react';
import { View, Text, StyleSheet, 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 app from '../../../app.json';
import TextView from '../../components/TextView';
import Skeleton from 'react-native-reanimated-skeleton';
export default class SummaryV2 extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
isActully: true,
refreshing: false,
summaryInfo: {
top: {},
station: {},
connector: {},
chargingFee: {},
idleFee: {},
reservationFee: {},
payment: {}
},
chargingPk: "",
isPendding: false
};
this.action = "";
this.canBack = false;
}
componentDidMount() {
const params = this.props.route.params;
if (params.chargingPk) {
//Dialog.showProgressDialog();
this.setState({
chargingPk: params.chargingPk
})
if (params.action && params.action == "view") {
this.setState({
isActully: false
});
setTimeout(() => {
this.getSummaryData(params.chargingPk);
}, 1000);
} else {
setTimeout(() => {
this.getSummaryData(params.chargingPk);
}, 3000);
}
}
if (params.action) {
this.action = params.action;
}
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.getChargeSummaryV2({
chargingPk: chargingPk
}).then(res => {
//Dialog.dismissLoading();
if (res.data) {
this.setState({
loading: false,
refreshing: false,
summaryInfo: res.data,
isPendding: (res.data.hasSettled != true)
});
}
}).catch((err) => {
//Dialog.dismissLoading();
toastShort(err);
this.setState({
isPendding: true,
refreshing: false
});
});
}
onRefresh() {
if (this.state.chargingPk) {
this.setState({
refreshing: true
});
this.getSummaryData(this.state.chargingPk);
}
}
toRating() {
this.canBack = true;
if (this.action == "view") {
goBack();
} else {
//routeUtil.resetToHome(this.props);
startPage(PageList.home);
//startPage(PageList.rating, this.state.stationInfo);
}
}
toTransaction() {
if (this.action == "view") {
goBack();
} else {
startPage(PageList.wallet)
}
}
getSummaryText(data) {
if (this.state.summaryInfo?.paymentType == 'Fleet Credit') {
return '-';
} else {
return currency + '' + (data ?? '0');
}
}
getTaxTitle(title="") {
if (this.state.summaryInfo?.taxRate) {
return title.replace("$s", this.state.summaryInfo.taxRate)
} else {
return title.replace(" ($s)", "");
}
}
isLoading(precond) {
return utils.isNotEmpty(precond) || this.state.loading;
}
getSkeletonLeft(size=3) {
const list = [];
for (let i = 0; i < size; i++) {
list.push({width: i % 2 ==0 ? '100%' : '70%', height: 18, marginTop: 4, marginBottom: 4, borderRadius: 3});
}
return list;
}
getSkeletonRight(size=3) {
const list = [];
for (let i = 0; i < size; i++) {
list.push({width: '100%', height: 18, marginTop: 4, marginBottom: 4, borderRadius: 3});
}
return list;
}
getSectionSkeleton(size) {
if (this.state.loading) {
return (
)
} else {
return <>>
}
}
render() {
if (this.state.isPendding) {
return (
this.onRefresh()}
/>
}>
{$t("receipt.processTitle")}
{$t("receipt.processMessage1")}
Please pull down refresh this page after a few minutes to view your receipt.
{/*
{$t("receipt.processMessage2")}
this.toTransaction()}>{$t("receipt.processMessage3")}.
*/}
{$t("receipt.processMessage4")}
)
} else {
return (
this.onRefresh()}
/>
}>
{ this.isLoading(this.state.summaryInfo.top) &&
{ this.state.isActully && <>
{$t('receipt.successful')}
{$t('receipt.chargingSessionComplete')}
>}
{ utils.isNotEmpty(this.state.summaryInfo.top.company) &&
{$t('sign.labelCompany')}:
{this.state.summaryInfo.top.company}
}
{ utils.isNotEmpty(this.state.summaryInfo.top.registrationNo) &&
{$t('receipt.labelRegistrationNo')}
{this.state.summaryInfo.top.registrationNo}
}
{ utils.isNotEmpty(this.state.summaryInfo.top.transactionId) &&
{$t('receipt.labelTransactionID')}
{this.state.summaryInfo.top.transactionId}
}
{ utils.isNotEmpty(this.state.summaryInfo.top.referenceId) &&
{$t('receipt.labelReferenceID')}
{this.state.summaryInfo.top.referenceId}
}
{ utils.isNotEmpty(this.state.summaryInfo.top.dateTime) &&
{$t('receipt.labelDateTime')}
{this.state.summaryInfo.top.dateTime}
}
}
{this.getSectionSkeleton(2)}
{/*
{$t('wallet.labelTransactionId')}
{this.state.summaryInfo.transactionPk}
{$t('wallet.labelReferenceId')}
{this.state.summaryInfo.chargingPk}
{$t('wallet.labelDateTime')}
{this.state.summaryInfo.dateTime}
*/}
{ utils.isNotEmpty(this.state.summaryInfo.station) &&
{$t('wallet.labelYourStation')}
{$t('wallet.labelStationId')}
{this.state.summaryInfo.station.stationId}
{$t('receipt.labelSiteName')}
{this.state.summaryInfo.station.siteName ?? "-"}
}
{this.getSectionSkeleton()}
{ utils.isNotEmpty(this.state.summaryInfo.connector) &&
{$t('wallet.labelYourConnector')}
{$t('charging.labelType')}:
{this.state.summaryInfo.connector.type}
{$t('charging.labelPower')}:
{this.state.summaryInfo.connector.power}
{$t('charging.labelRates')}:
{this.state.summaryInfo.connector.rates}
}
{this.getSectionSkeleton()}
{ utils.isNotEmpty(this.state.summaryInfo.chargingFee) &&
{$t('receipt.breakdownChargingFees')}
{$t('wallet.labelChargeTime')}
{this.state.summaryInfo.chargingFee.chargeTime ?? "-"}
{$t('wallet.labelChargeDelivered')}
{this.state.summaryInfo.chargingFee.chargeDelivered ?? 0}
{this.getTaxTitle($t('receipt.labelChargTransSubtotal2'))}
{this.state.summaryInfo.chargingFee.transactionSubtotal}
}
{this.getSectionSkeleton()}
{ utils.isNotEmpty(this.state.summaryInfo.idleFeeV2) &&
{$t('receipt.breakdownIdlesFees')}
Idle Fee Rules:
{this.state.summaryInfo.idleFeeV2.idleRule}
Grace Period Start Time:
{this.state.summaryInfo.idleFeeV2.gracePeriodStartTime}
Idle Fee Start Time:
{this.state.summaryInfo.idleFeeV2.idlePeriodStartTime}
Idle Fee Period:
{this.state.summaryInfo.idleFeeV2.idlePeriod}
Idle Fee End Time:
{this.state.summaryInfo.idleFeeV2.idlePeriodEndTime}
{$t('receipt.labelIdleFeeSubtotal3')}
{this.state.summaryInfo.idleFeeV2.sumFee}
}
{/* utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
{$t('receipt.breakdownIdlesFees')}
{$t('receipt.labelIdleStartTime')}
{this.state.summaryInfo.idleFee.startTime}
{$t('receipt.labelIdleDuration')}
{this.state.summaryInfo.idleFee.duration}
{$t('receipt.labelIdleFeeSubtotal3')}
{this.state.summaryInfo.idleFee.subtotal}
*/}
{this.getSectionSkeleton()}
{ utils.isNotEmpty(this.state.summaryInfo.reservationFee) &&
{$t('receipt.breakdownReservationFees')}
{$t('receipt.labelTimeReservation')}
{this.state.summaryInfo.reservationFee.reservationTime}
{$t('receipt.labelDurationReservation')}
{this.state.summaryInfo.reservationFee.reservationDuration}
{this.getTaxTitle($t('receipt.labelReservationFeeSubtotal2'))}
{this.state.summaryInfo.reservationFee.reservationFeeSubtotal}
}
{this.getSectionSkeleton(8)}
{ utils.isNotEmpty(this.state.summaryInfo.payment) &&
{$t('receipt.breakdownPayment')}
{$t('wallet.labelPaymentMadeBy')}
{this.state.summaryInfo.payment.paymentMadeBy ?? "-"}
{ utils.isNotEmpty(this.state.summaryInfo.payment.transactionSubtotal) &&
{this.getTaxTitle($t('receipt.labelChargTransSubtotal2'))}
{this.state.summaryInfo.payment.transactionSubtotal}
}
{ utils.isNotEmpty(this.state.summaryInfo.payment.idleFeeSubtotal) &&
{$t('receipt.labelIdleFeeSubtotal3')}
{this.state.summaryInfo.payment.idleFeeSubtotal}
}
{ utils.isNotEmpty(this.state.summaryInfo.payment.reservationFeeSubtotal) &&
{this.getTaxTitle($t('receipt.labelReservationFeeSubtotal2'))}
{this.state.summaryInfo.payment.reservationFeeSubtotal}
}
{ utils.isNotEmpty(this.state.summaryInfo.payment.finalPayment) &&
{ utils.isNotEmpty(this.state.summaryInfo.payment.discountCredit)
? $t('receipt.labelAfterDiscount')
: $t('receipt.labelFinalPaymentAmount')
}
{this.state.summaryInfo.payment.finalPayment ?? "-"}
}
{/*
{$t('wallet.labelChargeRates')}
{currency}{this.state.summaryInfo.chargeRates ?? '0.0'}
*/}
{ utils.isNotEmpty(this.state.summaryInfo.payment.exchangeRate) &&
{$t('wallet.labelExchangeRate')}
{this.state.summaryInfo.payment.exchangeRate ?? "-"}
}
{/*
{$t('wallet.labelPreviousBalance')}
{this.getSummaryText(this.state.summaryInfo.previousBalance)}
*/}
{ utils.isNotEmpty(this.state.summaryInfo.payment.resultingBalance) &&
{$t('wallet.labelResultingBalance')}
{this.state.summaryInfo.payment.resultingBalance ?? "-"}
}
{ utils.isNotEmpty(this.state.summaryInfo.payment.refundAmount) &&
{$t('wallet.labelRefundAmount')}
{this.state.summaryInfo.payment.refundAmount ?? "-"}
}
}
{ (this.state.isActully && utils.isNotEmpty(this.state.summaryInfo.top)) &&
{/* startPage(PageList.feedback)}>{$t('wallet.linkSubmitFeedback')} */}
{/* {$t('wallet.tipsReceipt')} */}
}
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingLeft: 16,
paddingRight: 16,
backgroundColor: colorLight
},
headerView: {
alignItems: 'center',
paddingTop: 16,
paddingBottom: 24
},
topTitle: {
color: textPrimary,
fontSize: 16,
paddingTop: 8,
paddingLeft: 8,
fontWeight: 'bold'
},
topDesc: {
color: textPrimary,
fontSize: 14,
marginBottom: 32
},
sections: {
borderRadius: 10,
marginBottom: 12,
backgroundColor: colorLight
},
sections2: {
paddingTop: 0,
paddingLeft: 0,
paddingRight: 0,
paddingBottom: 8,
borderRadius: 10,
marginBottom: 8,
backgroundColor: colorLight
},
formTitle: {
color: '#000',
fontSize: 14,
marginTop: -4,
marginBottom: 6,
paddingBottom: 6,
fontWeight: 'bold',
borderBottomWidth: 1,
borderBottomColor: textPrimary
},
formRow: {
paddingTop: 3,
paddingBottom: 3,
alignItems: 'center',
flexDirection: 'row'
},
label: {
flex: 1,
color: textPrimary,
fontSize: 13,
},
text: {
color: textPrimary,
fontSize: 12,
fontWeight: 'bold'
},
stationInfoView: {
padding: 12,
marginBottom: 0,
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-between'
},
stationInfoText: {
color: '#999',
fontSize: 11
},
connectorView: {
alignItems: 'center',
flexDirection: 'row'
},
typeIcon: {
width: 36,
height: 36
},
feedback: {
color: '#12A5F9',
fontSize: 14,
textAlign: 'center',
marginBottom: 16,
...ui.underline
},
bottomButton: {
marginTop: 16,
marginBottom: 32
},
tipText: {
color: textPrimary,
fontSize: 12,
textAlign: 'center',
marginBottom: 8
},
processContent: {
flex: 1,
justifyContent: 'center'
},
processTitle: {
color: textTitle,
fontSize: 24,
fontWeight: 'bold',
textAlign: 'center'
},
processText: {
color: textPrimary,
fontSize: 14,
textAlign: 'center',
paddingTop: 16
}
});