HistoryList.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /**
  2. * 交易历史页面
  3. * @邠心vbe on 2024/03/29
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, RefreshControl, FlatList, StyleSheet, Pressable, Image } from 'react-native';
  7. import { MyRefreshProps } from '../../components/ThemesConfig';
  8. import apiWallet from '../../api/apiWallet';
  9. import TextView from '../../components/TextView';
  10. import Dialog from '../../components/Dialog';
  11. import { PageList } from '../Router';
  12. import VbeSkeleton from '../../components/VbeSkeleton';
  13. const IconCharge = require('../../images/wallet/ic-type-charge.png');
  14. const IconPayment = require('../../images/wallet/ic-type-payment.png');
  15. export default class HistoryList extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. loading: true,
  20. dataList: [],
  21. hasMore: true,
  22. refreshing: false,
  23. loadingList: ["", "", "", ""]
  24. };
  25. }
  26. componentDidMount() {
  27. setTimeout(() => {
  28. this.getHistoryList();
  29. }, 500);
  30. }
  31. onRefresh() {
  32. this.setState({
  33. refreshing: true
  34. })
  35. this.getHistoryList();
  36. }
  37. getNextPage() {
  38. if (this.state.dataList.length > 0 && this.state.hasMore) {
  39. console.log("[Wallet History]", "getNextPage");
  40. const last = this.state.dataList[this.state.dataList.length-1]
  41. this.getHistoryList(last.creditRecordPk);
  42. }
  43. }
  44. getHistoryList(lastPk="") {
  45. apiWallet.getTransactionListV2({latestPk: lastPk}).then(res => {
  46. if (res.data) {
  47. if (lastPk) {
  48. if (res.data.length > 0) {
  49. const list = this.state.dataList;
  50. this.setState({
  51. dataList: list.concat(res.data)
  52. });
  53. } else {
  54. this.setState({
  55. hasMore: false
  56. })
  57. }
  58. } else {
  59. this.setState({
  60. dataList: res.data,
  61. hasMore: true
  62. });
  63. }
  64. } else {
  65. this.setState({
  66. dataList: []
  67. });
  68. }
  69. }).catch(err => {
  70. toastShort(err)
  71. }).finally(() => {
  72. this.setState({
  73. loading: false,
  74. refreshing: false
  75. });
  76. });
  77. }
  78. toSummary(item) {
  79. if (item.refPk) {
  80. startPage(PageList.summary, { action: 'view', chargingPk: item.refPk });
  81. }
  82. }
  83. getTransTitle(item) {
  84. let title = item.createTime;
  85. if (item.remarks) {
  86. title += ': ' + item.remarks;
  87. } else if (item.amountSymbol == 'M') {
  88. title += ': ' + (item.siteName || "Charging");
  89. } else {
  90. title += ': ' + $t('wallet.topUp');
  91. }
  92. return title;
  93. }
  94. listItem = ({item, index, separators}) => {
  95. return (
  96. <Pressable
  97. android_ripple={ripple}
  98. style={styles.itemView}
  99. onPress={() => {
  100. this.toSummary(item)
  101. }}>
  102. <Image
  103. style={styles.iconType}
  104. resizeMode="contain"
  105. source={(item.amountSymbol == 'P' || item.remarks) ? IconPayment : IconCharge}/>
  106. <View style={styles.itemContent}>
  107. <View style={ui.flex1}>
  108. <TextView style={styles.issueName}>{this.getTransTitle(item)}</TextView>
  109. <TextView style={styles.issueDesc}>{$t('wallet.labelTransactionId') + item.creditRecordPk}</TextView>
  110. </View>
  111. { item.amountSymbol == 'M'
  112. ? <TextView style={styles.amountDuct}>- {item.amount}</TextView>
  113. : <TextView style={styles.amountText}>+ {item.amount}</TextView>
  114. }
  115. </View>
  116. </Pressable>
  117. )
  118. }
  119. divideView = (props) => {
  120. return (<View style={styles.divide}></View>)
  121. }
  122. bottomView = () => {
  123. if (!this.state.hasMore) {
  124. return (<Text style={styles.noMore}>{$t('wallet.noMore')}</Text>)
  125. } else {
  126. return null
  127. }
  128. }
  129. render() {
  130. if (this.state.loading) {
  131. return (
  132. <View>
  133. { this.state.loadingList.map((item, index) =>
  134. <View style={styles.itemView} key={index}>
  135. <VbeSkeleton
  136. style={styles.iconType}
  137. layout={[
  138. {width: 32, height: 32, borderRadius: 30, marginRight: 16}
  139. ]}
  140. animationDirection={"horizontalRight"}
  141. />
  142. <View style={styles.itemContent}>
  143. <VbeSkeleton
  144. style={ui.flex1}
  145. layout={[
  146. {width: '100%', height: 15, marginTop: 4},
  147. {width: '60%', height: 15, marginTop: 4}
  148. ]}
  149. animationDirection={"horizontalRight"}
  150. />
  151. </View>
  152. </View>
  153. )}
  154. </View>
  155. )
  156. } else {
  157. return (
  158. <FlatList
  159. style={styles.listView}
  160. data={this.state.dataList}
  161. renderItem={this.listItem}
  162. ItemSeparatorComponent={this.divideView}
  163. ListFooterComponent={this.bottomView}
  164. keyExtractor={item => item.creditRecordPk}
  165. onEndReached={() => this.getNextPage()}
  166. onEndReachedThreshold={0.3}
  167. refreshControl={
  168. <RefreshControl
  169. {...MyRefreshProps()}
  170. refreshing={this.state.refreshing}
  171. onRefresh={() => this.onRefresh()}
  172. />
  173. }
  174. ListEmptyComponent={<Text style={styles.noData}>{$t('wallet.noHistoryData')}</Text>}
  175. />
  176. );
  177. }
  178. }
  179. }
  180. const styles = StyleSheet.create({
  181. listView: {
  182. flex: 1
  183. },
  184. itemView: {
  185. paddingLeft: 16,
  186. paddingRight: 16,
  187. alignItems: 'center',
  188. flexDirection: 'row'
  189. },
  190. itemContent: {
  191. flex: 1,
  192. marginLeft: 16,
  193. ...$padding(16, 4),
  194. alignItems: 'center',
  195. flexDirection: 'row'
  196. },
  197. divide: {
  198. marginLeft: 60,
  199. marginRight: 16,
  200. borderTopWidth: 1,
  201. borderTopColor: '#eee',
  202. },
  203. iconType: {
  204. width: 32,
  205. height: 32
  206. },
  207. issueName: {
  208. color: textPrimary,
  209. fontSize: 12,
  210. paddingBottom: 2
  211. },
  212. issueDesc: {
  213. color: '#999',
  214. fontSize: 11
  215. },
  216. amountDuct: {
  217. color: '#FF2E00',
  218. fontSize: 14,
  219. paddingLeft: 8
  220. },
  221. amountText: {
  222. color: textPrimary,
  223. fontSize: 14,
  224. paddingLeft: 8
  225. },
  226. noData: {
  227. color: textPlacehoder,
  228. fontSize: 14,
  229. padding: 20,
  230. textAlign: 'center'
  231. },
  232. noMore: {
  233. color: textPlacehoder,
  234. fontSize: 14,
  235. padding: 16,
  236. textAlign: 'center'
  237. }
  238. })