CardList.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * 信用卡列表
  3. * @邠心vbe on 2021/05/11
  4. */
  5. import React from 'react';
  6. import { View, Text, Image, StyleSheet } from 'react-native';
  7. import apiWallet from '../../api/apiWallet';
  8. import { ElevationObject } from '../../components/Button';
  9. export class CardList extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. cardList: [],
  14. refreshId: 0,
  15. };
  16. }
  17. componentDidMount() {
  18. this.refreshCardList();
  19. }
  20. componentDidUpdate() {
  21. if (this.state.refreshId != this.props.refreshId) {
  22. this.setState({
  23. refreshId: this.props.refreshId,
  24. });
  25. this.refreshCardList();
  26. }
  27. }
  28. refreshCardList() {
  29. apiWallet.getCardList().then(res => {
  30. if (res.data) {
  31. this.setState({
  32. cardList: res.data
  33. });
  34. }
  35. }).catch(err => {
  36. });
  37. }
  38. getSecuryNumber(number) {
  39. const last = number.substring(number.length - 2);
  40. var x = ''
  41. for (let i = 0; i < number.length - 2; i++) {
  42. x += 'X';
  43. }
  44. return x + last;
  45. }
  46. render() {
  47. return (
  48. this.state.cardList.length > 0
  49. ? this.state.cardList.map((item, index) => {
  50. return (
  51. <View
  52. key={index}
  53. style={styles.accountView}>
  54. <Image
  55. style={styles.bgAccount}
  56. source={require('../../images/user/bg-item-card.png')}/>
  57. <View style={styles.accountRow}>
  58. <View style={ui.flex1}>
  59. <View style={styles.accountRow}>
  60. <Image
  61. style={styles.accountLogo}
  62. source={require('../../images/user/account-visa.png')}/>
  63. <View>
  64. <Text
  65. ellipsizeMode='tail'
  66. numberOfLines={1}
  67. style={styles.accountName}>{item.nameOnCard}</Text>
  68. <Text style={styles.accountType}>({item.validTill})</Text>
  69. </View>
  70. </View>
  71. <Text style={styles.accountNumber}>{this.getSecuryNumber(item.cardNumber) + ' - ' + item.cardCvv}</Text>
  72. </View>
  73. <FontAwesome
  74. size={24}
  75. color={colorAccent}
  76. name='angle-right'/>
  77. </View>
  78. </View>
  79. );
  80. })
  81. : <Text style={ui.noData}>No Cards</Text>
  82. );
  83. }
  84. }
  85. const styles = StyleSheet.create({
  86. accountView: {
  87. padding: 16,
  88. borderRadius: 10,
  89. overflow: 'hidden',
  90. marginBottom: 16,
  91. borderColor: '#f5f5f5',
  92. borderWidth: 1,
  93. backgroundColor: 'white',
  94. ...ElevationObject(1.5)
  95. },
  96. bgAccount: {
  97. left: 0,
  98. bottom: 0,
  99. width: 69.5,
  100. height: 21,
  101. position: 'absolute'
  102. },
  103. accountRow: {
  104. flex: 1,
  105. alignItems: 'center',
  106. flexDirection: 'row'
  107. },
  108. accountLogo: {
  109. width: 36,
  110. height: 18,
  111. marginRight: 12
  112. },
  113. accountName: {
  114. color: '#000',
  115. fontSize: 14
  116. },
  117. accountType: {
  118. color: '#333',
  119. fontSize: 12
  120. },
  121. accountNumber: {
  122. color: '#000',
  123. fontSize: 15,
  124. paddingTop: 16
  125. },
  126. })