message.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. <u-toast ref="uToast"></u-toast>
  65. </view>
  66. </template>
  67. <script>
  68. import {
  69. notifyMessagePageAPI,
  70. updateNotifyMessageReadByIdAPI
  71. } from '@/api/wt/index.js'
  72. // let [page, isEnd] = [1, false]
  73. export default {
  74. data() {
  75. return {
  76. checkList: [],
  77. list: [],
  78. checkShow: false,
  79. messageType: {
  80. 0: '系统消息',
  81. 1: '提醒消息',
  82. 2: '告警消息'
  83. },
  84. messageStatus: {
  85. 0: '已读',
  86. 1: '未读'
  87. },
  88. page: 1,
  89. size: 10,
  90. isEnd: false,
  91. userInfo: ''
  92. }
  93. },
  94. onReachBottom() {
  95. console.log(this.isEnd, this.page);
  96. this.getList()
  97. },
  98. onShow() {
  99. this.doSearch();
  100. },
  101. onLoad() {
  102. this.userInfo = uni.getStorageSync("userInfo")
  103. console.log(this.userInfo);
  104. },
  105. methods: {
  106. doSearch() {
  107. this.isEnd = false;
  108. this.page = 1;
  109. this.list = []
  110. this.getList();
  111. },
  112. //已读操作
  113. async handleRead(item) {
  114. const res = await updateNotifyMessageReadByIdAPI([item.id]);
  115. if (res.code == 0) {
  116. this.list.find(data => item.id === data.id).readStatus = 1
  117. }
  118. // this.getList()
  119. },
  120. toggleChecked() {
  121. this.checkShow = !this.checkShow
  122. this.checkList = []
  123. },
  124. handleCheckChange({
  125. detail
  126. }) {
  127. this.checkList = detail.value
  128. },
  129. async readAll() {
  130. await this.markRead(
  131. this.list.filter(i => i.messageStatus == 1).map(i => i.id),
  132. 0
  133. )
  134. this.page = 1
  135. this.getList()
  136. },
  137. //获取我的消息列表数据
  138. async getList() {
  139. if (this.isEnd) {
  140. this.$refs.uToast.show({
  141. message: "暂无更多数据",
  142. duration: 1000
  143. })
  144. return
  145. }
  146. uni.showLoading({
  147. title: '加载中'
  148. })
  149. let params = {
  150. pageNum: this.page,
  151. size: this.size,
  152. userId: this.userInfo.userId
  153. }
  154. console.log(params);
  155. let res = await notifyMessagePageAPI(params)
  156. if (params.pageNum === 1) {
  157. this.list = res.list
  158. } else {
  159. this.list.push(...res.list)
  160. }
  161. this.page += 1
  162. this.isEnd = this.list.length >= res.count;
  163. },
  164. handleTo(e) {
  165. console.log(e)
  166. },
  167. }
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. .msg-container {
  172. padding: 0 20rpx;
  173. // background-color: $page-bg;
  174. min-height: 100vh;
  175. }
  176. </style>