TopupV2.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * 2C2P钱包充值页面
  3. * @邠心vbe on 2022/12/27
  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 Button from '../../components/Button';
  9. import Dialog from '../../components/Dialog';
  10. import { PageList } from '../Router';
  11. import { Balance } from './Payment';
  12. import { TopupStyle, WalletTitle } from './Topup';
  13. export default class TopupV2 extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. isAuto: false,
  18. topupList: [],
  19. selectIndex: 0,
  20. payType: {},
  21. balance: 0,
  22. };
  23. }
  24. componentDidMount() {
  25. this.props.navigation.addListener('focus', () => {
  26. getUserInfo(info => {
  27. this.setState({
  28. balance: info.credit
  29. })
  30. })
  31. });
  32. this.getTopupList();
  33. }
  34. getTopupList() {
  35. Dialog.showProgressDialog();
  36. apiWallet.getTopUpAmountList().then(res => {
  37. Dialog.dismissLoading();
  38. if (res.data.length > 0) {
  39. this.setState({
  40. topupList: res.data
  41. });
  42. }
  43. }).catch(err => {
  44. Dialog.dismissLoading();
  45. })
  46. }
  47. topup2() {
  48. const params = {
  49. payAmount: this.state.topupList[this.state.selectIndex]?.key,
  50. }
  51. apiWallet.doPaymentV2(params).then(res => {
  52. Dialog.dismissLoading();
  53. if (res.data.webPaymentUrl) {
  54. startPage(PageList.paymentWeb, { amount: params.payAmount, url: res.data.webPaymentUrl, type: 'Topup' });
  55. } else {
  56. toastShort('Error 0')
  57. }
  58. }).catch(err => {
  59. Dialog.dismissLoading();
  60. toastShort(err);
  61. });
  62. }
  63. topup() {
  64. const params = {
  65. payAmount: this.state.topupList[this.state.selectIndex]?.key,
  66. fomoPayType: this.state.payType.fomoPayType
  67. }
  68. console.log('params',params);
  69. if (params.payAmount) {
  70. if (params.fomoPayType == 'PAYNOW') {
  71. //PAYNOW支付
  72. Dialog.showProgressDialog();
  73. apiWallet.doPayment(params).then(res => {
  74. Dialog.dismissLoading();
  75. if (res.data.fomoId && res.data.qrCodeInBase64) {
  76. startPage(PageList.paynow, { amount: params.payAmount, base64: res.data.qrCodeInBase64 });
  77. } else {
  78. toastShort('Error 0')
  79. }
  80. }).catch(err => {
  81. Dialog.dismissLoading();
  82. toastShort(err);
  83. });
  84. } else {
  85. //信用卡支付
  86. startPage(PageList.formCard, { amount: params.payAmount, payType: params.fomoPayType });
  87. }
  88. } else {
  89. toastShort('Error 1')
  90. }
  91. }
  92. render() {
  93. return (
  94. <ScrollView style={styles.container}>
  95. <View style={styles.headerView}>
  96. <Balance balance={this.state.balance}/>
  97. </View>
  98. <View style={styles.contentView}>
  99. <View style={styles.topupView}>
  100. <WalletTitle>Top Up</WalletTitle>
  101. <Text style={styles.subTitle}>Choose Top Up Value: </Text>
  102. <View style={styles.topupItems}>
  103. { this.state.topupList.map((item, index) => {
  104. return (
  105. <Text
  106. key={index}
  107. style={[
  108. styles.topupItem,
  109. index > 0 && styles.right,
  110. index == this.state.selectIndex && styles.selected]}
  111. onPress={() => {
  112. this.setState({
  113. selectIndex: index
  114. })
  115. }}
  116. >{currency}{item.key}</Text>
  117. );
  118. })
  119. }
  120. </View>
  121. </View>
  122. {/* <View style={styles.topupView}>
  123. <WalletTitle>Payment</WalletTitle>
  124. <Text style={styles.subTitle}>Pay with: </Text>
  125. <PaythodList
  126. onChange={type => {
  127. this.setState({
  128. payType: type
  129. });
  130. }}/>
  131. </View> */}
  132. {/* <View style={ui.flexc}>
  133. <Text
  134. style={styles.autoView}
  135. onPress={() => {
  136. this.setState({
  137. isAuto: !this.state.isAuto
  138. });
  139. }}>Automatically top up S$20 when wallet balance is below S$5</Text>
  140. <Switch
  141. value={this.state.isAuto}
  142. trackColor={isIOS ? { false: "#B2B2B2", true: colorAccent } : null}
  143. onValueChange={v => {
  144. this.setState({
  145. isAuto: v
  146. });
  147. }}/>
  148. </View> */}
  149. </View>
  150. <View style={styles.buttonView}>
  151. <Button
  152. text='TOP UP'
  153. elevation={1.5}
  154. onClick={() => {
  155. //startPage(PageList.paycard)
  156. this.topup2();
  157. }}/>
  158. </View>
  159. </ScrollView>
  160. );
  161. }
  162. }
  163. const styles = TopupStyle;