ListCampaign.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * 活动信息列表
  3. * @邠心vbe on 2023/10/24
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, FlatList, StyleSheet, RefreshControl, PixelRatio } from 'react-native';
  7. import apiArticle from '../../api/apiArticle';
  8. import { MyRefreshProps } from '../../components/ThemesConfig';
  9. import { PageList } from '../Router';
  10. import AlertUtil from './AlertUtil';
  11. import ItemCampaign from './ItemCampaign';
  12. import VbeSkeleton from '../../components/VbeSkeleton';
  13. export default class ListCampaign extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. dataList: [],
  18. loading: true,
  19. refreshing: false,
  20. loadingList: ["", "", "", ""]
  21. };
  22. }
  23. componentDidMount() {
  24. this.props.navigation.addListener('focus', () => {
  25. this.getMessageList();
  26. });
  27. setTimeout(() => {
  28. this.getMessageList();
  29. }, 500);
  30. }
  31. toDetail(item={}) {
  32. if (item.articleId) {
  33. startPage(PageList.viewCampaign, {id: item.articleId});
  34. }
  35. }
  36. onRefresh() {
  37. this.setState({
  38. refreshing: true
  39. })
  40. this.getMessageList();
  41. }
  42. getMessageList() {
  43. apiArticle.getCampaignList().then(res => {
  44. if (res.data) {
  45. this.setState({
  46. dataList: res.data
  47. })
  48. }
  49. }).catch(err => {
  50. toastShort(err)
  51. }).finally(() => {
  52. this.setState({
  53. loading: false,
  54. refreshing: false
  55. })
  56. })
  57. }
  58. getMessageListPage() {
  59. const count = AlertUtil.getNewsCount();
  60. if (this.state.dataList.length > 0 && this.state.dataList.length < count) {
  61. const last = this.state.dataList[this.state.dataList.length-1]
  62. if (last.articleId) {
  63. apiArticle.getCampaignList(last.articleId).then(res => {
  64. if (res.data) {
  65. const list = [
  66. ...this.state.dataList,
  67. ]
  68. list.push(...res.data)
  69. this.setState({
  70. dataList: list
  71. })
  72. }
  73. }).catch(err => {
  74. toastShort(err)
  75. })
  76. }
  77. }
  78. }
  79. listItem = (props) => {
  80. return (
  81. <ItemCampaign
  82. {...props}
  83. onPress={() => this.toDetail(props.item)}
  84. />
  85. )
  86. }
  87. divideView = (props) => {
  88. return (<View style={{height: 1.5/PixelRatio.get()}}></View>)
  89. }
  90. render() {
  91. if (this.state.loading) {
  92. return (
  93. <View style={styles.listView}>
  94. { this.state.loadingList.map((item, index) =>
  95. <View style={styles.loadingView} key={index}>
  96. <VbeSkeleton
  97. style={styles.iconImage}
  98. layout={[
  99. {width: 85, height: 85, borderRadius: 6},
  100. {width: 35, height: 12, marginTop: 4, marginLeft: 25},
  101. ]}
  102. animationDirection={"horizontalRight"}
  103. />
  104. <VbeSkeleton
  105. style={ui.flex1}
  106. layout={[
  107. {width: '100%', height: 20},
  108. {width: '80%', height: 12, marginTop: 6},
  109. {width: '100%', height: 15, marginTop: 12},
  110. {width: '60%', height: 15, marginTop: 6}
  111. ]}
  112. animationDirection={"horizontalRight"}
  113. />
  114. </View>
  115. )}
  116. </View>
  117. )
  118. }
  119. return (
  120. <FlatList
  121. style={styles.listView}
  122. data={this.state.dataList}
  123. renderItem={this.listItem}
  124. ItemSeparatorComponent={this.divideView}
  125. keyExtractor={item => item.articleId}
  126. onEndReached={() => this.getMessageListPage()}
  127. onEndReachedThreshold={0.3}
  128. refreshControl={
  129. <RefreshControl
  130. {...MyRefreshProps()}
  131. refreshing={this.state.refreshing}
  132. onRefresh={() => this.onRefresh()}
  133. />
  134. }
  135. ListEmptyComponent={<Text style={styles.noData}>{$t('notification.empty')}</Text>}
  136. />
  137. );
  138. }
  139. }
  140. const styles = StyleSheet.create({
  141. listView: {
  142. flex: 1
  143. },
  144. noData: {
  145. color: textPlacehoder,
  146. fontSize: 14,
  147. padding: 20,
  148. textAlign: 'center'
  149. },
  150. loadingView: {
  151. padding: 16,
  152. flexDirection: 'row'
  153. },
  154. iconImage: {
  155. width: 85,
  156. height: 85,
  157. borderRadius: 6,
  158. marginRight: 16,
  159. marginBottom: 8
  160. }
  161. })