HistoryList.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. 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. } else {
  61. this.setState({
  62. dataList: []
  63. });
  64. }
  65. }).catch(err => {
  66. toastShort(err)
  67. }).finally(() => {
  68. this.setState({
  69. refreshing: false
  70. });
  71. Dialog.dismissLoading();
  72. });
  73. }
  74. toSummary(item) {
  75. if (item.refPk) {
  76. startPage(PageList.summary, { action: 'view', chargingPk: item.refPk });
  77. }
  78. }
  79. getTransTitle(item) {
  80. let title = item.createTime;
  81. if (item.remarks) {
  82. title += ': ' + item.remarks;
  83. } else if (item.amountSymbol == 'M') {
  84. title += ': ' + (item.siteName || "Charging");
  85. } else {
  86. title += ': ' + $t('wallet.topUp');
  87. }
  88. return title;
  89. }
  90. listItem = ({item, index, separators}) => {
  91. return (
  92. <Pressable
  93. android_ripple={ripple}
  94. style={styles.itemView}
  95. onPress={() => {
  96. this.toSummary(item)
  97. }}>
  98. <Image
  99. style={styles.iconType}
  100. resizeMode="contain"
  101. source={(item.amountSymbol == 'P' || item.remarks) ? IconPayment : IconCharge}/>
  102. <View style={styles.itemContent}>
  103. <View style={ui.flex1}>
  104. <TextView style={styles.issueName}>{this.getTransTitle(item)}</TextView>
  105. <TextView style={styles.issueDesc}>{$t('wallet.labelTransactionId') + item.creditRecordPk}</TextView>
  106. </View>
  107. { item.amountSymbol == 'M'
  108. ? <TextView style={styles.amountDuct}>- {item.amount}</TextView>
  109. : <TextView style={styles.amountText}>+ {item.amount}</TextView>
  110. }
  111. </View>
  112. </Pressable>
  113. )
  114. }
  115. divideView = (props) => {
  116. return (<View style={styles.divide}></View>)
  117. }
  118. bottomView = () => {
  119. if (!this.state.hasMore) {
  120. return (<Text style={styles.noMore}>{$t('wallet.noMore')}</Text>)
  121. } else {
  122. return null
  123. }
  124. }
  125. render() {
  126. return (
  127. <FlatList
  128. style={styles.listView}
  129. data={this.state.dataList}
  130. renderItem={this.listItem}
  131. ItemSeparatorComponent={this.divideView}
  132. ListFooterComponent={this.bottomView}
  133. keyExtractor={item => item.creditRecordPk}
  134. onEndReached={() => this.getNextPage()}
  135. onEndReachedThreshold={0.3}
  136. refreshControl={
  137. <RefreshControl
  138. {...MyRefreshProps()}
  139. refreshing={this.state.refreshing}
  140. onRefresh={() => this.onRefresh()}
  141. />
  142. }
  143. ListEmptyComponent={<Text style={styles.noData}>{$t('wallet.noHistoryData')}</Text>}
  144. />
  145. );
  146. }
  147. }
  148. const styles = StyleSheet.create({
  149. listView: {
  150. flex: 1
  151. },
  152. itemView: {
  153. paddingLeft: 16,
  154. paddingRight: 16,
  155. alignItems: 'center',
  156. flexDirection: 'row'
  157. },
  158. itemContent: {
  159. flex: 1,
  160. marginLeft: 16,
  161. ...$padding(16, 4),
  162. alignItems: 'center',
  163. flexDirection: 'row'
  164. },
  165. divide: {
  166. marginLeft: 60,
  167. marginRight: 16,
  168. borderTopWidth: 1,
  169. borderTopColor: '#eee',
  170. },
  171. iconType: {
  172. width: 28,
  173. height: 28
  174. },
  175. issueName: {
  176. color: textPrimary,
  177. fontSize: 12,
  178. paddingBottom: 2
  179. },
  180. issueDesc: {
  181. color: '#999',
  182. fontSize: 11
  183. },
  184. amountDuct: {
  185. color: '#FF2E00',
  186. fontSize: 14,
  187. paddingLeft: 8
  188. },
  189. amountText: {
  190. color: textPrimary,
  191. fontSize: 14,
  192. paddingLeft: 8
  193. },
  194. noData: {
  195. color: textPlacehoder,
  196. fontSize: 14,
  197. padding: 20,
  198. textAlign: 'center'
  199. },
  200. noMore: {
  201. color: textPlacehoder,
  202. fontSize: 14,
  203. padding: 16,
  204. textAlign: 'center'
  205. }
  206. })