<template> <view class="container"> <view class="news"> <view class="tab"> <view class="item" :class="{'active': activeStatus === 'all'}" @click="onLoadMessage('all')">全部<image src="../../static/images/icon_press02.png" class="icon"></image></view> <view class="item" :class="{'active': activeStatus === 'community'}" @click="onLoadMessage('community')">小区<image src="../../static/images/icon_press02.png" class="icon"></image></view> <view class="item" :class="{'active': activeStatus === 'committee'}" @click="onLoadMessage('committee')">业委会<image src="../../static/images/icon_press02.png" class="icon"></image></view> </view> <view class="list" v-if="activeList.length"> <view class="item" v-for="item in activeList" :key="item.id" @click="toDetails(item.id)"> <image mode="aspectFill" :src="item.noticeImage" class="icon"></image> <view class="con"> <view class="name">{{item.noticeTitle}}<view class="tag" v-if="item.urgentDegree === 'urgent'">非常紧急</view> </view> <view class="time">{{item.source | sourceFilter}} {{item.releaseTime || ''}}</view> </view> </view> </view> <no-data :show="activeList.length === 0" text="暂无数据"></no-data> </view> </view> </template> <script> import {queryNoticePageApi} from '@/config/api.js' import serverConfig from '@/config/server_config.js'; import noData from '@/components/no-data/no-data' export default { components: {noData}, data() { return { activeStatus: 'all', allPageNo: 1, committeePageNo: 1, communityPageNo: 1, allList: [], committeeList: [], communityList: [] } }, filters: { sourceFilter(value) { switch(value) { case 'community': return '小区' break case 'committee': return '业委会' break case 'councils': return '社区服务中心' break } } }, computed: { activeList() { if(this.activeStatus === 'all') { return [...this.allList] } if(this.activeStatus === 'community') { return [...this.communityList] } if(this.activeStatus === 'committee') { return [...this.committeeList] } } }, methods: { async getList() { let obj = {source: this.activeStatus} if(this.activeStatus === 'all') obj['pageNo'] = this.allPageNo if(this.activeStatus === 'community') obj['pageNo'] = this.communityPageNo if(this.activeStatus === 'committee') obj['pageNo'] = this.committeePageNo let {result} = await queryNoticePageApi({...obj}) let data = result.content.map(item=> { return { ...item, noticeImage: serverConfig.baseURL + '/sys/common/static/' + item.noticeImg } }) if(this.activeStatus === 'all') { if(this.allPageNo === 1) { this.allList = data } else { this.allList = this.allList.concat(data) } } if(this.activeStatus === 'community') { if(this.communityPageNo === 1) { this.communityList = data } else { this.communityList = this.communityList.concat(data) } } if(this.activeStatus === 'committee') { if(this.committeePageNo === 1) { this.committeeList = data } else { this.committeeList = this.committeeList.concat(data) } } }, toDetails(id) { uni.navigateTo({ url: `/pages/announcementDetails/index?id=${id}` }); }, onLoadMessage(status) { this.activeStatus = status if(this.activeStatus === 'all' && this.allList.length === 0) this.getList() if(this.activeStatus === 'community' && this.communityList.length === 0) this.getList() if(this.activeStatus === 'committee' && this.committeeList.length === 0) this.getList() } }, onShow() { this.allList = [] this.committeeList = [] this.communityList = [] this.getList() } } </script> <style> page { background-color: #F8F6F9; } </style> <style lang="scss" scoped> .page { padding: 30rpx 0 0; } .news { background-color: #ffffff; border-radius: 16rpx; .tab { padding: 30rpx 100rpx; display: flex; justify-content: space-between; .item { font-size: 30rpx; color: #9D9CA6; position: relative; transition: color .5s; .icon { width: 40rpx; height: 8rpx; position: absolute; bottom: -10px; left: 5px; opacity: 0; transition: opacity .5s; } } .active { color: #373737; .icon { opacity: 1; } } } .list { background-color: #F8F6F9; padding: 30rpx; .item { background-color: #ffffff; border-radius: 16rpx; display: flex; padding: 30rpx; margin-bottom: 30rpx; box-shadow: 0 0 25rpx 0 rgba(81,89,234,0.06); position: relative; &::after { content: " "; position: absolute; top: 30rpx; right: 30rpx; width: 14rpx; height: 14rpx; border-radius: 50%; z-index: 11; } &.noRead::after { background-color: #F6C864;; } .icon { flex: none; width: 186rpx; height: 140rpx; border-radius: 6rpx; } .con { margin-left: 30rpx; padding-right: 10rpx; .name { font-size: 30rpx; color: #373737; overflow : hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-all; /* 追加这一行代码 */ .tag { font-size: 22rpx; color: #F42E2E; border: 1px solid #F42E2E; padding: 4rpx 10rpx; border-radius: 30rpx; display: inline-block; margin-left: 20rpx; } } .time { font-size: 24rpx; color: #B6B6BA; height: 30rpx; line-height: 30rpx; margin-top: 30rpx; } } } } } </style>