TopupNew.js 6.9 KB

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