PointsHistory.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * 积分历史列表页面
  3. * @邠心vbe on 2024/05/07
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, RefreshControl, FlatList, StyleSheet } from 'react-native';
  7. import { MyRefreshProps } from '../../components/ThemesConfig';
  8. import TextView from '../../components/TextView';
  9. import Dialog from '../../components/Dialog';
  10. import apiVoucher from '../../api/apiVoucher';
  11. import app from '../../../app.json';
  12. export default class PointsHistory extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. dataList: [],
  17. hasMore: true,
  18. refreshing: false
  19. };
  20. }
  21. componentDidMount() {
  22. Dialog.showProgressDialog();
  23. this.getHistoryList();
  24. }
  25. onRefresh() {
  26. this.setState({
  27. refreshing: true
  28. })
  29. this.getHistoryList();
  30. }
  31. getNextPage() {
  32. if (this.state.dataList.length > 0 && this.state.hasMore) {
  33. console.log("[Points History]", "getNextPage");
  34. const last = this.state.dataList[this.state.dataList.length-1]
  35. this.getHistoryList(last.pointsHistoryId);
  36. }
  37. }
  38. getHistoryList(lastPk="") {
  39. apiVoucher.getPointsHistory(lastPk).then(res => {
  40. if (res.data) {
  41. if (lastPk) {
  42. if (res.data.length > 0) {
  43. const list = this.state.dataList;
  44. this.setState({
  45. dataList: list.concat(res.data)
  46. });
  47. } else {
  48. this.setState({
  49. hasMore: false
  50. })
  51. }
  52. } else {
  53. this.setState({
  54. dataList: res.data,
  55. hasMore: true
  56. });
  57. }
  58. } else {
  59. this.setState({
  60. dataList: []
  61. });
  62. }
  63. }).catch(err => {
  64. toastShort(err)
  65. }).finally(() => {
  66. this.setState({
  67. refreshing: false
  68. });
  69. Dialog.dismissLoading();
  70. });
  71. }
  72. listItem = ({item, index, separators}) => {
  73. return (
  74. <View style={styles.itemView}>
  75. <MaterialCommunityIcons
  76. style={styles.iconType}
  77. name={item.action == "Increase" ? "ev-station" : "ticket-percent-outline"}
  78. size={20}
  79. color={textPrimary}/>
  80. <View style={styles.itemContent}>
  81. <View style={ui.flex1}>
  82. <TextView style={styles.issueName}>{item.remarks}</TextView>
  83. <TextView style={styles.issueDesc}>{(item.siteName ?? item.voucherName) + ", " + (item.chargeBoxId ? item.chargeBoxId + ", " : "") + item.refId}</TextView>
  84. </View>
  85. { item.action == "Increase"
  86. ? <TextView style={styles.amountText}>+ {item.points}</TextView>
  87. : <TextView style={styles.amountDuct}>- {item.points}</TextView>
  88. }
  89. </View>
  90. </View>
  91. )
  92. }
  93. divideView = (props) => {
  94. return (<View style={styles.divide}></View>)
  95. }
  96. bottomView = () => {
  97. if (!this.state.hasMore) {
  98. return (<Text style={styles.noMore}>{$t('wallet.noMore')}</Text>)
  99. } else {
  100. return null
  101. }
  102. }
  103. render() {
  104. return (
  105. <FlatList
  106. style={styles.listView}
  107. data={this.state.dataList}
  108. renderItem={this.listItem}
  109. ItemSeparatorComponent={this.divideView}
  110. ListFooterComponent={this.bottomView}
  111. keyExtractor={item => item.pointsHistoryId}
  112. onEndReached={() => this.getNextPage()}
  113. onEndReachedThreshold={0.3}
  114. refreshControl={
  115. <RefreshControl
  116. {...MyRefreshProps()}
  117. refreshing={this.state.refreshing}
  118. onRefresh={() => this.onRefresh()}
  119. />
  120. }
  121. ListEmptyComponent={<Text style={styles.noData}>{$t('points.noData')}</Text>}
  122. />
  123. );
  124. }
  125. }
  126. const styles = StyleSheet.create({
  127. listView: {
  128. flex: 1
  129. },
  130. itemView: {
  131. paddingLeft: 16,
  132. paddingRight: 16,
  133. alignItems: 'center',
  134. flexDirection: 'row'
  135. },
  136. itemContent: {
  137. flex: 1,
  138. marginLeft: 8,
  139. ...$padding(16, 4),
  140. alignItems: 'center',
  141. flexDirection: 'row'
  142. },
  143. divide: {
  144. marginLeft: 52,
  145. marginRight: 16,
  146. borderTopWidth: 1,
  147. borderTopColor: '#eee',
  148. },
  149. iconType: {
  150. width: 28,
  151. height: 28,
  152. textAlign: 'center',
  153. lineHeight: 27,
  154. borderWidth: 1,
  155. borderRadius: 30,
  156. borderColor: textPrimary
  157. },
  158. issueName: {
  159. color: textPrimary,
  160. fontSize: 12,
  161. paddingBottom: 2
  162. },
  163. issueDesc: {
  164. color: '#999',
  165. fontSize: 8
  166. },
  167. amountDuct: {
  168. color: '#FF2E00',
  169. fontSize: 12,
  170. paddingLeft: 8
  171. },
  172. amountText: {
  173. color: colorAccent,
  174. fontSize: 12,
  175. paddingLeft: 8
  176. },
  177. noData: {
  178. color: textPlacehoder,
  179. fontSize: 8,
  180. padding: 20,
  181. textAlign: 'center'
  182. },
  183. noMore: {
  184. color: textPlacehoder,
  185. fontSize: 8,
  186. padding: 16,
  187. textAlign: 'center'
  188. }
  189. })