PaythodList.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * 支付方式列表
  3. * @邠心vbe on 2021/05/08
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Image, Pressable } from 'react-native';
  7. import { onChange } from 'react-native-reanimated';
  8. import apiWallet from '../../api/apiWallet';
  9. import ChargeItemSelect from '../../icons/ChargeItemSelect';
  10. export default class PaythodList extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. cIndex: 0,
  15. payTypeList: []
  16. };
  17. }
  18. componentDidMount() {
  19. this.getPayType();
  20. }
  21. getPayType() {
  22. apiWallet.getPayTypeList().then(res => {
  23. if (res.data) {
  24. this.setState({
  25. payTypeList: res.data
  26. });
  27. this.onChange(0);
  28. }
  29. }).catch(err => {
  30. });
  31. }
  32. changePayType(index) {
  33. this.setState({
  34. cIndex: index
  35. });
  36. this.onChange(index);
  37. }
  38. onChange(index) {
  39. if (this.props.onChange) {
  40. this.props.onChange(this.state.payTypeList[index]);
  41. }
  42. }
  43. getSecuryNumber(number, pk) {
  44. if (pk) {
  45. const last = number.substring(number.length - 8);
  46. var x = ''
  47. for (let i = 0; i < number.length - 8; i++) {
  48. x += 'X';
  49. }
  50. return x + last;
  51. } else {
  52. return number;
  53. }
  54. }
  55. render() {
  56. return (
  57. <View>
  58. { this.state.payTypeList.map((item, index) => {
  59. return (
  60. <Pressable
  61. key={index}
  62. style={[
  63. styles.paytypeView,
  64. index > 0 && styles.next,
  65. index == this.state.cIndex && styles.selected
  66. ]}
  67. onPress={() => {
  68. this.changePayType(index);
  69. }}>
  70. {/* item?.cardPk &&
  71. <Image
  72. style={styles.accountLogo}
  73. source={require('../../images/user/account-visa.png')}/>
  74. */}
  75. <Text style={styles.paytypeText}>{this.getSecuryNumber(item.payName, item.cardPk)}</Text>
  76. <View style={styles.selectIcon}>
  77. <ChargeItemSelect size={18} selected={index == this.state.cIndex} tint={colorPrimary}/>
  78. </View>
  79. </Pressable>
  80. );
  81. })
  82. }
  83. </View>
  84. );
  85. }
  86. }
  87. const styles = StyleSheet.create({
  88. paytypeView: {
  89. padding: 16,
  90. borderWidth: 1,
  91. borderColor: '#eee',
  92. borderRadius: 10,
  93. alignItems: 'center',
  94. flexDirection: 'row',
  95. backgroundColor: '#F5F5F5'
  96. },
  97. selected: {
  98. borderColor: colorPrimary
  99. },
  100. next: {
  101. marginTop: 16,
  102. },
  103. paytypeText: {
  104. flex: 1,
  105. color: '#333',
  106. fontSize: 14,
  107. },
  108. selectIcon: {
  109. width: 18,
  110. height: 18,
  111. },
  112. accountLogo: {
  113. width: 36,
  114. height: 18,
  115. marginRight: 32
  116. },
  117. });