TopupNew.js 8.2 KB

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