TopupNew.js 9.6 KB

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