myNotifyList.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view v-show="i === index">
  3. <view :style="[{'margin-top': CustomBar - 10 + 'px'}]">
  4. <view class="cu-bar search">
  5. <view class="search-form bg-white round">
  6. <text class="cuIcon-search"></text>
  7. <input type="text" placeholder="搜索" v-model="curWord" confirm-type="search" @input="inputWord"></input>
  8. </view>
  9. </view>
  10. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" :up="upOption" @up="upCallback">
  11. <view class="cu-list menu-avatar">
  12. <view class="cu-item" @click="toDetail(notify)" v-for="(notify, index) in list" :key="index">
  13. <view class="cu-avatar cuIcon-notification bg-blue round">
  14. </view>
  15. <view class="content">
  16. <view class="text-bold text-grey">
  17. <view class="ellipsis-description">
  18. 标题: {{notify.title}}
  19. </view>
  20. </view>
  21. <view class=" text-gray text-sm">
  22. <view class="ellipsis-description">
  23. 发布者:{{notify.createBy.name}},内容:{{notify.content}}
  24. </view>
  25. </view>
  26. </view>
  27. <view class="action">
  28. <view class="text-grey text-xs" >{{notify.createDate}}</view>
  29. <view :class="notify.readFlag === '1'?'bg-green':'bg-red'" class="cu-tag round sm">
  30. {{$dictUtils.getDictLabel('oa_notify_read', notify.readFlag ,'')}}</view>
  31. </view>
  32. </view>
  33. </view>
  34. </mescroll-body>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  40. import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
  41. import notifyService from "@/api/notify/notifyService";
  42. export default {
  43. mixins: [MescrollMixin,MescrollMoreItemMixin], // 使用mixin (在main.js注册全局组件)
  44. props:{
  45. i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
  46. index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
  47. type: Number,
  48. default(){
  49. return 0
  50. }
  51. },
  52. tabs: { // 为了请求数据,演示用,可根据自己的项目判断是否要传
  53. type: Array,
  54. default(){
  55. return []
  56. }
  57. }
  58. },
  59. data() {
  60. return {
  61. upOption: {
  62. noMoreSize: 3, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
  63. empty: {
  64. tip: '~ 搜索无结果 ~' // 提示
  65. }
  66. },
  67. CustomBar: this.CustomBar,
  68. list: [], // 数据列表
  69. modalName: null,
  70. curWord:"" //当前搜索关键词
  71. }
  72. },
  73. methods: {
  74. // 跳转到详细页面
  75. toDetail (item) {
  76. uni.navigateTo({
  77. url: '/pages/apps/notification/notificationDetail?id='+item.id
  78. })
  79. },
  80. // 输入监听
  81. inputWord(e){
  82. // this.curWord = e.detail.value // 已使用v-model,无需再次赋值
  83. // 节流,避免输入过快多次请求
  84. this.searchTimer && clearTimeout(this.searchTimer)
  85. this.searchTimer = setTimeout(()=>{
  86. this.doSearch(this.curWord)
  87. },300)
  88. },
  89. // 搜索
  90. doSearch(word){
  91. this.curWord = word
  92. this.list = []; // 先清空列表,显示加载进度
  93. this.mescroll.resetUpScroll();
  94. },
  95. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  96. upCallback(page) {
  97. //联网加载数据
  98. notifyService.list({
  99. isSelf: true,
  100. current: page.num,
  101. size: page.size,
  102. title: this.curWord
  103. }).then(({data})=>{
  104. let curPageData = data.records
  105. this.mescroll.endBySize(curPageData.length, data.total);
  106. //如果是第一页需手动制空列表
  107. if(page.num == 1)
  108. this.list = [];
  109. //追加新数据
  110. this.list=this.list.concat(curPageData);
  111. }).catch(e=>{
  112. //联网失败, 结束加载
  113. this.mescroll.endErr();
  114. })
  115. },
  116. del (id) {
  117. notifyService.delete(id).then(({data})=>{
  118. uni.showToast({
  119. title: data,
  120. icon:"success"
  121. })
  122. this.doSearch(this.curWord)
  123. })
  124. }
  125. }
  126. }
  127. </script>
  128. <style>
  129. .ellipsis-description {
  130. font-size: 12px;
  131. line-height: $line-height-base;
  132. display: -webkit-box;/*作为弹性伸缩盒子模型显示*/
  133. -webkit-line-clamp: 1; /*显示的行数;如果要设置2行加...则设置为2*/
  134. overflow: hidden; /*超出的文本隐藏*/
  135. text-overflow: ellipsis; /* 溢出用省略号*/
  136. -webkit-box-orient: vertical;/*伸缩盒子的子元素排列:从上到下*/
  137. }
  138. /*关键词搜索*/
  139. .item{
  140. padding: 20rpx;
  141. }
  142. .tip{
  143. font-size: 30rpx;
  144. vertical-align: middle;
  145. }
  146. .word-input{
  147. display: inline-block;
  148. width: 60%;
  149. height: 50rpx;
  150. line-height: 50rpx;
  151. font-size: 24rpx;
  152. margin-left: 30rpx;
  153. border: 2rpx solid #18B4FE;
  154. border-radius: 60rpx;
  155. text-align: center;
  156. background-color: #fff;
  157. vertical-align: middle;
  158. }
  159. .cu-bar .search-form{
  160. background-color: white;
  161. }
  162. </style>