Wallets.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**
  2. * 多钱包页面
  3. * @邠心vbe on 2025/01/17
  4. */
  5. import React, { Component } from 'react';
  6. import { FlatList, StyleSheet } from 'react-native';
  7. import { View, Text } from 'react-native';
  8. import PagerView from 'react-native-pager-view';
  9. import apiWallets from '../../api/apiWallets';
  10. import { ElevationObject } from '../../components/Button';
  11. import VbeSkeleton from '../../components/VbeSkeleton';
  12. import ViewHistory from './ViewHistory';
  13. import ViewWallet from './ViewWallet';
  14. export default class Wallets extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. loading: true,
  19. wallets: [],
  20. active: 0,
  21. history: {
  22. },
  23. historyList: [],
  24. loadingList: false
  25. };
  26. }
  27. componentDidMount() {
  28. setTimeout(() => {
  29. this.getWalletsInfo();
  30. }, 500);
  31. }
  32. getWalletsInfo() {
  33. apiWallets.getWalletsInfo().then(res => {
  34. if (res.data) {
  35. this.setState({
  36. wallets: res.data
  37. })
  38. }
  39. }).catch(err => {
  40. toastShort(err)
  41. }).finally(() => {
  42. this.setState({
  43. loading: false
  44. })
  45. })
  46. }
  47. getTransactionInfo(code) {
  48. if (this.state.history[code]) {
  49. this.setState({
  50. loadingList: false,
  51. historyList: this.state.history[code]
  52. })
  53. return;
  54. }
  55. apiWallets.getTransactionList({
  56. walletTypeCode: code
  57. }).then(res => {
  58. if (res.data) {
  59. this.state.history[code] = res.data;
  60. this.setState({
  61. historyList: res.data
  62. })
  63. } else {
  64. this.setState({
  65. historyList: []
  66. })
  67. }
  68. }).catch(err => {
  69. this.setState({
  70. historyList: []
  71. })
  72. }).finally(() => {
  73. this.setState({
  74. loadingList: false
  75. })
  76. })
  77. }
  78. changeCard(e) {
  79. //console.log("changeCard", e.nativeEvent.position);
  80. this.setState({
  81. active: e.nativeEvent.position
  82. }, () => {
  83. let wallet = this.state.wallets[this.state.active];
  84. if (wallet && wallet.walletTypeCode) {
  85. this.setState({
  86. loadingList: true
  87. });
  88. setTimeout(() => {
  89. this.getTransactionInfo(wallet.walletTypeCode);
  90. }, 300);
  91. }
  92. })
  93. }
  94. divideView = (props) => {
  95. return (<View style={styles.divideView}></View>)
  96. }
  97. render() {
  98. if (this.state.loading) {
  99. return (
  100. <VbeSkeleton
  101. style={[ui.flex1, $padding(16)]}
  102. layout={[
  103. {width: "100%", height: 200, borderRadius: 16},
  104. {width: "100%", height: $vh(100) - 320, borderRadius: 16, marginTop: 24},
  105. ]}
  106. animationDirection={"horizontalRight"}
  107. />
  108. )
  109. }
  110. return (
  111. <View style={styles.container}>
  112. <PagerView
  113. style={styles.pagerView}
  114. initialPage={0}
  115. onPageSelected={e => this.changeCard(e)}>
  116. { this.state.wallets.map((item, index) => (
  117. <ViewWallet key={index} wallet={item}/>
  118. ))}
  119. </PagerView>
  120. <View style={styles.indicatorView}>
  121. { this.state.wallets.map((item, index) => (
  122. <MaterialCommunityIcons
  123. key={index}
  124. style={$margin(2)}
  125. name={this.state.active == index ? "checkbox-blank-circle" : "checkbox-blank-circle-outline"}
  126. size={10}/>
  127. ))}
  128. </View>
  129. <View style={styles.listView}>
  130. { this.state.loadingList
  131. ? <VbeSkeleton
  132. style={[ui.flex1, $padding(16)]}
  133. layout={[
  134. {width: "100%", height: 14, borderRadius: 16},
  135. {width: "100%", height: 14, borderRadius: 16, marginTop: 12},
  136. {width: "60%", height: 14, borderRadius: 16, marginTop: 12},
  137. {width: "100%", height: 14, borderRadius: 16, marginTop: 24},
  138. {width: "100%", height: 14, borderRadius: 16, marginTop: 12},
  139. {width: "60%", height: 14, borderRadius: 16, marginTop: 12}
  140. ]}/>
  141. : <FlatList
  142. data={this.state.historyList}
  143. renderItem={ViewHistory}
  144. ItemSeparatorComponent={this.divideView}
  145. keyExtractor={item => item.refPk}
  146. ListEmptyComponent={<Text style={styles.noData}>No Data</Text>}/>
  147. }
  148. </View>
  149. </View>
  150. );
  151. }
  152. }
  153. const styles = StyleSheet.create({
  154. container: {
  155. flex: 1,
  156. backgroundColor: pageBackground
  157. },
  158. pagerView: {
  159. height: 200
  160. },
  161. indicatorView: {
  162. padding: 8,
  163. alignItems: 'center',
  164. flexDirection: 'row',
  165. justifyContent: 'center',
  166. },
  167. listView: {
  168. flex: 1,
  169. overflow: 'hidden',
  170. ...$margin(8, 16, 16),
  171. ...ElevationObject(2),
  172. borderRadius: 16,
  173. backgroundColor: colorLight
  174. },
  175. noData: {
  176. color: textPlacehoder,
  177. fontSize: 14,
  178. padding: 20,
  179. textAlign: 'center'
  180. },
  181. divideView: {
  182. height: 1,
  183. opacity: 0.5,
  184. marginLeft: 16,
  185. marginRight: 16,
  186. backgroundColor: '#e8e8e8'
  187. }
  188. })