Payment.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * 支付组件
  3. * @邠心vbe on 2021/04/23
  4. */
  5. import React, { useState } from 'react';
  6. import { useEffect } from 'react';
  7. import { View, Text, StyleSheet, Image } from 'react-native';
  8. import Button from '../../components/Button';
  9. import TextRadius from '../../components/TextRadius';
  10. import utils from '../../utils/utils';
  11. import { LowCreditDialog } from '../charge/InfoDialog';
  12. import { PageList } from '../Router';
  13. const Payment = ({topup, balance, payType="Credit Wallet", onMethodChange, isWallet = true, refreshId = 0}) => {
  14. const [visible, showDialog] = useState(false)
  15. /*useEffect(() => {
  16. if (balance == undefined) {
  17. if (userInfo.credit <= 5 && refreshId > 0) {
  18. showDialog(true)
  19. }
  20. }
  21. }, [refreshId])*/
  22. return (
  23. <View style={styles.paymentView}>
  24. <Image
  25. style={styles.walletIcon}
  26. source={require('../../images/charge/ic-payment.png')}
  27. />
  28. { isWallet
  29. ? <View style={{paddingLeft: 16}}>
  30. <Image
  31. style={{
  32. width: 51,
  33. height: 16
  34. }}
  35. source={require('../../images/app-logo.png')}/>
  36. <Text
  37. style={styles.rateText}
  38. numberOfLines={1}
  39. ellipsizeMode={'clip'}>{payType}</Text>
  40. </View>
  41. : <View style={{paddingLeft: 16}}>
  42. <Text style={styles.creditText}>Visa/Mastercard</Text>
  43. <Text style={styles.creditText}>Credit/Debit Card</Text>
  44. </View>
  45. }
  46. <Text
  47. style={styles.balance}
  48. numberOfLines={1}
  49. suppressHighlighting={true}>
  50. {isWallet ? currency + (balance ?? userInfo.credit) : ''}
  51. </Text>
  52. { topup
  53. ? <Button
  54. style={styles.topupView}
  55. text="+ Top Up"
  56. textStyle={styles.topupText}
  57. viewStyle={styles.infoStatus}
  58. onClick={topup}/>
  59. : <Button
  60. style={styles.topupView}
  61. text="Selected"
  62. textStyle={styles.topupText}
  63. viewStyle={styles.infoStatus}
  64. onClick={() => {if (onMethodChange) onMethodChange()}}/>
  65. }
  66. <LowCreditDialog
  67. visible={visible}
  68. onClose={topup => {
  69. showDialog(false)
  70. if (topup) {
  71. startPage(PageList.topup)
  72. } else {
  73. //goBack();
  74. }
  75. }
  76. }/>
  77. </View>
  78. );
  79. }
  80. export default Payment;
  81. export const Balance = ({balance}) => {
  82. return (
  83. <View style={styles.balanceView}>
  84. <Image
  85. style={styles.balanceIcon}
  86. source={require('../../images/icon/draw-wallet.png')}/>
  87. <Text style={styles.balanceTitle}>Credit Wallet</Text>
  88. <Text style={styles.balanceValue}>{currency}{getBalance(utils.isNotEmpty(balance) ? balance : userInfo.credit)}</Text>
  89. </View>
  90. );
  91. }
  92. export const PAYTYPE = {
  93. CREDIT_WALLET: "CreditWallet", // 钱包余额支付
  94. PAY_PER_USE: "PayPerUse" // 按次支付
  95. }
  96. const getBalance = (balance) => {
  97. console.log('getBalance', balance, userInfo);
  98. return balance ? balance.toFixed(2) : '0.0'
  99. }
  100. const styles = StyleSheet.create({
  101. paymentView: {
  102. borderRadius: 8,
  103. paddingTop: 12,
  104. paddingLeft: 16,
  105. paddingRight: 16,
  106. paddingBottom: 12,
  107. alignItems: 'center',
  108. flexDirection: 'row',
  109. backgroundColor: '#F5F5F5',
  110. justifyContent: 'space-between'
  111. },
  112. walletIcon: {
  113. width: 36,
  114. height: 36
  115. },
  116. creditText: {
  117. color: '#333',
  118. fontSize: 14,
  119. },
  120. rateText: {
  121. color: '#333',
  122. fontSize: 14,
  123. },
  124. balance: {
  125. flex: 1,
  126. color: '#333',
  127. fontSize: 16,
  128. textAlign: 'right',
  129. fontWeight: 'bold',
  130. paddingRight: 24,
  131. },
  132. balanceIcon: {
  133. width: 30,
  134. height: 30
  135. },
  136. balanceTitle: {
  137. flex: 1,
  138. color: '#000',
  139. fontSize: 16,
  140. paddingLeft: 12
  141. },
  142. balanceValue: {
  143. color: '#000',
  144. fontSize: 18,
  145. paddingRight: 6
  146. },
  147. infoStatus: {
  148. paddingTop: 4,
  149. paddingLeft: 10,
  150. paddingRight: 10,
  151. paddingBottom: 4,
  152. borderRadius: 4
  153. },
  154. selected: {
  155. color: colorAccent,
  156. backgroundColor: '#333'
  157. },
  158. topupView: {
  159. borderRadius: 4,
  160. backgroundColor: '#333'
  161. },
  162. topupText: {
  163. color: colorAccent,
  164. fontSize: 12,
  165. fontWeight: 'normal'
  166. },
  167. balanceView: {
  168. padding: 16,
  169. alignItems: 'center',
  170. flexDirection: 'row'
  171. }
  172. });