Payment.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 TextView from '../../components/TextView';
  9. import utils from '../../utils/utils';
  10. import { LowCreditDialog } from '../charge/InfoDialog';
  11. import { PaymentDefault } from '../payment/PaymentConfig';
  12. import { PageList } from '../Router';
  13. const Payment = ({
  14. topup, balance,
  15. payType = PaymentDefault.DEFAULT.payName,
  16. isWallet = PaymentDefault.DEFAULT.isWallet,
  17. isPayPerUse = PaymentDefault.DEFAULT.isPayPerUse,
  18. canShowLowCreditDialog = false,
  19. onMethodChange,
  20. refreshId = 0
  21. }) => {
  22. const [visible, showDialog] = useState(false)
  23. useEffect(() => {
  24. if (balance == undefined && canShowLowCreditDialog) {
  25. if (userInfo.credit <= 5 && refreshId > 0) {
  26. showDialog(true)
  27. }
  28. }
  29. }, [refreshId]);
  30. return (
  31. <View style={styles.paymentView}>
  32. <Image
  33. style={styles.walletIcon}
  34. source={require('../../images/charge/ic-payment.png')}
  35. />
  36. { isWallet || isPayPerUse
  37. ? <View style={{paddingLeft: 16}}>
  38. <Image
  39. style={{
  40. width: 50,
  41. height: 14
  42. }}
  43. resizeMode={'contain'}
  44. source={require('../../images/tool-logo.png')}/>
  45. <Text
  46. style={styles.rateText}
  47. numberOfLines={1}
  48. ellipsizeMode={'clip'}>{payType}</Text>
  49. </View>
  50. : <View style={{paddingLeft: 16}}>
  51. <Text style={styles.creditText}>Visa/Mastercard</Text>
  52. <Text style={styles.creditText}>Credit/Debit Card</Text>
  53. </View>
  54. }
  55. <Text
  56. style={styles.balance}
  57. numberOfLines={1}
  58. suppressHighlighting={true}>
  59. {isWallet ? currency + (balance ?? userInfo.credit) : ''}
  60. </Text>
  61. { topup
  62. ? <Button
  63. style={styles.topupView}
  64. text="+ Top Up"
  65. textStyle={styles.topupText}
  66. viewStyle={styles.infoStatus}
  67. onClick={topup}/>
  68. : <Button
  69. style={styles.topupView}
  70. text="Selected"
  71. textStyle={styles.topupText}
  72. viewStyle={styles.infoStatus}
  73. onClick={() => {if (onMethodChange) onMethodChange()}}/>
  74. }
  75. <LowCreditDialog
  76. visible={visible}
  77. onClose={topup => {
  78. showDialog(false)
  79. if (topup) {
  80. toTopupPage()
  81. } else {
  82. //goBack();
  83. }
  84. }
  85. }/>
  86. </View>
  87. );
  88. }
  89. export default Payment;
  90. export const Balance = ({balance=0, balanceText, action, page=PageList.wallet}) => {
  91. return (
  92. <Pressable
  93. style={styles.balanceView}
  94. onPress={() => startPage(page)}>
  95. <Image
  96. style={styles.balanceIcon}
  97. source={require('../../images/user/card-wallet.png')}/>
  98. <TextView style={styles.balanceTitle}>{$t('wallet.creditWalletLabel')}</TextView>
  99. { balanceText
  100. ? <TextView style={styles.balanceValue} numberOfLines={1}>{balanceText}</TextView>
  101. : <TextView style={styles.balanceValue} numberOfLines={1}>{getBalance(utils.isNotEmpty(balance) ? balance : userInfo.credit)}</TextView>
  102. }
  103. <Text style={ui.flex1}></Text>
  104. <TextView style={styles.actionText} numberOfLines={1} ellipsizeMode="middle">{action ?? $t('wallet.viewHistory')}</TextView>
  105. <MaterialIcons
  106. size={20}
  107. color={textCancel}
  108. name='chevron-right'/>
  109. </Pressable>
  110. );
  111. }
  112. const getBalance = (balance) => {
  113. console.log('getBalance', balance, userInfo);
  114. return balance ? balance.toFixed(2) : '0.0'
  115. }
  116. const styles = StyleSheet.create({
  117. paymentView: {
  118. borderRadius: 8,
  119. paddingTop: 12,
  120. paddingLeft: 16,
  121. paddingRight: 16,
  122. paddingBottom: 12,
  123. alignItems: 'center',
  124. flexDirection: 'row',
  125. ...ElevationObject(5),
  126. backgroundColor: colorLight,
  127. justifyContent: 'space-between'
  128. },
  129. walletIcon: {
  130. width: 36,
  131. height: 36
  132. },
  133. creditText: {
  134. color: textPrimary,
  135. fontSize: 14,
  136. },
  137. rateText: {
  138. color: textPrimary,
  139. fontSize: 14,
  140. },
  141. balance: {
  142. flex: 1,
  143. color: textPrimary,
  144. fontSize: 16,
  145. textAlign: 'right',
  146. fontWeight: 'bold',
  147. paddingRight: 24,
  148. },
  149. balanceIcon: {
  150. width: 30,
  151. height: 30
  152. },
  153. balanceTitle: {
  154. color: '#000',
  155. fontSize: 16,
  156. paddingLeft: 12,
  157. fontWeight: 'bold'
  158. },
  159. balanceValue: {
  160. color: '#000',
  161. fontSize: 18,
  162. paddingLeft: 6
  163. },
  164. infoStatus: {
  165. paddingTop: 4,
  166. paddingLeft: 10,
  167. paddingRight: 10,
  168. paddingBottom: 4,
  169. borderRadius: 4
  170. },
  171. selected: {
  172. color: colorAccent,
  173. backgroundColor: colorDark
  174. },
  175. topupView: {
  176. borderRadius: 4,
  177. backgroundColor: colorDark
  178. },
  179. topupText: {
  180. color: colorAccent,
  181. fontSize: 12,
  182. fontWeight: 'normal'
  183. },
  184. balanceView: {
  185. margin: 16,
  186. padding: 16,
  187. alignItems: 'center',
  188. flexDirection: 'row',
  189. borderRadius: 6,
  190. overflow: 'hidden',
  191. ...ElevationObject(5),
  192. backgroundColor: colorLight
  193. },
  194. actionText: {
  195. color: textCancel,
  196. fontSize: 12,
  197. paddingLeft: 8,
  198. paddingRight: 2
  199. }
  200. });