Wallet.js 5.4 KB

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