Alerts.js 2.7 KB

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