/** * 新版钱包充值页面 * @邠心vbe on 2023/02/02 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, ScrollView, AppState, Linking } from 'react-native'; import apiWallet from '../../api/apiWallet'; import BadgeSelectItem from '../../components/BadgeSelectItem'; import Button, { ElevationObject } from '../../components/Button'; import Dialog from '../../components/Dialog'; import TextView from '../../components/TextView'; import { PaymentDefault } from '../payment/PaymentConfig'; import { PageList } from '../Router'; import { Balance } from './Payment'; import TopupPaythod from './TopupPaythod'; import app from '../../../app.json'; import utils from '../../utils/utils'; import CheckBox from '../../components/CheckBox'; import VbeSkeleton from '../../components/VbeSkeleton'; export default class TopupNew extends Component { constructor(props) { super(props); this.state = { loading: true, isAuto: false, topupList: [], selectIndex: 0, payType: {}, balance: 0, agree: false, isCallback: true }; //this.stateListener; } componentDidMount() { this.props.navigation.addListener('focus', () => { getUserInfo(info => { this.setState({ balance: info?.creditStr }, () => { this.getTopupList(); }) }, true); }); /*this.stateListener = AppState.addEventListener("change", state => { if (state == 'active' && this.state.isCallback) { this.setState({ agree: true, isCallback: false }) } });*/ } componentWillUnmount() { /*if (this.stateListener) { this.stateListener?.remove(); }*/ } getTopupList() { // apiWallet.getTopUpAmountList() apiWallet.getTopUpAmountListV2().then(res => { Dialog.dismissLoading(); if (res.data.length > 0) { this.setState({ topupList: res.data }); } }).catch(err => { toastShort(err) const data = apiWallet.getTempAmountListV2(); this.setState({ topupList: data }); }).finally(() => { this.setState({ loading: false }); }) } /** * 2C2P充值 */ topup2() { const topup = this.state.topupList[this.state.selectIndex] const params = { currency: topup?.currency, payAmount: topup?.amount } if (this.state.payType?.fomoPayType) { params.payTypeSelection = this.state.payType.fomoPayType } Dialog.showProgressDialog(); //console.log('充值请求参数', params); apiWallet.doPaymentV2(params).then(res => { Dialog.dismissLoading(); if (app.charge.anzPayment) { if (res.data.qr) { startPage(PageList.paynow, { info: res.data.qr, type: 'Topup' }); } else if (res.data.webPaymentUrl) { startPage(PageList.paymentWeb, { amount: params.payAmount, url: res.data.webPaymentUrl, type: 'Topup' }); } else { toastShort('Error 01') } } else { if (res.data.webPaymentUrl) { startPage(PageList.paymentWeb, { amount: params.payAmount, url: res.data.webPaymentUrl, type: 'Topup' }); } else { toastShort('Error 0') } } }).catch(err => { Dialog.dismissLoading(); toastShort(err); }); } /** * FOMO充值 */ topup() { const topup = this.state.topupList[this.state.selectIndex] const params = { currency: topup?.currency, payAmount: topup?.amount, fomoPayType: this.state.payType?.fomoPayType } //console.log('params',params); if (params.payAmount) { if (params.fomoPayType == 'PAYNOW' || params.fomoPayType == 'GRABPAY') { //PAYNOW支付 Dialog.showProgressDialog(); apiWallet.doPayment(params).then(res => { Dialog.dismissLoading(); if (res.data.fomoId && res.data.qrCodeInBase64) { startPage(PageList.paynow, { amount: params.payAmount, base64: res.data.qrCodeInBase64 }); } else if (res.data.url) { startPage(PageList.paymentWeb, { amount: params.payAmount, url: res.data.url, type: 'Topup' }); } else { toastShort('Error 0') } }).catch(err => { Dialog.dismissLoading(); toastShort(err); }); } else { //信用卡支付 startPage(PageList.formCard, { amount: params.payAmount, payType: params.fomoPayType }); } } else { toastShort('Error 1') } } changeAgree(ag) { this.setState({ agree: ag }); } toPolicy() { Linking.openURL(app.storeUrl.refundUrl); } render() { if (this.state.loading) { return ( ) } return ( {$t('wallet.titleChooseCreditValue')} { app.modules.nationally ? { this.state.topupList.map((item, index) => { return ( { this.setState({ selectIndex: index }) }}> {item.currencySymbol} {item.amount} {/* {item.currency} */} ); }) } : { this.state.topupList.map((item, index) => { return ( 0 && styles.right]} checked={index == this.state.selectIndex} onPress={() => { this.setState({ selectIndex: index }) }}> {item.currencySymbol} {item.amount} {/* {item.currency} */} ); }) } } { (!PaymentDefault.is2c2p || app.modules.topup_payment_type) && {$t('wallet.titleChoosePaymentType')} { this.setState({ payType: type }); }}/> } { utils.isNotEmpty(app.storeUrl.refundUrl) && this.changeAgree(v)} /> this.changeAgree(!this.state.agree)}> {$t('sign.iHaveReadAndAgree')} this.toPolicy()}>Refund Policy }