Payment.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. { utils.isNotEmpty(page) &&
  106. <MaterialIcons
  107. size={20}
  108. color={textCancel}
  109. name='chevron-right'/>
  110. }
  111. </Pressable>
  112. );
  113. }
  114. const getBalance = (balance) => {
  115. console.log('getBalance', balance, userInfo);
  116. return balance ? balance.toFixed(2) : '0.0'
  117. }
  118. const styles = StyleSheet.create({
  119. paymentView: {
  120. borderRadius: 8,
  121. paddingTop: 12,
  122. paddingLeft: 16,
  123. paddingRight: 16,
  124. paddingBottom: 12,
  125. alignItems: 'center',
  126. flexDirection: 'row',
  127. ...ElevationObject(5),
  128. backgroundColor: colorLight,
  129. justifyContent: 'space-between'
  130. },
  131. walletIcon: {
  132. width: 36,
  133. height: 36
  134. },
  135. creditText: {
  136. color: textPrimary,
  137. fontSize: 14,
  138. },
  139. rateText: {
  140. color: textPrimary,
  141. fontSize: 14,
  142. },
  143. balance: {
  144. flex: 1,
  145. color: textPrimary,
  146. fontSize: 16,
  147. textAlign: 'right',
  148. fontWeight: 'bold',
  149. paddingRight: 24,
  150. },
  151. balanceIcon: {
  152. width: 30,
  153. height: 30
  154. },
  155. balanceTitle: {
  156. color: '#000',
  157. fontSize: 16,
  158. paddingLeft: 12,
  159. fontWeight: 'bold'
  160. },
  161. balanceValue: {
  162. color: '#000',
  163. fontSize: 18,
  164. paddingLeft: 6
  165. },
  166. infoStatus: {
  167. paddingTop: 4,
  168. paddingLeft: 10,
  169. paddingRight: 10,
  170. paddingBottom: 4,
  171. borderRadius: 4
  172. },
  173. selected: {
  174. color: colorAccent,
  175. backgroundColor: colorDark
  176. },
  177. topupView: {
  178. borderRadius: 4,
  179. backgroundColor: colorDark
  180. },
  181. topupText: {
  182. color: colorAccent,
  183. fontSize: 12,
  184. fontWeight: 'normal'
  185. },
  186. balanceView: {
  187. margin: 16,
  188. padding: 16,
  189. alignItems: 'center',
  190. flexDirection: 'row',
  191. borderRadius: 6,
  192. overflow: 'hidden',
  193. ...ElevationObject(5),
  194. backgroundColor: colorLight
  195. },
  196. actionText: {
  197. color: textCancel,
  198. fontSize: 12,
  199. paddingLeft: 8,
  200. paddingRight: 2
  201. }
  202. });