message.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="msg-container">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="我的消息" @clickLeft="back"
  4. background-color="#157A2C" color="#fff" style="margin-bottom: 10rpx;z-index: 99999;">
  5. </uni-nav-bar>
  6. <view class="tool-box">
  7. <view class="tool-box-wrapper">
  8. <u-transition :show="checkShow" mode="fade-down">
  9. <view class="inner">
  10. <text @tap="checkShow = false">取消</text>
  11. <text @tap="markDelete">删除</text>
  12. </view>
  13. </u-transition>
  14. </view>
  15. <uni-list class="list-item">
  16. <template v-for="(item, index) in list" size="small">
  17. <uni-badge v-if='item.readStatus!=1' :text="100" :offset=[0,20] is-dot type="error"
  18. style="z-index: 99;" absolute='rightTop'>
  19. <uni-list-item @click="" style="border-top: 1px solid #f2f2f2;" direction='column'
  20. @click='handleRead(item)' clickable :avatarCircle='false' :border='false'>
  21. <template v-slot:header>
  22. <div style="display: flex;justify-content: space-between;">
  23. <span
  24. style="font-size: 15px;align-self: center;color: #afafaf">{{item.createTime}}</span>
  25. </div>
  26. </template>
  27. <template v-slot:body>
  28. <div>
  29. <span style="font-size: 15px;">{{item.templateContent}}</span>
  30. </div>
  31. </template>
  32. <template v-slot:footer>
  33. <div style="display: flex;justify-content: flex-end;">
  34. <span
  35. style="font-size: 15px;align-self: center;color: #afafaf">{{item.templateNickname}}</span>
  36. </div>
  37. </template>
  38. </uni-list-item>
  39. </uni-badge>
  40. <uni-list-item v-else style="border-top: 1px solid #f2f2f2;" direction='column' clickable
  41. :avatarCircle='false' :border='false'>
  42. <template v-slot:header>
  43. <div style="display: flex;justify-content: space-between;">
  44. <span
  45. style="font-size: 15px;align-self: center;color: #afafaf">{{item.createTime}}</span>
  46. </div>
  47. </template>
  48. <template v-slot:body>
  49. <div>
  50. <span style="font-size: 15px;">{{item.templateContent}}</span>
  51. </div>
  52. </template>
  53. <template v-slot:footer>
  54. <div style="display: flex;justify-content: flex-end;">
  55. <span
  56. style="font-size: 15px;align-self: center;color: #afafaf">{{item.templateNickname}}</span>
  57. </div>
  58. </template>
  59. </uni-list-item>
  60. </uni-badge>
  61. </template>
  62. </uni-list>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. notifyMessagePageAPI,
  69. updateNotifyMessageReadByIdAPI
  70. } from '@/api/wt/index.js'
  71. let [page, isEnd] = [1, false]
  72. export default {
  73. data() {
  74. return {
  75. checkList: [],
  76. list: [],
  77. checkShow: false,
  78. messageType: {
  79. 0: '系统消息',
  80. 1: '提醒消息',
  81. 2: '告警消息'
  82. },
  83. messageStatus: {
  84. 0: '已读',
  85. 1: '未读'
  86. }
  87. }
  88. },
  89. onReachBottom() {
  90. if (isEnd) return
  91. page++
  92. this.getList()
  93. },
  94. onShow() {
  95. page = 1
  96. this.getList()
  97. },
  98. methods: {
  99. //已读操作
  100. async handleRead(item) {
  101. await updateNotifyMessageReadByIdAPI([item.id]);
  102. this.getList()
  103. },
  104. toggleChecked() {
  105. this.checkShow = !this.checkShow
  106. this.checkList = []
  107. },
  108. handleCheckChange({
  109. detail
  110. }) {
  111. this.checkList = detail.value
  112. },
  113. async readAll() {
  114. await this.markRead(
  115. this.list.filter(i => i.messageStatus == 1).map(i => i.id),
  116. 0
  117. )
  118. page = 1
  119. this.getList()
  120. },
  121. //获取我的消息列表数据
  122. async getList() {
  123. let userInfo = wx.getStorageSync("userInfo");
  124. const params = {
  125. pageNum: page,
  126. size: 8,
  127. userId: userInfo.userId
  128. }
  129. let res = await notifyMessagePageAPI(params)
  130. if (params.page === 1) {
  131. this.list = []
  132. }
  133. this.list.push(...res.list)
  134. isEnd = this.list.length >= res.count
  135. },
  136. handleTo(e) {
  137. console.log(e)
  138. },
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .msg-container {
  144. padding: 0 20rpx;
  145. // background-color: $page-bg;
  146. min-height: 100vh;
  147. }
  148. </style>