TopupNew.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /**
  2. * 新版钱包充值页面
  3. * @邠心vbe on 2023/02/02
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, ScrollView, StyleSheet, Switch } from 'react-native';
  7. import apiWallet from '../../api/apiWallet';
  8. import BadgeSelectItem from '../../components/BadgeSelectItem';
  9. import Button, { ElevationObject } from '../../components/Button';
  10. import Dialog from '../../components/Dialog';
  11. import TextView from '../../components/TextView';
  12. import { PaymentDefault } from '../payment/PaymentConfig';
  13. import { PageList } from '../Router';
  14. import { Balance } from './Payment';
  15. import TopupPaythod from './TopupPaythod';
  16. export default class TopupNew extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. isAuto: false,
  21. topupList: [],
  22. selectIndex: 0,
  23. payType: {},
  24. balance: 0,
  25. };
  26. }
  27. componentDidMount() {
  28. this.props.navigation.addListener('focus', () => {
  29. getUserInfo(info => {
  30. this.setState({
  31. balance: info?.creditStr
  32. })
  33. }, true);
  34. });
  35. this.getTopupList();
  36. }
  37. getTopupList() {
  38. Dialog.showProgressDialog();
  39. // apiWallet.getTopUpAmountList()
  40. apiWallet.getTopUpAmountListV2().then(res => {
  41. Dialog.dismissLoading();
  42. if (res.data.length > 0) {
  43. this.setState({
  44. topupList: res.data
  45. });
  46. }
  47. }).catch(err => {
  48. toastShort(err)
  49. const data = apiWallet.getTempAmountListV2();
  50. this.setState({
  51. topupList: data
  52. });
  53. Dialog.dismissLoading();
  54. })
  55. }
  56. /**
  57. * 2C2P充值
  58. */
  59. topup2() {
  60. const topup = this.state.topupList[this.state.selectIndex]
  61. const params = {
  62. currency: topup?.currency,
  63. payAmount: topup?.amount
  64. }
  65. apiWallet.doPaymentV2(params).then(res => {
  66. Dialog.dismissLoading();
  67. if (res.data.webPaymentUrl) {
  68. startPage(PageList.paymentWeb, { amount: params.payAmount, url: res.data.webPaymentUrl, type: 'Topup' });
  69. } else {
  70. toastShort('Error 0')
  71. }
  72. }).catch(err => {
  73. Dialog.dismissLoading();
  74. toastShort(err);
  75. });
  76. }
  77. /**
  78. * FOMO充值
  79. */
  80. topup() {
  81. const topup = this.state.topupList[this.state.selectIndex]
  82. const params = {
  83. currency: topup?.currency,
  84. payAmount: topup?.amount,
  85. fomoPayType: this.state.payType.fomoPayType
  86. }
  87. //console.log('params',params);
  88. if (params.payAmount) {
  89. if (params.fomoPayType == 'PAYNOW' || params.fomoPayType == 'GRABPAY') {
  90. //PAYNOW支付
  91. Dialog.showProgressDialog();
  92. apiWallet.doPayment(params).then(res => {
  93. Dialog.dismissLoading();
  94. if (res.data.fomoId && res.data.qrCodeInBase64) {
  95. startPage(PageList.paynow, { amount: params.payAmount, base64: res.data.qrCodeInBase64 });
  96. } else if (res.data.url) {
  97. startPage(PageList.paymentWeb, { amount: params.payAmount, url: res.data.url, type: 'Topup' });
  98. } else {
  99. toastShort('Error 0')
  100. }
  101. }).catch(err => {
  102. Dialog.dismissLoading();
  103. toastShort(err);
  104. });
  105. } else {
  106. //信用卡支付
  107. startPage(PageList.formCard, { amount: params.payAmount, payType: params.fomoPayType });
  108. }
  109. } else {
  110. toastShort('Error 1')
  111. }
  112. }
  113. render() {
  114. return (
  115. <View style={styles.container}>
  116. <View style={styles.headerView}>
  117. <Balance balanceText={this.state.balance}/>
  118. </View>
  119. <View style={styles.contentView}>
  120. <View style={styles.topupView}>
  121. <WalletTitle>{$t('wallet.titleChooseCreditValue')}</WalletTitle>
  122. <View style={styles.topupItems}>
  123. { this.state.topupList.map((item, index) => {
  124. return (
  125. <BadgeSelectItem
  126. key={index}
  127. style={[styles.topupItem, index > 0 && styles.right]}
  128. checked={index == this.state.selectIndex}
  129. onPress={() => {
  130. this.setState({
  131. selectIndex: index
  132. })
  133. }}>
  134. <Text style={[styles.topupText, index == this.state.selectIndex && {color: colorAccent}]}>
  135. {item.amount}
  136. <Text style={{fontSize: 16}}> {item.currency}</Text>
  137. </Text>
  138. </BadgeSelectItem>
  139. );
  140. })
  141. }
  142. </View>
  143. </View>
  144. { !PaymentDefault.is2c2p &&
  145. <View style={styles.topupView}>
  146. <WalletTitle>{$t('wallet.titleChoosePaymentType')}</WalletTitle>
  147. <TopupPaythod
  148. onChange={type => {
  149. this.setState({
  150. payType: type
  151. });
  152. }}/>
  153. </View>
  154. }
  155. </View>
  156. <View style={ui.flex1}></View>
  157. <View style={styles.buttonView}>
  158. <Button
  159. text={$t('wallet.btnPurchase')}
  160. elevation={1.5}
  161. onClick={() => {
  162. PaymentDefault.is2c2p
  163. ? this.topup2()
  164. : this.topup()
  165. }}/>
  166. </View>
  167. </View>
  168. );
  169. }
  170. }
  171. export const WalletTitle = ({children}) => {
  172. return (
  173. <View style={styles.topupTitle}>
  174. {/* <Text style={styles.titleLeft}></Text> */}
  175. <TextView style={styles.titleText}>{children}</TextView>
  176. </View>
  177. );
  178. }
  179. const styles = StyleSheet.create({
  180. container: {
  181. flex: 1,
  182. backgroundColor: pageBackground
  183. },
  184. headerView: {
  185. paddingBottom: 76,
  186. //backgroundColor: colorAccent
  187. },
  188. contentView: {
  189. padding: 16,
  190. marginTop: -88
  191. },
  192. topupView: {
  193. marginBottom: 16
  194. },
  195. topupViewOld: {
  196. padding: 16,
  197. borderRadius: 10,
  198. marginBottom: 16,
  199. backgroundColor: colorLight
  200. },
  201. topupTitle: {
  202. marginBottom: 16,
  203. alignItems: 'center',
  204. flexDirection: 'row'
  205. },
  206. titleLeft: {
  207. width: 4,
  208. height: 15,
  209. borderRadius: 16,
  210. backgroundColor: colorPrimary
  211. },
  212. titleText: {
  213. color: textPrimary,
  214. fontSize: 16,
  215. paddingLeft: 0,
  216. fontWeight: 'bold',
  217. textShadowOffset: {
  218. width: 0,
  219. height: 1
  220. },
  221. textShadowRadius: 4,
  222. textShadowColor: "rgba(0, 0, 0, 0.25)",
  223. },
  224. subTitle: {
  225. color: textPrimary,
  226. fontSize: 14,
  227. marginTop: 16,
  228. marginBottom: 16
  229. },
  230. topupItems: {
  231. paddingBottom: 16,
  232. alignItems: 'center',
  233. flexDirection: 'row'
  234. },
  235. topupItem: {
  236. flex: 1,
  237. alignItems: 'center',
  238. justifyContent: 'center',
  239. backgroundColor: colorLight,
  240. ...ElevationObject(5)
  241. },
  242. topupText: {
  243. fontSize: 18,
  244. color: textPrimary,
  245. ...$padding(20, 0)
  246. },
  247. right: {
  248. marginLeft: 16
  249. },
  250. selected: {
  251. color: textLight,
  252. borderColor: colorDark,
  253. backgroundColor: colorPrimary
  254. },
  255. autoView: {
  256. flex: 1,
  257. color: textPrimary,
  258. fontSize: 14,
  259. paddingRight: 32
  260. },
  261. buttonView: {
  262. padding: 16,
  263. marginTop: 0,
  264. marginBottom: 16
  265. }
  266. })