Wallet.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. * 钱包页面
  3. * @邠心vbe on 2021/05/07
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, ScrollView, RefreshControl } from 'react-native';
  7. import Payment, { toTopupPage } from './Payment';
  8. import { PageList } from '../Router';
  9. import History from './History';
  10. import Overview from './Overview';
  11. import { MyRefreshProps } from '../../components/MyRefreshControl';
  12. import Button from '../../components/Button';
  13. export default class Wallet extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. balance: 0,
  18. tabIndex: 0,
  19. refreshing: false,
  20. };
  21. }
  22. componentDidMount() {
  23. this.props.navigation.addListener('focus', () => {
  24. this.onRefresh();
  25. getUserInfo(info => {
  26. this.setState({
  27. balance: info.credit
  28. })
  29. }, true)
  30. });
  31. }
  32. changeTab(index) {
  33. if (this.state.tabIndex !== index) {
  34. this.setState({
  35. tabIndex: index
  36. });
  37. }
  38. }
  39. onRefresh() {
  40. this.setState({
  41. refreshing: true
  42. });
  43. }
  44. stopRefresh() {
  45. this.setState({
  46. refreshing: false
  47. });
  48. }
  49. render() {
  50. return (
  51. <ScrollView
  52. style={styles.container}
  53. refreshControl={
  54. <RefreshControl
  55. {...MyRefreshProps}
  56. refreshing={this.state.refreshing}
  57. onRefresh={() => this.onRefresh()}
  58. />
  59. }>
  60. <View style={styles.balanceView}>
  61. <Payment
  62. balance={this.state.balance}
  63. topup={() => toTopupPage()}/>
  64. </View>
  65. <View style={styles.tabView}>
  66. <Button
  67. style={[
  68. styles.tab,
  69. styles.left,
  70. this.state.tabIndex == 0 && styles.active
  71. ]}
  72. viewStyle={{}}
  73. borderRadius={0}
  74. onClick={() => this.changeTab(0)}>
  75. <Text
  76. style={[
  77. styles.tabText,
  78. this.state.tabIndex == 0 && styles.active
  79. ]}>Overview</Text>
  80. </Button>
  81. <Button
  82. style={[
  83. styles.tab,
  84. styles.right,
  85. ]}
  86. viewStyle={{}}
  87. borderRadius={0}
  88. onClick={() => this.changeTab(1)}>
  89. <Text
  90. style={[
  91. styles.tabText,
  92. styles.rightText,
  93. this.state.tabIndex == 1 && styles.active
  94. ]}>History</Text>
  95. </Button>
  96. </View>
  97. <View>
  98. <Overview
  99. refresh={this.state.refreshing}
  100. refreshed={() => this.stopRefresh()}
  101. shown={this.state.tabIndex == 0}/>
  102. <History
  103. refresh={this.state.refreshing}
  104. refreshed={() => this.stopRefresh()}
  105. shown={this.state.tabIndex == 1}/>
  106. </View>
  107. </ScrollView>
  108. );
  109. }
  110. }
  111. const styles = StyleSheet.create({
  112. container: {
  113. flex: 1,
  114. backgroundColor: '#f5f5f5'
  115. },
  116. balanceView: {
  117. paddingTop: 12,
  118. paddingLeft: 16,
  119. paddingRight: 16,
  120. paddingBottom: 12,
  121. backgroundColor: '#fff'
  122. },
  123. tabView: {
  124. padding: 16,
  125. alignItems: 'center',
  126. flexDirection: 'row',
  127. justifyContent: 'center'
  128. },
  129. tabText: {
  130. color: '#333',
  131. fontSize: 14,
  132. paddingTop: 5,
  133. paddingLeft: 36,
  134. paddingRight: 36,
  135. paddingBottom: 5,
  136. },
  137. tab: {
  138. borderWidth: 1,
  139. borderColor: '#333',
  140. overflow: 'hidden',
  141. backgroundColor: '#fff'
  142. },
  143. left: {
  144. borderTopLeftRadius: 6,
  145. borderBottomLeftRadius: 6
  146. },
  147. right: {
  148. borderTopRightRadius: 6,
  149. borderBottomRightRadius: 6
  150. },
  151. rightText: {
  152. paddingLeft: 40,
  153. paddingRight: 40,
  154. },
  155. active: {
  156. color: colorAccent,
  157. backgroundColor: '#333'
  158. }
  159. })