You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
7.1 KiB

<template>
<view>
2 years ago
<view class="search-wrap">
<image class="bg" src="@/static/image/info-bg.jpg"></image>
<view class="info">
<view class="text">行业资讯与活动</view>
<view class="text">速览</view>
<uni-search-bar class="search" radius="30" placeholder="请输入文章名称,标签" v-model="keyword" clearButton="auto" cancelButton="none" bgColor="#fff" />
</view>
</view>
<view class="type">
<view v-for="(item, i) in classifications.slice(0, 4)" :key="i" :class="['item', {active: active == item.id}]" @click="classificationClick(item, 1)">{{ item.classificationName }}</view>
<image class="unfold" src="@/static/image/unfold.png" mode="widthFix" @click="typeVisible = true"></image>
</view>
<template v-if="list.length">
<view class="list">
2 years ago
<view v-for="(item, i) in list" :key="i" class="item" @click="toDetail(item)">
<view class="title">{{ item.title }}</view>
<view class="texts">
<view class="left">
<view class="des" v-html="item.mainBody"></view>
<view class="metas">
<text class="date">{{ item.releaseTime }}</text>
<view v-if="item.labelName" class="labels">
<view v-for="(label, j) in item.labelName" :key="j" class="label">{{ label }}</view>
</view>
</view>
</view>
2 years ago
<image class="pic" :src="item.bannerImg"></image>
</view>
</view>
</view>
<uni-load-more :status="status" />
</template>
<empty v-else></empty>
2 years ago
<view class="type-popup" v-show="typeVisible">
<uni-icons class="close" type="closeempty" size="20" color="#757575" @click="closeType"></uni-icons>
<view class="title">所属分类</view>
<view class="types">
<view v-for="(item, i) in classifications" :key="i" :class="['item', {active: active == item.id}]" @click="classificationClick(item)">{{ item.classificationName }}</view>
</view>
</view>
</view>
</template>
<script>
2 years ago
import { partnerOperatingList, queryClassificationByType } from '@/apis/modules/article.js'
export default {
data() {
return {
2 years ago
classifications: [
{
2 years ago
id: '',
classificationName: '不限'
}
],
2 years ago
active: '',
typeVisible: false,
reachBottom: 0, // 是否是上拉加载。0->否,1->是,-1->加载完所有数据
status: 'more', // 上拉加载状态 more|loading|noMore
searchTimer: null,
2 years ago
articleNameSort: 'desc',
keyword: '',
2 years ago
list: [],
page: 1,
pageSize: 10,
}
},
watch: {
keyword () {
2 years ago
this.active = ''
clearTimeout(this.searchTimer)
this.searchTimer = setTimeout(() => {
this.initList()
}, 500)
}
},
// 下拉刷新
onPullDownRefresh() {
this.initList()
setTimeout(() => {
uni.stopPullDownRefresh()
}, 1500)
},
// 上拉加载
onReachBottom() {
if (this.reachBottom >= 0) {
this.reachBottom = 1
this.status = 'loading'
this.getList()
}
},
onShow() {
2 years ago
this.initRole()
},
methods: {
// 初始化权限
initRole() {
2 years ago
if (!uni.getStorageSync('auth').includes('资讯')) {
this.per = false
}
this.initList()
2 years ago
this.getClassification()
},
getList() {
const data = {
2 years ago
keyWord: this.keyword,
pageNum: this.page,
pageSize: this.pageSize,
2 years ago
querySource: 4,
typeId: 2,
articleNameSort: this.articleNameSort,
classificationId: this.active
}
uni.showLoading({
title: '加载中'
})
2 years ago
partnerOperatingList(data).then(({ data }) => {
uni.hideLoading()
// 未加载完所有数据,并且不是筛选,则拼接list,否则直接赋值
const list = data.records
2 years ago
list.forEach(e => {
if (e.labelName) e.labelName = e.labelName.split(',').slice(0, 2) // 只展示前两个标签
})
this.list = this.reachBottom > 0 ? [...this.list, ...list] : list
this.page++ // 每次获取了数据后page+1
const noMore = this.list.length === data.total // 是否加载完所有数据
this.status = noMore ? 'noMore' : 'more' // 加载完了则设置为noMore
this.reachBottom = noMore ? -1 : 0 // 加载完了则设置为-1
}).catch(e => {
uni.hideLoading()
})
},
initList() {
this.page = 1
this.reachBottom = 0
this.getList()
},
2 years ago
// 获取所属分类
getClassification() {
queryClassificationByType(2).then(({ data }) => {
this.classifications.push(...data)
}).catch(e => {})
},
// 所属分类点击回调
classificationClick(item, query) {
this.active = item.id
query && this.initList()
},
// 关闭所属分类弹框
closeType() {
this.typeVisible = false
this.initList()
},
// 展开
toggle(item) {
item.toggle = !item.toggle
},
// 排序
switchSort() {
2 years ago
this.articleNameSort = this.articleNameSort === 'desc' ? 'asc' : 'desc'
this.initList()
},
// 跳转详情
toDetail(item) {
2 years ago
this.$util.to(`/team/article/article?id=` + item.id)
},
}
}
</script>
<style scoped lang="scss">
2 years ago
.search-wrap {
position: relative;
height: 300rpx;
padding: 120rpx 10px 0;
.bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.info {
position: relative;
}
.text {
margin: 0 10px 10rpx;
font-size: 50rpx;
color: #fff;
}
}
.type {
position: relative;
display: flex;
padding: 30rpx;
background-color: #fff;
.item {
padding: 0 15rpx;
line-height: 1.6;
font-size: 28rpx;
color: #333;
white-space: nowrap;
&.active {
color: #007FFF;
font-weight: 600;
}
}
.unfold {
position: absolute;
right: 40rpx;
width: 40rpx;
}
}
.type-popup {
z-index: 10;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 10rpx;
background-color: #fff;
.close {
position: absolute;
top: 50rpx;
right: 50rpx;
}
.title {
margin: 150rpx 20rpx 30rpx;
font-size: 30rpx;
color: #333;
}
.types {
display: flex;
flex-wrap: wrap;
}
.item {
width: calc((100% - 80rpx) / 3);
margin: 10rpx;
font-size: 28rpx;
line-height: 3;
text-align: center;
color: #1f1f1f;
background-color: #dbebff;
border-radius: 2px;
&.active {
color: #fff;
background-color: #007EFF;
}
}
}
.list {
background-color: #fff;
.item {
2 years ago
margin-bottom: 10rpx;
padding: 20rpx 40rpx;
border-bottom: 1px solid #f1f1f1;
}
.texts {
display: flex;
justify-content: space-between;
align-items: center;
}
.pic {
2 years ago
width: 260rpx;
height: 180rpx;
border-radius: 8px;
}
2 years ago
.left {
width: calc(100% - 280rpx);
}
.title {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
2 years ago
.des {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
text-overflow: ellipsis;
overflow: hidden;
}
.metas {
display: flex;
justify-content: space-between;
align-items: center;
}
.date {
font-size: 24rpx;
color: #ccc;
white-space: nowrap;
}
.labels {
display: inline-flex;
2 years ago
flex-wrap: wrap;
align-items: center;
2 years ago
margin-top: 15rpx;
}
.label {
2 years ago
width: 90rpx;
padding: 2px 6px;
2 years ago
margin: 0 10rpx 15rpx 0;
font-size: 24rpx;
color: #fff;
2 years ago
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
background-color: #ccc;
border-radius: 4px;
}
}
</style>