Wallet.js 6.4 KB

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