Payment.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * 支付组件
  3. * @邠心vbe on 2021/04/23
  4. */
  5. import React, { useEffect, useState } from 'react';
  6. import { View, Text, StyleSheet, Image, Pressable } from 'react-native';
  7. import Button, { ElevationObject } from '../../components/Button';
  8. import utils from '../../utils/utils';
  9. import { LowCreditDialog } from '../charge/InfoDialog';
  10. import { PageList } from '../Router';
  11. /**
  12. * @is2c2p 控制是否启用2C2P
  13. * @DEFAULT 控制默认的支付方式
  14. */
  15. export const PaymentDefault = {
  16. is2c2p: false,
  17. DEFAULT: {
  18. payType: "CreditWallet",
  19. payName: "Credit Wallet",
  20. isWallet: true,
  21. isPayPerUse: false
  22. },
  23. DEFAULT2: {
  24. payType: "PayPerUse",
  25. payName: "Pay Per Use (SGQR)",
  26. isWallet: false,
  27. isPayPerUse: true
  28. }
  29. }
  30. export const PAYTYPE = {
  31. CREDIT_WALLET: "CreditWallet", // 钱包余额支付
  32. PAY_PER_USE: "PayPerUse" // 按次支付
  33. }
  34. const Payment = ({
  35. topup, balance,
  36. payType = PaymentDefault.DEFAULT.payName,
  37. isWallet = PaymentDefault.DEFAULT.isWallet,
  38. isPayPerUse = PaymentDefault.DEFAULT.isPayPerUse,
  39. canShowLowCreditDialog = false,
  40. onMethodChange,
  41. refreshId = 0
  42. }) => {
  43. const [visible, showDialog] = useState(false)
  44. useEffect(() => {
  45. if (balance == undefined && canShowLowCreditDialog) {
  46. if (userInfo.credit <= 5 && refreshId > 0) {
  47. showDialog(true)
  48. }
  49. }
  50. }, [refreshId]);
  51. return (
  52. <View style={styles.paymentView}>
  53. <Image
  54. style={styles.walletIcon}
  55. source={require('../../images/charge/ic-payment.png')}
  56. />
  57. { isWallet || isPayPerUse
  58. ? <View style={{paddingLeft: 16}}>
  59. <Image
  60. style={{
  61. width: 50,
  62. height: 14
  63. }}
  64. resizeMode={'contain'}
  65. source={require('../../images/tool-logo.png')}/>
  66. <Text
  67. style={styles.rateText}
  68. numberOfLines={1}
  69. ellipsizeMode={'clip'}>{payType}</Text>
  70. </View>
  71. : <View style={{paddingLeft: 16}}>
  72. <Text style={styles.creditText}>Visa/Mastercard</Text>
  73. <Text style={styles.creditText}>Credit/Debit Card</Text>
  74. </View>
  75. }
  76. <Text
  77. style={styles.balance}
  78. numberOfLines={1}
  79. suppressHighlighting={true}>
  80. {isWallet ? currency + (balance ?? userInfo.credit) : ''}
  81. </Text>
  82. { topup
  83. ? <Button
  84. style={styles.topupView}
  85. text="+ Top Up"
  86. textStyle={styles.topupText}
  87. viewStyle={styles.infoStatus}
  88. onClick={topup}/>
  89. : <Button
  90. style={styles.topupView}
  91. text="Selected"
  92. textStyle={styles.topupText}
  93. viewStyle={styles.infoStatus}
  94. onClick={() => {if (onMethodChange) onMethodChange()}}/>
  95. }
  96. <LowCreditDialog
  97. visible={visible}
  98. onClose={topup => {
  99. showDialog(false)
  100. if (topup) {
  101. toTopupPage()
  102. } else {
  103. //goBack();
  104. }
  105. }
  106. }/>
  107. </View>
  108. );
  109. }
  110. export default Payment;
  111. export const Balance = ({balance, action="View History", page=PageList.wallet}) => {
  112. return (
  113. <Pressable
  114. style={styles.balanceView}
  115. onPress={() => startPage(page)}>
  116. <Image
  117. style={styles.balanceIcon}
  118. source={require('../../images/user/card-wallet.png')}/>
  119. <Text style={styles.balanceTitle}>Credit Wallet:</Text>
  120. <Text style={styles.balanceValue}>{currency}{getBalance(utils.isNotEmpty(balance) ? balance : userInfo.credit)}</Text>
  121. <Text style={styles.actionText}>{action}</Text>
  122. <FontAwesome
  123. size={20}
  124. color={textCancel}
  125. name='angle-right'/>
  126. </Pressable>
  127. );
  128. }
  129. const getBalance = (balance) => {
  130. console.log('getBalance', balance, userInfo);
  131. return balance ? balance.toFixed(2) : '0.0'
  132. }
  133. /*export const toTopupPage = () => {
  134. if (PaymentDefault.is2c2p) {
  135. startPage(PageList.topupV2);
  136. } else {
  137. startPage(PageList.topup);
  138. }
  139. }*/
  140. export const toTopupPage = () => {
  141. startPage(PageList.topupNew);
  142. }
  143. const styles = StyleSheet.create({
  144. paymentView: {
  145. borderRadius: 8,
  146. paddingTop: 12,
  147. paddingLeft: 16,
  148. paddingRight: 16,
  149. paddingBottom: 12,
  150. alignItems: 'center',
  151. flexDirection: 'row',
  152. ...ElevationObject(5),
  153. backgroundColor: colorLight,
  154. justifyContent: 'space-between'
  155. },
  156. walletIcon: {
  157. width: 36,
  158. height: 36
  159. },
  160. creditText: {
  161. color: textPrimary,
  162. fontSize: 14,
  163. },
  164. rateText: {
  165. color: textPrimary,
  166. fontSize: 14,
  167. },
  168. balance: {
  169. flex: 1,
  170. color: textPrimary,
  171. fontSize: 16,
  172. textAlign: 'right',
  173. fontWeight: 'bold',
  174. paddingRight: 24,
  175. },
  176. balanceIcon: {
  177. width: 30,
  178. height: 30
  179. },
  180. balanceTitle: {
  181. color: '#000',
  182. fontSize: 16,
  183. paddingLeft: 12,
  184. fontWeight: 'bold'
  185. },
  186. balanceValue: {
  187. flex: 1,
  188. color: '#000',
  189. fontSize: 18,
  190. paddingLeft: 6
  191. },
  192. infoStatus: {
  193. paddingTop: 4,
  194. paddingLeft: 10,
  195. paddingRight: 10,
  196. paddingBottom: 4,
  197. borderRadius: 4
  198. },
  199. selected: {
  200. color: colorAccent,
  201. backgroundColor: colorDark
  202. },
  203. topupView: {
  204. borderRadius: 4,
  205. backgroundColor: colorDark
  206. },
  207. topupText: {
  208. color: colorAccent,
  209. fontSize: 12,
  210. fontWeight: 'normal'
  211. },
  212. balanceView: {
  213. margin: 16,
  214. padding: 16,
  215. alignItems: 'center',
  216. flexDirection: 'row',
  217. borderRadius: 6,
  218. ...ElevationObject(5),
  219. backgroundColor: colorLight
  220. },
  221. actionText: {
  222. color: textCancel,
  223. fontSize: 12,
  224. paddingRight: 6
  225. }
  226. });