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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<template>
<div class="app-container">
<div class="filter-container">
<el-input :placeholder="'搜素'" v-model="listQuery.filter.value" style="width: 160px;" class="filter-item" @keyup.enter.native="handleFilter"/>
<el-select v-model="listQuery.filter.key" :placeholder="'搜索字段'" clearable class="filter-item" style="width: 110px">
<el-option v-for="item in SearchTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-select v-model="listQuery.filter.is_online" :placeholder="'上线'" clearable class="filter-item" style="width: 100px">
<el-option v-for="item in BooleanTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-select v-model="listQuery.filter.complaints__isnull" :placeholder="'举报'" clearable class="filter-item" style="width: 100px">
<el-option v-for="item in ReBooleanTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-select v-model="listQuery.filter.is_puppet" :placeholder="'马甲'" clearable class="filter-item" style="width: 100px">
<el-option v-for="item in BooleanTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-select v-model="listQuery.filter.content_level" :placeholder="'帖子星级'" clearable class="filter-item" style="width: 100px">
<el-option v-for="item in ContentLevelTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">创建</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('offline')">下线</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('online')">上线</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="batchUpdate" >批量上线</el-button>
</div>
<el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange" @sort-change="sortChange">
<el-table-column type="selection" align="center"></el-table-column>
<el-table-column align="center" label="帖子ID " sortable="custom" min-width="85px" prop="id">
<template slot-scope="scope">
<router-link :to="'/topic/edit/'+scope.row.id" class="link-type">
<span>{{ scope.row.id }}</span>
</router-link>
</template>
</el-table-column>
<el-table-column align="center" label="用户">
<template slot-scope="scope">
<span>{{ scope.row.user.name }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="帖子详情" min-width="300px;">
<template slot-scope="scope">
<span>{{ scope.row.content }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="最新回复">
<template slot-scope="scope">
<span>{{ scope.row.newly_reply }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="小组">
<template slot-scope="scope">
<span>{{ scope.row.group.name }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="更新时间">
<template slot-scope="scope">
<span>{{ scope.row.update_time }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="举报时间">
<template slot-scope="scope">
<span>{{ scope.row.reported_time? scope.row.reported_time: '无' }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="帖子星级">
<template slot-scope="scope">
<span>{{ scope.row.content_level }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="是否在线">
<template slot-scope="scope">
<el-tag :type="scope.row.is_online | isOnlineFilter">{{ scope.row.is_online=== 1 ? '是' : '否' }}</el-tag>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :pageSizes="pageSize" :limit.sync="listQuery.limit" style="margin-left: 150px;" @pagination="getList" />
<el-dialog :visible.sync="dialogFormVisible">
<label>发帖时间: </label>
<el-date-picker
v-model="select_start_time "
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
placeholder="起始时间"
style="width: 230px"
/> ----
<el-date-picker
v-model="select_end_time "
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
placeholder="结束时间"
style="width: 230px"
/>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取消</el-button>
<el-button type="primary" @click="updateData()" :disabled="this.is_click">确认</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { fetchList, OffLineOrOnLine } from '@/api/topic'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import waves from '@/directive/waves'
export default {
name: 'TopicList',
components: { Pagination },
filters: {
isOnlineFilter(status) {
const statusMap = {
1: 'success',
0: 'info',
}
return statusMap[status]
},
genderFilter(status) {
const statusMap = {
'男': 'success',
'女': 'info',
'全部': 'danger'
}
return statusMap[status]
},
},
directives: { waves },
data() {
return {
list: null,
total: 0,
pageSize: [10, 30, 50, 100, 250],
listLoading: true,
multipleSelection: [],
del_list: [],
listQuery: {
page: 0,
limit: 10,
filter: {
value: '',
key: '',
is_online: '',
complaints__isnull: '',
user__is_puppet: '',
content_level: ''
},
sort: ['-id', ]
},
BooleanTypeOptions: [
{'key': 1, 'display_name': '是'},
{'key': 0, 'display_name': '否'}
],
ReBooleanTypeOptions: [
{'key': '0', 'display_name': '是'},
{'key': '1', 'display_name': '否'}
],
SearchTypeOptions:[
{'key': 'id', 'display_name': '帖子ID'},
{'key': 'content', 'display_name': '帖子内容'},
{'key': 'group__name', 'display_name': '小组'},
],
ContentLevelTypeOptions:[
{'key': 0, 'display_name': '未审核'},
{'key': 1, 'display_name': '星级一'},
{'key': 2, 'display_name': '星级二'},
{'key': 3, 'display_name': '星级三'},
{'key': 4, 'display_name': '星级四'},
{'key': 5, 'display_name': '星级五'},
],
dialogFormVisible: false,
is_click: false,
dialogStatus: '',
select_start_time: '',
select_end_time: ''
}
},
created() {
this.getList()
},
methods: {
getList() {
this.listLoading = true
this.listQuery.user_id = this.$route.query.user_id || ''
this.listQuery.group_id = this.$route.query.group_id || ''
fetchList(this.listQuery).then(response => {
this.list = response.data.data.data
this.total = response.data.data.total
this.listLoading = false
})
},
handleSelectionChange(val) {
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.limit = val
this.getList()
},
handleCurrentChange(val) {
this.listQuery.page = val
this.getList()
},
handleOfflineOrOnline(val){
const length = this.multipleSelection.length;
var ids = []
var updates = {}
this.del_list = this.del_list.concat(this.multipleSelection);
for (let i = 0; i < length; i++) {
if (val === 'offline'){
this.multipleSelection[i].is_online = 0
updates['is_online'] = 0
} else{
this.multipleSelection[i].is_online = 1
updates['is_online'] = 1
}
ids.push(this.multipleSelection[i].id)
}
OffLineOrOnLine({updates: JSON.stringify(updates), ids: JSON.stringify(ids)}).then(response => {
this.multipleSelection = [];
this.$message.success(response.data.data.message);
this.$router.go(0)
})
},
handleFilter() {
this.listQuery.page = 1
this.getList()
},
handleCreate() {
this.$router.push('/topic/create')
},
sortChange(data){
const {prop, order} = data
if (prop === 'id'){
this.sortByID(order)
}
},
sortByID(order){
if (order === 'ascending'){
this.listQuery.sort.shift()
this.listQuery.sort.push(...['id'])
}else{
this.listQuery.sort.shift()
this.listQuery.sort.push(...['-id'])
}
this.handleFilter()
},
batchUpdate(){
this.dialogFormVisible = true;
this.reset()
},
updateData(){
const length = this.multipleSelection.length;
var ids = []
var updates = {}
var extra_info = {}
this.del_list = this.del_list.concat(this.multipleSelection);
for (let i = 0; i < length; i++) {
this.multipleSelection[i].is_online = 1
updates['is_online'] = 1
ids.push(this.multipleSelection[i].id)
}
if (!length){
this.$message.error('请先勾选帖子ID,再进行后续操作.....')
return false
}
if (!this.select_start_time || !this.select_end_time){
this.$message.error('起始时间或者结束时间不能为空.....')
return false
}
if (this.select_start_time > this.select_end_time){
this.$message.error('起始时间不能小于结束时间.....')
return false
}
extra_info['start_time'] = this.select_start_time
extra_info['end_time'] = this.select_end_time
OffLineOrOnLine({updates: JSON.stringify(updates), ids: JSON.stringify(ids), extra: JSON.stringify(extra_info)}).then(response => {
this.multipleSelection = [];
this.$message.success(response.data.data.message);
this.$router.go(0)
this.dialogFormVisible = false;
})
},
reset(){
this.select_start_time = ''
this.select_end_time = ''
}
}
}
</script>
<style scoped>
.edit-input {
padding-right: 100px;
}
.cancel-btn {
position: absolute;
right: 15px;
top: 10px;
}
</style>