|
|
@@ -5,9 +5,10 @@
|
|
|
import React, { Component } from 'react';
|
|
|
import { View } from 'react-native';
|
|
|
import apiCharge from '../../api/apiCharge';
|
|
|
+import apiWallet from '../../api/apiWallet';
|
|
|
import Dialog from '../../components/Dialog';
|
|
|
import { ErrorDialog } from '../chargeV2/InfoDialog';
|
|
|
-import { PaymentDefault } from '../payment/PaymentConfig';
|
|
|
+import { PaymentDefault, PAYTYPE } from '../payment/PaymentConfig';
|
|
|
import { PageList } from '../Router';
|
|
|
import StepAuth from './StepAuth';
|
|
|
import StepCharging from './StepCharging';
|
|
|
@@ -28,7 +29,7 @@ export default class ChargingPage extends Component {
|
|
|
lastUpdated: '',
|
|
|
showErrorDialog: false,
|
|
|
showStationDialog: false,
|
|
|
- curerntPerUse: undefined,
|
|
|
+ currentPerUse: "",
|
|
|
currentPayment: PaymentDefault.DEFAULT.payType,
|
|
|
currentPaytype: PaymentDefault.DEFAULT.payName
|
|
|
};
|
|
|
@@ -50,6 +51,24 @@ export default class ChargingPage extends Component {
|
|
|
this.getConnectorInfo();
|
|
|
})
|
|
|
}
|
|
|
+ this.props.navigation.addListener('focus', () => {
|
|
|
+ //console.log("充电流程页面获取焦点" + this.isPageShow, this.state.currentPerUse);
|
|
|
+ if (!this.isPageShow && this.state.currentPerUse == "Pending") {
|
|
|
+ this.isPageShow = true;
|
|
|
+ //console.log("继续充电流程");
|
|
|
+ this.setState({
|
|
|
+ currentPerUse: "Paid"
|
|
|
+ })
|
|
|
+ this.refreshChargeData();
|
|
|
+ } else {
|
|
|
+ this.isPageShow = true;
|
|
|
+ //this.canShowLoginDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.props.navigation.addListener('blur', () => {
|
|
|
+ this.isPageShow = false;
|
|
|
+ //console.log("充电流程页面失去焦点");
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
@@ -91,6 +110,11 @@ export default class ChargingPage extends Component {
|
|
|
connectorInfo: {}
|
|
|
}
|
|
|
state.connectorInfo = res.data;
|
|
|
+ if (res.data.currentPaymentType && res.data.currentPaymentType == PAYTYPE.PAY_PER_USE) {
|
|
|
+ state.currentPayment = PAYTYPE.PAY_PER_USE
|
|
|
+ } else {
|
|
|
+ state.currentPayment = PAYTYPE.CREDIT_WALLET
|
|
|
+ }
|
|
|
console.log("状态", res.data.status);
|
|
|
switch (res.data.status) {
|
|
|
case 'Available': //可用的
|
|
|
@@ -194,6 +218,10 @@ export default class ChargingPage extends Component {
|
|
|
isCharging: true
|
|
|
});
|
|
|
this.waitStartCharging = true;
|
|
|
+ if (this.state.currentPayment == PAYTYPE.PAY_PER_USE) {
|
|
|
+ this.onStartChargePerUse();
|
|
|
+ return;
|
|
|
+ }
|
|
|
apiCharge.startCharge(this.state.stationInfo).then(res => {
|
|
|
console.log("[开始充电-onStartCharge]", res);
|
|
|
setTimeout(() => {
|
|
|
@@ -215,6 +243,31 @@ export default class ChargingPage extends Component {
|
|
|
} else {
|
|
|
this.showErrorDialog('A4', err);
|
|
|
}
|
|
|
+ this.setState({
|
|
|
+ isCharging: false
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ onStartChargePerUse() {
|
|
|
+ const params = {
|
|
|
+ paymentOption: this.state.currentPayment,
|
|
|
+ ...this.state.stationInfo
|
|
|
+ }
|
|
|
+ apiWallet.doPaymentV2(params).then(res => {
|
|
|
+ if (res.data.webPaymentUrl) {
|
|
|
+ this.setState({
|
|
|
+ currentPerUse: "Pending"
|
|
|
+ })
|
|
|
+ startPage(PageList.paymentWeb, { amount: params.payAmount, url: res.data.webPaymentUrl, type: 'PayPerUse' });
|
|
|
+ } else {
|
|
|
+ toastShort('Error 0')
|
|
|
+ }
|
|
|
+ }).catch(({err}) => {
|
|
|
+ this.showErrorDialog('A9', err);
|
|
|
+ this.setState({
|
|
|
+ isCharging: false
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -302,26 +355,23 @@ export default class ChargingPage extends Component {
|
|
|
{ this.state.isStoping
|
|
|
? <StepStop
|
|
|
currentPayment={this.state.currentPayment}
|
|
|
- curerntPerUse={this.state.curerntPerUse}
|
|
|
/>
|
|
|
: ( this.state.isCharging
|
|
|
? <StepCharging
|
|
|
connectorInfo={this.state.connectorInfo}
|
|
|
currentPayment={this.state.currentPayment}
|
|
|
- curerntPerUse={this.state.curerntPerUse}
|
|
|
onStopCharge={() => this.onStopCharge()}
|
|
|
/>
|
|
|
: ( this.state.isAuthentic
|
|
|
? <StepAuth
|
|
|
status={this.state.connectorInfo?.status}
|
|
|
currentPayment={this.state.currentPayment}
|
|
|
- curerntPerUse={this.state.curerntPerUse}
|
|
|
onStartCharge={() => this.onStartCharge()}
|
|
|
+ onPaymentMethodChanged={(type) => this.onPaymentMethodChanged(type)}
|
|
|
/>
|
|
|
: <StepStart
|
|
|
connectorInfo={this.state.connectorInfo}
|
|
|
currentPayment={this.state.currentPayment}
|
|
|
- curerntPerUse={this.state.curerntPerUse}
|
|
|
onAuthenticate={() => this.onAuthenticate()}
|
|
|
onPaymentMethodChanged={(type) => this.onPaymentMethodChanged(type)}
|
|
|
/>
|