| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /**
- * 支付组件
- * @邠心vbe on 2021/04/23
- */
- import React, { useState } from 'react';
- import { useEffect } from 'react';
- import { View, Text, StyleSheet, Image } from 'react-native';
- import Button from '../../components/Button';
- import TextRadius from '../../components/TextRadius';
- import utils from '../../utils/utils';
- import { LowCreditDialog } from '../charge/InfoDialog';
- import { PageList } from '../Router';
- const Payment = ({topup, balance, payType="Credit Wallet", onMethodChange, isWallet = true, refreshId = 0}) => {
- const [visible, showDialog] = useState(false)
- /*useEffect(() => {
- if (balance == undefined) {
- if (userInfo.credit <= 5 && refreshId > 0) {
- showDialog(true)
- }
- }
- }, [refreshId])*/
- return (
- <View style={styles.paymentView}>
- <Image
- style={styles.walletIcon}
- source={require('../../images/charge/ic-payment.png')}
- />
- { isWallet
- ? <View style={{paddingLeft: 16}}>
- <Image
- style={{
- width: 51,
- height: 16
- }}
- source={require('../../images/app-logo.png')}/>
- <Text
- style={styles.rateText}
- numberOfLines={1}
- ellipsizeMode={'clip'}>{payType}</Text>
- </View>
- : <View style={{paddingLeft: 16}}>
- <Text style={styles.creditText}>Visa/Mastercard</Text>
- <Text style={styles.creditText}>Credit/Debit Card</Text>
- </View>
- }
- <Text
- style={styles.balance}
- numberOfLines={1}
- suppressHighlighting={true}>
- {isWallet ? currency + (balance ?? userInfo.credit) : ''}
- </Text>
- { topup
- ? <Button
- style={styles.topupView}
- text="+ Top Up"
- textStyle={styles.topupText}
- viewStyle={styles.infoStatus}
- onClick={topup}/>
- : <Button
- style={styles.topupView}
- text="Selected"
- textStyle={styles.topupText}
- viewStyle={styles.infoStatus}
- onClick={() => {if (onMethodChange) onMethodChange()}}/>
- }
- <LowCreditDialog
- visible={visible}
- onClose={topup => {
- showDialog(false)
- if (topup) {
- startPage(PageList.topup)
- } else {
- //goBack();
- }
- }
- }/>
- </View>
- );
- }
- export default Payment;
- export const Balance = ({balance}) => {
- return (
- <View style={styles.balanceView}>
- <Image
- style={styles.balanceIcon}
- source={require('../../images/icon/draw-wallet.png')}/>
- <Text style={styles.balanceTitle}>Credit Wallet</Text>
- <Text style={styles.balanceValue}>{currency}{getBalance(utils.isNotEmpty(balance) ? balance : userInfo.credit)}</Text>
- </View>
- );
- }
- export const PAYTYPE = {
- CREDIT_WALLET: "CreditWallet", // 钱包余额支付
- PAY_PER_USE: "PayPerUse" // 按次支付
- }
- 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',
- backgroundColor: '#F5F5F5',
- justifyContent: 'space-between'
- },
- walletIcon: {
- width: 36,
- height: 36
- },
- creditText: {
- color: '#333',
- fontSize: 14,
- },
- rateText: {
- color: '#333',
- fontSize: 14,
- },
- balance: {
- flex: 1,
- color: '#333',
- fontSize: 16,
- textAlign: 'right',
- fontWeight: 'bold',
- paddingRight: 24,
-
- },
- balanceIcon: {
- width: 30,
- height: 30
- },
- balanceTitle: {
- flex: 1,
- color: '#000',
- fontSize: 16,
- paddingLeft: 12
- },
- balanceValue: {
- color: '#000',
- fontSize: 18,
- paddingRight: 6
- },
- infoStatus: {
- paddingTop: 4,
- paddingLeft: 10,
- paddingRight: 10,
- paddingBottom: 4,
- borderRadius: 4
- },
- selected: {
- color: colorAccent,
- backgroundColor: '#333'
- },
- topupView: {
- borderRadius: 4,
- backgroundColor: '#333'
- },
- topupText: {
- color: colorAccent,
- fontSize: 12,
- fontWeight: 'normal'
- },
- balanceView: {
- padding: 16,
- alignItems: 'center',
- flexDirection: 'row'
- }
- });
|