/** * V3新版充电结算页面 * @邠心vbe on 2023/12/22 */ 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 TextView from '../../components/TextView'; import Skeleton from 'react-native-reanimated-skeleton'; export default class SummaryV3 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; } } 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 ( {$t("receipt.processTitle")} {$t("receipt.processMessage1")} {$t("receipt.processMessage2")} this.toTransaction()}>{$t("receipt.processMessage3")}. {$t("receipt.processMessage4")}