TopupPaythod.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * 钱包充值的支付方式列表
  3. * @邠心vbe on 2023/02/02
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet } from 'react-native';
  7. import apiWallet from '../../api/apiWallet';
  8. import BadgeSelectItem from '../../components/BadgeSelectItem';
  9. import { ElevationObject } from '../../components/Button';
  10. import TextView from '../../components/TextView';
  11. import { PaymentIcon } from '../payment/PaymentConfig';
  12. export default class TopupPaythod extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. cIndex: 0,
  17. payTypeList: []
  18. };
  19. }
  20. componentDidMount() {
  21. this.getPayType();
  22. }
  23. getPayType() {
  24. apiWallet.getPayTypeList().then(res => {
  25. if (res.data) {
  26. this.setState({
  27. payTypeList: res.data
  28. });
  29. this.onChange(0);
  30. }
  31. }).catch(err => {
  32. });
  33. }
  34. changePayType(index) {
  35. this.setState({
  36. cIndex: index
  37. });
  38. this.onChange(index);
  39. }
  40. onChange(index) {
  41. if (this.props.onChange) {
  42. this.props.onChange(this.state.payTypeList[index]);
  43. }
  44. }
  45. getSecuryNumber(number, pk) {
  46. if (pk) {
  47. const last = number.substring(number.length - 8);
  48. var x = ''
  49. for (let i = 0; i < number.length - 8; i++) {
  50. x += 'X';
  51. }
  52. return x + last;
  53. } else {
  54. return " ";
  55. }
  56. }
  57. render() {
  58. return (
  59. <View style={styles.listView}>
  60. { this.state.payTypeList.map((item, index) => {
  61. return (
  62. <BadgeSelectItem
  63. key={index}
  64. style={[
  65. styles.paytypeView,
  66. index > 0 && styles.next
  67. ]}
  68. checked={index == this.state.cIndex}
  69. onPress={() => this.changePayType(index)}>
  70. <View style={$padding(12, 8, 8)}>
  71. <PaymentIcon method={item.fomoPayType} checked={index == this.state.cIndex}/>
  72. </View>
  73. <TextView style={[styles.paytypeText, (index == this.state.cIndex && {color: colorAccent})]}>{item.payName}</TextView>
  74. <TextView style={styles.cardText}>{this.getSecuryNumber(item.payName, item.cardPk)}</TextView>
  75. </BadgeSelectItem>
  76. );
  77. })
  78. }
  79. </View>
  80. );
  81. }
  82. }
  83. const styles = StyleSheet.create({
  84. listView: {
  85. flexWrap: 'wrap',
  86. flexDirection: 'row'
  87. },
  88. paytypeView: {
  89. flex: 1,
  90. alignItems: 'center',
  91. backgroundColor: colorLight,
  92. ...ElevationObject(5)
  93. },
  94. selected: {
  95. borderColor: colorPrimary
  96. },
  97. next: {
  98. marginLeft: 16,
  99. },
  100. paytypeText: {
  101. color: textPrimary,
  102. fontSize: 14,
  103. fontWeight: 'bold',
  104. paddingBottom: 14
  105. },
  106. cardText: {
  107. color: "#666",
  108. fontSize: 8,
  109. marginTop: -18,
  110. paddingBottom: 4
  111. },
  112. selectIcon: {
  113. width: 18,
  114. height: 18,
  115. },
  116. accountLogo: {
  117. width: 36,
  118. height: 18,
  119. marginRight: 32
  120. },
  121. });