Wallet.js 5.7 KB

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