Wallet.js 3.8 KB

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