message.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-blue" backUrl="/pages/index/index?id=apps" :isBack="false">
  4. <block slot="content"> 消息</block>
  5. </cu-custom>
  6. <u-search :show-action="false" v-model="searchForm.title" @change="inputWord" margin="20rpx 50rpx"></u-search>
  7. <view>
  8. <u-swipe-action>
  9. <view
  10. v-for="(notify, index) in dataList"
  11. :key="index">
  12. <u-swipe-action-item @click="del(notify.id)" :key="notify.id" :threshold="60" duration="500"
  13. :options="[ {
  14. text: '删除',
  15. style: {
  16. backgroundColor: '#f56c6c'
  17. }
  18. }]">
  19. <u-cell-group>
  20. <u-cell @click="toDetail(notify)">
  21. <u-avatar slot="icon" icon="bell-fill" fontSize="22" randomBgColor></u-avatar>
  22. <view slot="title" class="content">
  23. <view class="text-bold text-grey">
  24. <view class="ellipsis-description">
  25. 标题:{{notify.title}}
  26. </view>
  27. </view>
  28. <view class="text-gray text-sm">
  29. <view class="ellipsis-description">
  30. 发布者:{{notify.createBy.name}}, {{notify.createTime}}
  31. </view>
  32. </view>
  33. <view class="text-sm">
  34. <view class="ellipsis-description">
  35. 内容:{{notify.content}}
  36. </view>
  37. </view>
  38. </view>
  39. <view slot="right-icon">
  40. <u-tag :text="$dictUtils.getDictLabel('oa_notify_read', notify.readFlag ,'')" v-if="notify.readFlag === '1'" plain shape="circle"></u-tag>
  41. <u-tag :text="$dictUtils.getDictLabel('oa_notify_read', notify.readFlag ,'')" v-else plain type="error" shape="circle"></u-tag>
  42. </view>
  43. </u-cell>
  44. </u-cell-group>
  45. </u-swipe-action-item>
  46. </view>
  47. </u-swipe-action>
  48. </view>
  49. <u-loadmore :status="status" @loadmore="loadmore" :line="true" />
  50. <u-gap height="100" bgColor="#fff"></u-gap>
  51. <u-back-top :scrollTop="0" mode="square"></u-back-top>
  52. </view>
  53. </template>
  54. <script>
  55. import notifyService from "@/api/notify/notifyService";
  56. import { EventBus } from '@/store/eventBus.js';
  57. export default {
  58. data() {
  59. return {
  60. status: 'loadmore',
  61. searchForm: {
  62. title: ''
  63. },
  64. dataList: [],
  65. tablePage: {
  66. pages: 0,
  67. currentPage: 0,
  68. pageSize: 10,
  69. orders: [{ column: "a.create_time", asc: false }],
  70. },
  71. loading: false,
  72. }
  73. },
  74. created() {
  75. this.loadmore()
  76. },
  77. methods: {
  78. // 跳转到详细页面
  79. toDetail (notify) {
  80. if(notify.status === '1'){
  81. uni.navigateTo({
  82. url: '/pages/apps/notification/notificationDetail?id='+notify.id
  83. })
  84. }else{
  85. this.toEdit(notify)
  86. }
  87. },
  88. toEdit (notify) {
  89. uni.navigateTo({
  90. url: '/pages/apps/notification/oaNotifyForm?id='+notify.id
  91. })
  92. },
  93. toAdd (){
  94. uni.navigateTo({
  95. url: '/pages/apps/notification/oaNotifyForm'
  96. })
  97. },
  98. // 输入监听
  99. inputWord(e){
  100. this.searchTimer && clearTimeout(this.searchTimer)
  101. this.searchTimer = setTimeout(()=>{
  102. this.doSearch()
  103. },300)
  104. },
  105. // 搜索
  106. doSearch(){
  107. this.dataList = [];
  108. this.tablePage.currentPage = 0;
  109. this.tablePage.pageSize = 10;
  110. this.tablePage.pages = 0;
  111. this.loadmore()
  112. },
  113. onReachBottom() {
  114. this.loadmore()
  115. },
  116. async loadmore() {
  117. if(this.tablePage.currentPage!==0 && this.tablePage.pages <= this.tablePage.currentPage ) {
  118. this.status = 'nomore';
  119. return;
  120. }
  121. this.tablePage.currentPage = ++ this.tablePage.currentPage;
  122. //联网加载数据
  123. this.status = 'loading';
  124. notifyService.list({
  125. isSelf: true,
  126. current: this.tablePage.currentPage,
  127. size: this.tablePage.pageSize,
  128. orders: this.tablePage.orders,
  129. ...this.searchForm
  130. }).then((data)=>{
  131. //追加新数据
  132. this.dataList=this.dataList.concat(data.records);
  133. this.tablePage.pages = data.pages;
  134. if(this.tablePage.pages <= this.tablePage.currentPage){
  135. this.status = 'nomore'
  136. } else {
  137. this.status = 'loadmore'
  138. }
  139. })
  140. notifyService.getUnreadCountByIsSelf({
  141. isSelf: true,
  142. ...this.searchForm
  143. }).then((data)=>{
  144. EventBus.$emit('dataFromMessage', data); // 触发事件,传递参数
  145. })
  146. },
  147. del (id) {
  148. notifyService.delete(id).then((data)=>{
  149. this.doSearch()
  150. uni.showToast({
  151. title: data,
  152. icon:"success"
  153. })
  154. })
  155. },
  156. }
  157. }
  158. </script>