Wallet.js 6.9 KB

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