PaythodList.js 2.8 KB

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