HistoryList.js 5.1 KB

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