Wallet.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * 钱包页面
  3. * @邠心vbe on 2021/05/07
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, ScrollView, RefreshControl, Image, Pressable } from 'react-native';
  7. import Payment, { Balance, toTopupPage } from './Payment';
  8. import { PageList } from '../Router';
  9. import History from './History';
  10. import Overview from './Overview';
  11. import { MyRefreshProps } from '../../components/ThemesConfig';
  12. import Button, { ElevationObject } 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. tabWidth: 0,
  21. tabHeight: 0,
  22. };
  23. }
  24. componentDidMount() {
  25. this.props.navigation.addListener('focus', () => {
  26. this.onRefresh();
  27. getUserInfo(info => {
  28. this.setState({
  29. balance: info.credit
  30. })
  31. }, true)
  32. });
  33. }
  34. changeTab(index) {
  35. if (this.state.tabIndex !== index) {
  36. this.setState({
  37. tabIndex: index
  38. });
  39. }
  40. }
  41. onRefresh() {
  42. this.setState({
  43. refreshing: true
  44. });
  45. }
  46. stopRefresh() {
  47. this.setState({
  48. refreshing: false
  49. });
  50. }
  51. tabLayout({nativeEvent}) {
  52. //console.log('tab layout\n\n\n\n\n', nativeEvent.layout);
  53. if (nativeEvent.layout.width) {
  54. this.setState({
  55. tabWidth: nativeEvent.layout.width,
  56. tabHeight: 0.171955 * nativeEvent.layout.width
  57. })
  58. }
  59. }
  60. render() {
  61. return (
  62. <ScrollView
  63. style={styles.container}
  64. refreshControl={
  65. <RefreshControl
  66. {...MyRefreshProps}
  67. refreshing={this.state.refreshing}
  68. onRefresh={() => this.onRefresh()}
  69. />
  70. }>
  71. {/* <View style={styles.balanceView}>
  72. <Payment
  73. balance={this.state.balance}
  74. isPayPerUse={false}
  75. isWallet={true}
  76. payType={"Credit Wallet"}
  77. topup={() => toTopupPage()}/>
  78. </View> */}
  79. <Balance
  80. balance={this.state.balance}
  81. action="Top Up"
  82. page={PageList.topupNew}
  83. />
  84. <View style={styles.contentView}>
  85. <View style={styles.tabView} onLayout={props => this.tabLayout(props)}>
  86. { this.state.tabIndex == 0
  87. ? <Image
  88. style={[styles.tabBackgroundLeft, {width: this.state.tabWidth + 1, height: this.state.tabHeight}]}
  89. resizeMode="cover"
  90. source={require('../../images/wallet/tab-left.png')}
  91. />
  92. : <Image
  93. style={[styles.tabBackgroundRight, {width: this.state.tabWidth + 1, height: this.state.tabHeight}]}
  94. resizeMode="cover"
  95. source={require('../../images/wallet/tab-right.png')}
  96. />
  97. }
  98. <Pressable
  99. style={styles.tabItem}
  100. onPress={() => this.changeTab(0)}>
  101. <Text
  102. style={[
  103. styles.tabText,
  104. this.state.tabIndex == 0 && styles.active
  105. ]}>Overview</Text>
  106. </Pressable>
  107. <View style={{width: 16}}></View>
  108. <Pressable
  109. style={styles.tabItem}
  110. onPress={() => this.changeTab(1)}>
  111. <Text
  112. style={[
  113. styles.tabText,
  114. this.state.tabIndex == 1 && styles.active
  115. ]}>History</Text>
  116. </Pressable>
  117. </View>
  118. <Overview
  119. atAglance={false}
  120. refresh={this.state.refreshing}
  121. refreshed={() => this.stopRefresh()}
  122. shown={this.state.tabIndex == 0}/>
  123. <History
  124. refresh={this.state.refreshing}
  125. refreshed={() => this.stopRefresh()}
  126. shown={this.state.tabIndex == 1}/>
  127. </View>
  128. </ScrollView>
  129. );
  130. }
  131. }
  132. const styles = StyleSheet.create({
  133. container: {
  134. flex: 1,
  135. backgroundColor: '#f5f5f5'
  136. },
  137. balanceView: {
  138. paddingTop: 12,
  139. paddingLeft: 16,
  140. paddingRight: 16,
  141. paddingBottom: 12,
  142. backgroundColor: colorLight
  143. },
  144. tabView: {
  145. height: 60,
  146. padding: 16,
  147. overflow: 'hidden',
  148. alignItems: 'center',
  149. flexDirection: 'row',
  150. justifyContent: 'center'
  151. },
  152. tabItem: {
  153. flex: 1,
  154. marginTop: -14,
  155. alignItems: 'center',
  156. justifyContent: 'center'
  157. },
  158. tabText: {
  159. color: textSecondary,
  160. fontSize: 16,
  161. paddingTop: 5,
  162. paddingLeft: 36,
  163. paddingRight: 36,
  164. paddingBottom: 5,
  165. },
  166. active: {
  167. color: textPrimary,
  168. fontWeight: 'bold'
  169. },
  170. contentView: {
  171. ...$margin(8, 16, 16),
  172. overflow: 'hidden',
  173. borderRadius: 6,
  174. ...ElevationObject(5),
  175. backgroundColor: colorLight
  176. },
  177. tabBackgroundLeft: {
  178. top: -1,
  179. left: -1,
  180. right: 0,
  181. paddingRight: 1,
  182. width: $vw(90),
  183. height: $vw(14),
  184. position: 'absolute'
  185. },
  186. tabBackgroundRight: {
  187. top: -1,
  188. left: 0,
  189. right: -1,
  190. paddingRight: 1,
  191. width: $vw(90),
  192. height: $vw(14),
  193. position: 'absolute'
  194. }
  195. })