PaythodList.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * 支付方式列表
  3. * @邠心vbe on 2021/05/08
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Pressable } from 'react-native';
  7. import apiWallet from '../../api/apiWallet';
  8. import ChargeItemSelect from '../../icons/ChargeItemSelect';
  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. <View style={styles.selectIcon}>
  76. <ChargeItemSelect size={18} selected={index == this.state.cIndex} tint={colorPrimary}/>
  77. </View>
  78. </Pressable>
  79. );
  80. })
  81. }
  82. </View>
  83. );
  84. }
  85. }
  86. const styles = StyleSheet.create({
  87. paytypeView: {
  88. padding: 16,
  89. borderWidth: 1,
  90. borderColor: '#eee',
  91. borderRadius: 10,
  92. alignItems: 'center',
  93. flexDirection: 'row',
  94. backgroundColor: '#F5F5F5'
  95. },
  96. selected: {
  97. borderColor: colorPrimary
  98. },
  99. next: {
  100. marginTop: 16,
  101. },
  102. paytypeText: {
  103. flex: 1,
  104. color: textPrimary,
  105. fontSize: 14,
  106. },
  107. selectIcon: {
  108. width: 18,
  109. height: 18,
  110. },
  111. accountLogo: {
  112. width: 36,
  113. height: 18,
  114. marginRight: 32
  115. },
  116. });