TopupV2.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. export default class TopupV2 extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. isAuto: false,
  17. topupList: [],
  18. selectIndex: 0,
  19. payType: {},
  20. balance: 0,
  21. };
  22. }
  23. componentDidMount() {
  24. this.props.navigation.addListener('focus', () => {
  25. getUserInfo(info => {
  26. this.setState({
  27. balance: info.credit
  28. })
  29. })
  30. });
  31. this.getTopupList();
  32. }
  33. getTopupList() {
  34. Dialog.showProgressDialog();
  35. apiWallet.getTopUpAmountList().then(res => {
  36. Dialog.dismissLoading();
  37. if (res.data.length > 0) {
  38. this.setState({
  39. topupList: res.data
  40. });
  41. }
  42. }).catch(err => {
  43. Dialog.dismissLoading();
  44. })
  45. }
  46. topup2() {
  47. const params = {
  48. payAmount: this.state.topupList[this.state.selectIndex]?.key,
  49. }
  50. apiWallet.doPaymentV2(params).then(res => {
  51. Dialog.dismissLoading();
  52. if (res.data.webPaymentUrl) {
  53. startPage(PageList.paymentWeb, { amount: params.payAmount, url: res.data.webPaymentUrl, type: 'Topup' });
  54. } else {
  55. toastShort('Error 0')
  56. }
  57. }).catch(err => {
  58. Dialog.dismissLoading();
  59. toastShort(err);
  60. });
  61. }
  62. topup() {
  63. const params = {
  64. payAmount: this.state.topupList[this.state.selectIndex]?.key,
  65. fomoPayType: this.state.payType.fomoPayType
  66. }
  67. console.log('params',params);
  68. if (params.payAmount) {
  69. if (params.fomoPayType == 'PAYNOW') {
  70. //PAYNOW支付
  71. Dialog.showProgressDialog();
  72. apiWallet.doPayment(params).then(res => {
  73. Dialog.dismissLoading();
  74. if (res.data.fomoId && res.data.qrCodeInBase64) {
  75. startPage(PageList.paynow, { amount: params.payAmount, base64: res.data.qrCodeInBase64 });
  76. } else {
  77. toastShort('Error 0')
  78. }
  79. }).catch(err => {
  80. Dialog.dismissLoading();
  81. toastShort(err);
  82. });
  83. } else {
  84. //信用卡支付
  85. startPage(PageList.formCard, { amount: params.payAmount, payType: params.fomoPayType });
  86. }
  87. } else {
  88. toastShort('Error 1')
  89. }
  90. }
  91. render() {
  92. return (
  93. <ScrollView style={styles.container}>
  94. <View style={styles.headerView}>
  95. <Balance balance={this.state.balance}/>
  96. </View>
  97. <View style={styles.contentView}>
  98. <View style={styles.topupView}>
  99. <WalletTitle>Top Up</WalletTitle>
  100. <Text style={styles.subTitle}>Choose Top Up Value: </Text>
  101. <View style={styles.topupItems}>
  102. { this.state.topupList.map((item, index) => {
  103. return (
  104. <Text
  105. key={index}
  106. style={[
  107. styles.topupItem,
  108. index > 0 && styles.right,
  109. index == this.state.selectIndex && styles.selected]}
  110. onPress={() => {
  111. this.setState({
  112. selectIndex: index
  113. })
  114. }}
  115. >{currency}{item.key}</Text>
  116. );
  117. })
  118. }
  119. </View>
  120. </View>
  121. {/* <View style={styles.topupView}>
  122. <WalletTitle>Payment</WalletTitle>
  123. <Text style={styles.subTitle}>Pay with: </Text>
  124. <PaythodList
  125. onChange={type => {
  126. this.setState({
  127. payType: type
  128. });
  129. }}/>
  130. </View> */}
  131. {/* <View style={ui.flexc}>
  132. <Text
  133. style={styles.autoView}
  134. onPress={() => {
  135. this.setState({
  136. isAuto: !this.state.isAuto
  137. });
  138. }}>Automatically top up S$20 when wallet balance is below S$5</Text>
  139. <Switch
  140. value={this.state.isAuto}
  141. trackColor={isIOS ? { false: "#B2B2B2", true: colorAccent } : null}
  142. onValueChange={v => {
  143. this.setState({
  144. isAuto: v
  145. });
  146. }}/>
  147. </View> */}
  148. </View>
  149. <View style={styles.buttonView}>
  150. <Button
  151. text='Top Up'
  152. elevation={1.5}
  153. onClick={() => {
  154. //startPage(PageList.paycard)
  155. this.topup2();
  156. }}/>
  157. </View>
  158. </ScrollView>
  159. );
  160. }
  161. }
  162. export const WalletTitle = ({children}) => {
  163. return (
  164. <View style={styles.topupTitle}>
  165. <Text style={styles.titleLeft}></Text>
  166. <Text style={styles.titleText}>{children}</Text>
  167. </View>
  168. );
  169. }
  170. const styles = StyleSheet.create({
  171. container: {
  172. flex: 1,
  173. backgroundColor: '#F5F5F5'
  174. },
  175. headerView: {
  176. paddingBottom: 76,
  177. //backgroundColor: colorAccent
  178. },
  179. contentView: {
  180. padding: 16,
  181. marginTop: -88
  182. },
  183. topupView: {
  184. padding: 16,
  185. borderRadius: 10,
  186. marginBottom: 16,
  187. backgroundColor: 'white'
  188. },
  189. topupTitle: {
  190. alignItems: 'center',
  191. flexDirection: 'row'
  192. },
  193. titleLeft: {
  194. width: 4,
  195. height: 15,
  196. borderRadius: 16,
  197. backgroundColor: colorPrimary
  198. },
  199. titleText: {
  200. color: '#333',
  201. fontSize: 16,
  202. paddingLeft: 10
  203. },
  204. subTitle: {
  205. color: '#333',
  206. fontSize: 14,
  207. marginTop: 16,
  208. marginBottom: 16
  209. },
  210. topupItems: {
  211. paddingBottom: 16,
  212. alignItems: 'center',
  213. flexDirection: 'row'
  214. },
  215. topupItem: {
  216. flex: 1,
  217. height: 60,
  218. lineHeight: 60,
  219. color: '#666',
  220. fontSize: 24,
  221. borderWidth: 1,
  222. borderRadius: 4,
  223. borderColor: '#999',
  224. textAlign: 'center'
  225. },
  226. right: {
  227. marginLeft: 20
  228. },
  229. selected: {
  230. color: '#fff',
  231. borderColor: '#333',
  232. backgroundColor: colorPrimary
  233. },
  234. autoView: {
  235. flex: 1,
  236. color: '#333',
  237. fontSize: 14,
  238. paddingRight: 32
  239. },
  240. buttonView: {
  241. padding: 16,
  242. marginTop: 0,
  243. marginBottom: 16
  244. }
  245. })