NewsList.vue
6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<template>
<div>
<van-sticky>
<NavBar :is-custom="true" @go-back="handleGoBack">
<template slot="title">新闻公告</template>
</NavBar>
<van-search
placeholder="请输入标题搜索..."
v-model="searchValue"
@search="onSearchChange"
@input="onSearch"
/>
</van-sticky>
<div class="roadWrapper flow_list">
<van-pull-refresh v-model="isDownLoading" @refresh="onRefresh()">
<van-list
v-if="itemList && itemList.length > 0"
v-model="loading"
:finished="finished"
finished-text="没有更多了"
:immediate-check="false"
:offset="20"
@load="onLoad"
class="new-matter-list"
>
<template v-if="itemList.length > 0">
<template v-for="item in itemList">
<div
v-if="compareDate(item.endTime)"
:key="item.id"
class="mobile-news-item"
:class="{ 'readed-wrap': item.reader }"
>
<div @click="handleReadNews(item, 'mobile')">
<div class="new-title-content">
<i
v-if="item.icon && item.icon.indexOf('icon-') > -1"
:style="{ color: item.iconColor }"
:class="[item.icon, { leftIcon: !item.iconColor }]"
></i>
<a
class="link-dot readed"
:class="{
'no-icon':
!item.icon ||
(item.icon && item.icon.indexOf('icon-') == -1),
}"
:title="item[showFields.title]"
>
{{ item[showFields.title] }}
</a>
</div>
<div class="news-date readed">
<span>{{ dateTimeFormat(item[showFields.date]) }}</span>
<span style="margin-left: 32px">{{ item.drafter }}</span>
</div>
</div>
</div>
</template>
</template>
</van-list>
</van-pull-refresh>
<van-empty
v-if="itemList.length == 0 && finished"
class="custom-image"
:image="noDataImage"
description="暂无内容"
/>
</div>
<MobileNewsRead
ref="mobileNewsRead"
:news-item="newsItem"
@refresh="refresh"
/>
</div>
</template>
<script>
import moment from 'moment'
import vanListCommon from '@/mixins/vanListCommon.js'
import { getColumnByAlias } from '@/api/portal.js'
import MobileNewsRead from './mobileNewsRead.vue'
export default {
name: 'NewsList',
mixins: [vanListCommon],
components: { MobileNewsRead },
props: {
showFields: {
type: Object,
default: () => {
return {
title: 'title',
date: 'createTime',
}
},
},
formatDateStr: {
type: String,
default: 'YYYY-MM-DD',
},
},
data() {
return {
searchValue: '',
ids: [],
newsItem: {},
noDataImage: require('@/assets/images/no_data.png'),
}
},
computed: {
dateTimeFormat() {
return (item) => {
return moment(item).format(this.formatDateStr) || '-'
}
},
alias() {
return this.$route.query.alias
},
},
mounted() {
this.load()
},
methods: {
compareDate(date) {
if (date) {
const endTime = new Date(Date.parse(date))
const currentDate = Date.parse(new Date())
return endTime > currentDate
} else {
return true
}
},
handleGoBack() {
this.$router.push({
path: '/home',
})
},
//上拉加载
//异步请求数据 ,我们的项目时封装好的方法,此处只是调用
// 获取新闻列表, 轮播图
onLoad() {
let params = {
pageBean: {
page: this.page,
pageSize: this.pageSize,
showTotal: true,
},
querys: [
{
property: 'classifyId',
value: this.ids,
group: 'advance',
relation: 'AND',
operation: 'IN',
},
],
}
if (this.searchValue) {
params.querys.push({
property: 'title',
value: this.searchValue,
operation: 'LIKE',
relation: 'OR',
group: 'quickSearch',
})
}
let _self = this
this.$requestConfig
.getListAndImg(params)
.then((response) => {
_self.loadData(response, _self)
})
.catch((error) => {})
.finally(() => {
_self.isDownLoading = false
_self.isUpLoading = false
})
},
load() {
if (!this.alias) {
return
}
getColumnByAlias(this.alias).then((response) => {
let params = JSON.parse(response.dataParam)
this.ids = params.announcementOrPictures || []
if (this.ids.length > 0) {
this.onRefresh()
}
})
},
handleReadNews(newsItem, type) {
this.newsItem = newsItem
this.$emit('newUnread')
this.$refs.mobileNewsRead.showDialog()
},
async refresh() {
this.onRefresh()
},
},
}
</script>
<style lang="scss" scoped>
.van-search {
padding: 16px 16px 8px;
.van-search__content {
border-radius: 8px;
}
}
//手机端样式
.mobile-news-item {
padding: 16px;
font-size: 16px;
color: #262626;
font-weight: bold;
border-bottom: 0.5px solid #e6e6e6;
.new-title-content {
margin-bottom: 12px;
}
.news-date {
font-size: 12px;
font-weight: 400;
color: #8c8c8c;
}
}
.mobile-news-content {
padding: 6px 12px;
}
.roadWrapper {
height: calc(#{$vh} - 104px);
overflow: scroll;
background-color: #fff;
}
.readed-wrap {
.readed {
color: #d5d5d5 !important;
&:before {
background-color: #d5d5d5;
}
}
}
</style>