Wallet.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 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={() => {
  64. startPage(PageList.topup);
  65. }}/>
  66. </View>
  67. <View style={styles.tabView}>
  68. <Button
  69. style={[
  70. styles.tab,
  71. styles.left,
  72. this.state.tabIndex == 0 && styles.active
  73. ]}
  74. viewStyle={{}}
  75. borderRadius={0}
  76. onClick={() => this.changeTab(0)}>
  77. <Text
  78. style={[
  79. styles.tabText,
  80. this.state.tabIndex == 0 && styles.active
  81. ]}>Overview</Text>
  82. </Button>
  83. <Button
  84. style={[
  85. styles.tab,
  86. styles.right,
  87. ]}
  88. viewStyle={{}}
  89. borderRadius={0}
  90. onClick={() => this.changeTab(1)}>
  91. <Text
  92. style={[
  93. styles.tabText,
  94. styles.rightText,
  95. this.state.tabIndex == 1 && styles.active
  96. ]}>History</Text>
  97. </Button>
  98. </View>
  99. <View>
  100. <Overview
  101. refresh={this.state.refreshing}
  102. refreshed={() => this.stopRefresh()}
  103. shown={this.state.tabIndex == 0}/>
  104. <History
  105. refresh={this.state.refreshing}
  106. refreshed={() => this.stopRefresh()}
  107. shown={this.state.tabIndex == 1}/>
  108. </View>
  109. </ScrollView>
  110. );
  111. }
  112. }
  113. const styles = StyleSheet.create({
  114. container: {
  115. flex: 1,
  116. backgroundColor: '#f5f5f5'
  117. },
  118. balanceView: {
  119. paddingTop: 12,
  120. paddingLeft: 16,
  121. paddingRight: 16,
  122. paddingBottom: 12,
  123. backgroundColor: '#fff'
  124. },
  125. tabView: {
  126. padding: 16,
  127. alignItems: 'center',
  128. flexDirection: 'row',
  129. justifyContent: 'center'
  130. },
  131. tabText: {
  132. color: '#333',
  133. fontSize: 14,
  134. paddingTop: 5,
  135. paddingLeft: 36,
  136. paddingRight: 36,
  137. paddingBottom: 5,
  138. },
  139. tab: {
  140. borderWidth: 1,
  141. borderColor: '#333',
  142. overflow: 'hidden',
  143. backgroundColor: '#fff'
  144. },
  145. left: {
  146. borderTopLeftRadius: 6,
  147. borderBottomLeftRadius: 6
  148. },
  149. right: {
  150. borderTopRightRadius: 6,
  151. borderBottomRightRadius: 6
  152. },
  153. rightText: {
  154. paddingLeft: 40,
  155. paddingRight: 40,
  156. },
  157. active: {
  158. color: colorAccent,
  159. backgroundColor: '#333'
  160. }
  161. })