TopupNew.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. {item.amount}
  146. <Text style={{fontSize: 16}}> {item.currency}</Text>
  147. </Text>
  148. </BadgeSelectItem>
  149. );
  150. })
  151. }
  152. </View>
  153. : <View style={styles.topupItems}>
  154. { this.state.topupList.map((item, index) => {
  155. return (
  156. <BadgeSelectItem
  157. key={index}
  158. style={[styles.topupItem, index > 0 && styles.right]}
  159. checked={index == this.state.selectIndex}
  160. onPress={() => {
  161. this.setState({
  162. selectIndex: index
  163. })
  164. }}>
  165. <Text style={[styles.topupText, index == this.state.selectIndex && {color: colorAccent}]}>
  166. {item.amount}
  167. <Text style={{fontSize: 16}}> {item.currency}</Text>
  168. </Text>
  169. </BadgeSelectItem>
  170. );
  171. })
  172. }
  173. </View>
  174. }
  175. </View>
  176. { !PaymentDefault.is2c2p &&
  177. <View style={styles.topupView}>
  178. <WalletTitle>{$t('wallet.titleChoosePaymentType')}</WalletTitle>
  179. <TopupPaythod
  180. onChange={type => {
  181. this.setState({
  182. payType: type
  183. });
  184. }}/>
  185. </View>
  186. }
  187. </View>
  188. <View style={ui.flex1}></View>
  189. { utils.isNotEmpty(app.storeUrl.refundUrl) &&
  190. <View style={styles.agreeView}>
  191. <CheckBox
  192. value={this.state.agree}
  193. onTintColor={colorAccent}
  194. onCheckColor={colorAccent}
  195. onValueChange={v => this.changeAgree(v)}
  196. />
  197. <View style={styles.agreeTextRow}>
  198. <TextView style={styles.agreeText} onPress={() => this.changeAgree(!this.state.agree)}>
  199. {$t('sign.iHaveReadAndAgree')}
  200. </TextView>
  201. <TextView style={styles.agreeLink} onPress={() => startPage(PageList.refundPolicy)}>Refund Policy</TextView>
  202. </View>
  203. </View>
  204. }
  205. <View style={styles.buttonView}>
  206. <Button
  207. text={$t('wallet.btnPurchase')}
  208. elevation={1.5}
  209. disabled={!this.state.agree}
  210. onClick={() => {
  211. PaymentDefault.is2c2p
  212. ? this.topup2()
  213. : this.topup()
  214. }}/>
  215. </View>
  216. </View>
  217. );
  218. }
  219. }
  220. export const WalletTitle = ({children}) => {
  221. return (
  222. <View style={styles.topupTitle}>
  223. {/* <Text style={styles.titleLeft}></Text> */}
  224. <TextView style={styles.titleText}>{children}</TextView>
  225. </View>
  226. );
  227. }
  228. const styles = StyleSheet.create({
  229. container: {
  230. flex: 1,
  231. backgroundColor: pageBackground
  232. },
  233. headerView: {
  234. paddingBottom: 76,
  235. //backgroundColor: colorAccent
  236. },
  237. contentView: {
  238. padding: 16,
  239. marginTop: -88
  240. },
  241. topupView: {
  242. marginBottom: 16
  243. },
  244. topupViewOld: {
  245. padding: 16,
  246. borderRadius: 10,
  247. marginBottom: 16,
  248. backgroundColor: colorLight
  249. },
  250. topupTitle: {
  251. marginBottom: 16,
  252. alignItems: 'center',
  253. flexDirection: 'row'
  254. },
  255. titleLeft: {
  256. width: 4,
  257. height: 15,
  258. borderRadius: 16,
  259. backgroundColor: colorPrimary
  260. },
  261. titleText: {
  262. color: textPrimary,
  263. fontSize: 16,
  264. paddingLeft: 0,
  265. fontWeight: 'bold',
  266. textShadowOffset: {
  267. width: 0,
  268. height: 1
  269. },
  270. textShadowRadius: 4,
  271. textShadowColor: "rgba(0, 0, 0, 0.25)",
  272. },
  273. subTitle: {
  274. color: textPrimary,
  275. fontSize: 14,
  276. marginTop: 16,
  277. marginBottom: 16
  278. },
  279. topupItems: {
  280. paddingBottom: 16,
  281. alignItems: 'center',
  282. flexDirection: 'row'
  283. },
  284. topupItems2: {
  285. paddingBottom: 16,
  286. alignItems: 'center'
  287. },
  288. topupItem: {
  289. flex: 1,
  290. alignItems: 'center',
  291. justifyContent: 'center',
  292. backgroundColor: colorLight,
  293. ...ElevationObject(5)
  294. },
  295. topupItem2: {
  296. width: "100%",
  297. marginBottom: 16,
  298. alignItems: 'center',
  299. justifyContent: 'center',
  300. backgroundColor: colorLight,
  301. ...ElevationObject(5)
  302. },
  303. topupText: {
  304. fontSize: 18,
  305. color: textPrimary,
  306. ...$padding(20, 0)
  307. },
  308. right: {
  309. marginLeft: 16
  310. },
  311. selected: {
  312. color: textLight,
  313. borderColor: colorDark,
  314. backgroundColor: colorPrimary
  315. },
  316. autoView: {
  317. flex: 1,
  318. color: textPrimary,
  319. fontSize: 14,
  320. paddingRight: 32
  321. },
  322. buttonView: {
  323. padding: 16,
  324. marginTop: 0,
  325. marginBottom: 16
  326. },
  327. agreeView: {
  328. margin: 16,
  329. flexDirection: 'row',
  330. alignItems: 'center',
  331. },
  332. agreeTextRow: {
  333. flex: 1,
  334. flexWrap: 'wrap',
  335. flexDirection: 'row'
  336. },
  337. agreeText: {
  338. color: textPrimary,
  339. fontSize: 14,
  340. paddingTop: 4,
  341. paddingBottom: 4
  342. },
  343. agreeLink: {
  344. ...ui.link,
  345. fontSize: 14,
  346. paddingTop: 4,
  347. paddingBottom: 4,
  348. textDecorationLine: 'underline'
  349. }
  350. })