Payment.js 4.4 KB

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