TopupNew.js 6.4 KB

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