messageDetail.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar
  6. :command-list="commandList"
  7. :title="typeObj.label"
  8. @command="handleCommand" />
  9. <wk-scroll-view
  10. :status="listStatus"
  11. class="list-scroll"
  12. @refresh="getList(true)"
  13. @loadmore="getList()">
  14. <template v-if="type === 4">
  15. <notice-item
  16. v-for="(item, index) in listData"
  17. :key="item.messageId"
  18. :item-data="item"
  19. @delete="deleteOne(index)" />
  20. </template>
  21. <template v-else>
  22. <message-item
  23. v-for="(item, index) in listData"
  24. :key="item.messageId"
  25. :item-data="item"
  26. @read="handlerRead(index)"
  27. @delete="deleteOne(index)" />
  28. </template>
  29. </wk-scroll-view>
  30. </view>
  31. <uni-popup ref="popup" type="dialog">
  32. <uni-popup-dialog
  33. :content="dialogMsg"
  34. :duration="2000"
  35. type="warning"
  36. @confirm="deleteAllRead" />
  37. </uni-popup>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. QueryMessageList,
  43. ReadAllMessage,
  44. MessageClear,
  45. MessageDeleteById
  46. } from 'API/admin'
  47. import MessageItem from './message/messageItem.vue'
  48. import NoticeItem from './message/noticeItem.vue'
  49. import mainListMixins from '@/mixins/mainList.js'
  50. import config from './message.js'
  51. export default {
  52. name: 'MessageDetail',
  53. components: {
  54. MessageItem,
  55. NoticeItem
  56. },
  57. mixins: [mainListMixins],
  58. data() {
  59. return {
  60. type: null,
  61. listData: [],
  62. commandList: [
  63. {
  64. label: '全部已读',
  65. imgIcon: 'dealStatus',
  66. value: 'readAll'
  67. },
  68. {
  69. label: '删除已读',
  70. imgIcon: 'delete',
  71. value: 'delete'
  72. }
  73. ],
  74. dialogMsg: ''
  75. }
  76. },
  77. computed: {
  78. typeObj() {
  79. if (!this.type) return {}
  80. return config.typeList.find(o => o.value === this.type) || {}
  81. }
  82. },
  83. onLoad(options) {
  84. this.type = Number(options.type)
  85. this.getList()
  86. },
  87. methods: {
  88. getList(refresh = false) {
  89. this.listStatus = 'loading'
  90. if (refresh) {
  91. this.listParams.page = 0
  92. }
  93. this.listParams.page++
  94. QueryMessageList({
  95. ...this.listParams,
  96. label: this.type
  97. }).then(res => {
  98. if (this.listParams.page === 1) {
  99. this.listData = []
  100. }
  101. this.listData = this.listData.concat(res.list)
  102. if (res.hasOwnProperty('lastPage')) {
  103. this.listStatus = res.lastPage ? 'noMore' : 'more'
  104. } else {
  105. this.listStatus = res.list.length === 0 ? 'noMore' : 'more'
  106. }
  107. }).catch(() => {
  108. this.listStatus = 'more'
  109. })
  110. },
  111. handlerRead(index) {
  112. this.listData[index].isRead = 1
  113. this.$set(this.listData, index, this.listData[index])
  114. },
  115. handleCommand(command) {
  116. if (command.value === 'readAll') {
  117. // 全部标记已读
  118. ReadAllMessage({
  119. label: this.type
  120. }).then(res => {
  121. this.$toast('操作成功')
  122. this.getList(true)
  123. }).catch(() => {})
  124. } else if (command.value === 'delete') {
  125. this.dialogMsg = '确定删除全部已读消息?'
  126. this.$refs.popup.open()
  127. }
  128. },
  129. deleteAllRead(next) {
  130. // 删除已读
  131. next()
  132. MessageClear({
  133. label: this.type
  134. }).then(res => {
  135. this.$toast('操作成功')
  136. this.getList(true)
  137. }).catch(() => {})
  138. },
  139. deleteOne(index) {
  140. MessageDeleteById({
  141. messageId: this.listData[index].messageId
  142. }).then(res => {
  143. this.$toast('操作成功')
  144. this.listData.splice(index, 1)
  145. }).catch(() => {})
  146. }
  147. }
  148. }
  149. </script>
  150. <style scoped lang="scss">
  151. .main-container {
  152. .list-scroll {
  153. flex: 1;
  154. padding-top: 20rpx;
  155. overflow: hidden;
  156. }
  157. }
  158. </style>