announcementList.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="list">
  3. <view class="selectParam">
  4. <uni-search-bar :focus="false" v-model="title" @input="search" @cancel="cancel" clearButton="auto" cancelButton="none"></uni-search-bar>
  5. </view>
  6. <view v-for="(item, index) in list" :key="item.id" class="item">
  7. <img :src="loadImgSrcLocalhost(`${item.announcementImg}`)" class="avatar" />
  8. <view class="info" style="height: 5em;">
  9. <view class="name" @click="handleNavigate(item)">
  10. 标题:{{ item.announcementTitle }}
  11. <view class="unread-dot" v-if="item.readType == 0"></view>
  12. </view>
  13. </view>
  14. <em class="iconfont icon-xiangyoujiantou" @click="handleNavigate(item)"></em>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import { getList } from '@/api/index/index.js';
  20. export default {
  21. data() {
  22. return {
  23. queryParam: {
  24. pageNum: 1,
  25. pageSize: 10,
  26. announcementTitle: '',
  27. userId: getApp().globalData.userId
  28. },
  29. total: null,
  30. title:'',
  31. list: [],
  32. flag: true,
  33. };
  34. },
  35. onLoad() {
  36. this.queryParam.pageNum = 1
  37. this.queryParam.pageSize = 10
  38. this.flag=true
  39. this.getAnnoList();
  40. },
  41. onReachBottom() {
  42. let pageNum = this.queryParam.pageNum;
  43. let pageSize = this.queryParam.pageSize;
  44. let total = this.total;
  45. if (pageNum * pageSize >= total) {
  46. uni.showToast({
  47. title: '暂无更多数据'
  48. });
  49. return;
  50. } else {
  51. this.queryParam.pageNum += 1;
  52. this.flag=true
  53. this.getAnnoList();
  54. }
  55. },
  56. methods: {
  57. cancel(){
  58. this.queryParam.pageNum = 1
  59. this.queryParam.pageSize = 10
  60. this.queryParam.announcementTitle = ''
  61. },
  62. search(){
  63. this.queryParam.pageNum = 1
  64. this.queryParam.pageSize = 10
  65. this.queryParam.announcementTitle = this.title
  66. this.flag=false
  67. this.getAnnoList()
  68. },
  69. getAnnoList() {
  70. getList(this.queryParam).then((res) => {
  71. if(this.flag){
  72. this.list = [...this.list,...res.rows]
  73. // this.list = res.rows;
  74. this.total = res.total
  75. }else{
  76. this.list = res.rows
  77. this.total = res.total
  78. }
  79. });
  80. },
  81. handleNavigate(item) {
  82. item.readType = 1;
  83. uni.navigateTo({
  84. url: '/pages/index/announcementDetails?id=' + item.id
  85. });
  86. }
  87. }
  88. };
  89. </script>
  90. <style>
  91. .list {
  92. padding: 20rpx;
  93. }
  94. .item {
  95. display: flex;
  96. align-items: center;
  97. margin-bottom: 20rpx;
  98. }
  99. .avatar {
  100. width: 60rpx;
  101. height: 60rpx;
  102. border-radius: 50%;
  103. }
  104. .info {
  105. display: flex;
  106. align-items: center;
  107. }
  108. .name {
  109. font-size: 28rpx;
  110. font-weight: bold;
  111. margin-right: 10rpx; /* 添加间距 */
  112. position: relative;
  113. }
  114. .unread-dot {
  115. width: 10rpx;
  116. height: 10rpx;
  117. background-color: red;
  118. border-radius: 50%;
  119. position: absolute;
  120. right: -15rpx; /* 相对于父容器位置调整 */
  121. top: 50%;
  122. transform: translateY(-50%);
  123. }
  124. </style>