Promotions.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * 活动信息列表
  3. * @邠心vbe on 2023/08/17
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, FlatList, StyleSheet, RefreshControl } from 'react-native';
  7. import apiNotification from '../../api/apiNotification';
  8. import Dialog from '../../components/Dialog';
  9. import { MyRefreshProps } from '../../components/ThemesConfig';
  10. import { PageList } from '../Router';
  11. import ItemView from './ItemView';
  12. export default class Promotions extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. dataList: [],
  17. refreshing: false
  18. };
  19. this.open = false;
  20. }
  21. componentDidMount() {
  22. //this.getMessageList();
  23. if (this.open) {
  24. this.props.navigation.addListener('focus', () => {
  25. this.getMessageList();
  26. });
  27. }
  28. }
  29. toDetail(item={}) {
  30. if (item.notificationId) {
  31. startPage(PageList.viewPromotion, {id: item.notificationId});
  32. }
  33. }
  34. toDelete(item={}) {
  35. if (item.notificationId) {
  36. Dialog.showDialog({
  37. title: $t("notification.deleteMessage"),
  38. message: $t("notification.confirmDelete"),
  39. ok: $t("nav.confirm"),
  40. callback: (btn) => {
  41. if (btn == Dialog.BUTTON_OK) {
  42. this.deleteMessage(item.notificationId);
  43. }
  44. }
  45. })
  46. }
  47. }
  48. deleteMessage(id) {
  49. this.setState({
  50. refreshing: true
  51. })
  52. apiNotification.deleteMessage(id).then(res => {
  53. toastShort($t("common.deleteSuccess"))
  54. this.getMessageList();
  55. }).catch(err => {
  56. toastShort(err)
  57. this.setState({
  58. refreshing: false
  59. })
  60. })
  61. }
  62. getMessageList() {
  63. this.setState({
  64. refreshing: true
  65. })
  66. apiNotification.getNotificationList().then(res => {
  67. if (res.data) {
  68. this.setState({
  69. dataList: res.data
  70. })
  71. }
  72. }).catch(err => {
  73. toastShort(err)
  74. }).finally(() => {
  75. this.setState({
  76. refreshing: false
  77. })
  78. })
  79. }
  80. listItem = (props) => {
  81. return (
  82. <ItemView
  83. {...props}
  84. onPress={() => this.toDetail(props.item)}
  85. onLongPress={() => this.toDelete(props.item)}
  86. />
  87. )
  88. }
  89. render() {
  90. if (this.open) {
  91. return (
  92. <FlatList
  93. style={styles.listView}
  94. data={this.state.dataList}
  95. renderItem={this.listItem}
  96. keyExtractor={item => item.notificationId}
  97. refreshControl={
  98. <RefreshControl
  99. {...MyRefreshProps()}
  100. refreshing={this.state.refreshing}
  101. onRefresh={() => this.getMessageList()}
  102. />
  103. }
  104. ListEmptyComponent={<Text style={styles.noData}>{$t('notification.empty')}</Text>}
  105. />
  106. );
  107. } else {
  108. return (
  109. <View>
  110. <Text style={ui.noData}> Coming soon </Text>
  111. </View>
  112. );
  113. }
  114. }
  115. }
  116. const styles = StyleSheet.create({
  117. listView: {
  118. flex: 1
  119. },
  120. noData: {
  121. color: textPlacehoder,
  122. fontSize: 14,
  123. padding: 20,
  124. textAlign: 'center'
  125. }
  126. })