/**
* 支付组件
* @邠心vbe on 2021/04/23
*/
import React, { useEffect, useState } from 'react';
import { View, Text, StyleSheet, Image, Pressable } from 'react-native';
import Button, { ElevationObject } from '../../components/Button';
import TextView from '../../components/TextView';
import utils from '../../utils/utils';
import { LowCreditDialog } from '../charge/InfoDialog';
import { PaymentDefault } from '../payment/PaymentConfig';
import { PageList } from '../Router';
const Payment = ({
topup, balance,
payType = PaymentDefault.DEFAULT.payName,
isWallet = PaymentDefault.DEFAULT.isWallet,
isPayPerUse = PaymentDefault.DEFAULT.isPayPerUse,
canShowLowCreditDialog = false,
onMethodChange,
refreshId = 0
}) => {
const [visible, showDialog] = useState(false)
useEffect(() => {
if (balance == undefined && canShowLowCreditDialog) {
if (userInfo.credit <= 5 && refreshId > 0) {
showDialog(true)
}
}
}, [refreshId]);
return (
{ isWallet || isPayPerUse
?
{payType}
:
Visa/Mastercard
Credit/Debit Card
}
{isWallet ? currency + (balance ?? userInfo.credit) : ''}
{ topup
?
);
}
export default Payment;
export const Balance = ({balance=0, balanceText, action, page=PageList.wallet}) => {
return (
startPage(page)}>
{$t('wallet.creditWalletLabel')}
{ balanceText
? {balanceText}
: {getBalance(utils.isNotEmpty(balance) ? balance : userInfo.credit)}
}
{action ?? $t('wallet.viewHistory')}
{ utils.isNotEmpty(page) &&
}
);
}
const getBalance = (balance) => {
console.log('getBalance', balance, userInfo);
return balance ? balance.toFixed(2) : '0.0'
}
const styles = StyleSheet.create({
paymentView: {
borderRadius: 8,
paddingTop: 12,
paddingLeft: 16,
paddingRight: 16,
paddingBottom: 12,
alignItems: 'center',
flexDirection: 'row',
...ElevationObject(5),
backgroundColor: colorLight,
justifyContent: 'space-between'
},
walletIcon: {
width: 36,
height: 36
},
creditText: {
color: textPrimary,
fontSize: 14,
},
rateText: {
color: textPrimary,
fontSize: 14,
},
balance: {
flex: 1,
color: textPrimary,
fontSize: 16,
textAlign: 'right',
fontWeight: 'bold',
paddingRight: 24,
},
balanceIcon: {
width: 30,
height: 30
},
balanceTitle: {
color: '#000',
fontSize: 16,
paddingLeft: 12,
fontWeight: 'bold'
},
balanceValue: {
color: '#000',
fontSize: 18,
paddingLeft: 6
},
infoStatus: {
paddingTop: 4,
paddingLeft: 10,
paddingRight: 10,
paddingBottom: 4,
borderRadius: 4
},
selected: {
color: colorAccent,
backgroundColor: colorDark
},
topupView: {
borderRadius: 4,
backgroundColor: colorDark
},
topupText: {
color: colorAccent,
fontSize: 12,
fontWeight: 'normal'
},
balanceView: {
margin: 16,
padding: 16,
alignItems: 'center',
flexDirection: 'row',
borderRadius: 6,
overflow: 'hidden',
...ElevationObject(5),
backgroundColor: colorLight
},
actionText: {
color: textCancel,
fontSize: 12,
paddingLeft: 8,
paddingRight: 2
}
});