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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
<template>
<div class="createPost-container">
<el-form ref="postForm" :model="postForm" :rules="rules" class="form-container">
<sticky :class-name="'sub-navbar'">
<el-button v-loading="loading" style="margin-left: 10px;" type="success" @click="submitForm">保存
</el-button>
</sticky>
<div class="createPost-main-container">
<el-row :gutter="20">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>pick相关</span>
</div>
<el-row>
<el-col :span="24">
<el-form-item style="margin-bottom: 40px;" prop="name">
<MDinput v-model="postForm.name" :maxlength="100" name="name" required>
pick名称
</MDinput>
</el-form-item>
<div class="postInfo-container">
<el-row>
<el-col :span="8">
<el-form-item label-width="45px" label="性别:" class="postInfo-container-item" prop="gender">
<el-select v-model="postForm.gender" :placeholder="'性别:'" clearable
class="postInfo-container-item"
style="width: 120px">
<el-option v-for="item in GenderTypeOptions" :key="item.key" :label="item.display_name"
:value="item.key"/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label-width="60px" label="属性:" class="postInfo-container-item" prop="pick_type">
<el-select v-model="postForm.pick_type" :placeholder="'属性:'" clearable
class="postInfo-container-item" style="width:120px" v-if="isEdit" disabled>
<el-option v-for="item in PickTypeOptions" :key="item.key" :label="item.display_name"
:value="item.key"/>
</el-select>
<el-select v-model="postForm.pick_type" :placeholder="'属性:'" clearable
class="postInfo-container-item" style="width:120px" v-else>
<el-option v-for="item in PickTypeOptions" :key="item.key" :label="item.display_name"
:value="item.key"/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="45px" label="位置:" prop="position">
<el-input :rows="1" v-model="postForm.position" type="number" class="article-textarea"
style="width: 120px"
placeholder="请输入内容"/>
</el-form-item>
</el-col>
</el-row>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<div class="postInfo-container">
<el-row>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="45px" label="pickid:" prop="id"
v-if="isEdit">
<el-input :rows="1" v-model="postForm.id" type="number" class="article-textarea"
style="width: 120px" disabled/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="pick用户:" prop="user_nums"
v-if="isEdit">
<el-input :rows="1" v-model="postForm.user_nums" type="number" class="article-textarea"
style="width: 120px" disabled/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="85px" label="创建时间:" prop="create_time"
v-if="isEdit">
<el-input :rows="1" v-model="postForm.create_time" type="text" class="article-textarea"
style="width: 170px" disabled/>
</el-form-item>
</el-col>
</el-row>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label-width="45px" label="国家:" class="postInfo-container-item" prop="country">
<el-select v-model="country" :remote-method="getRemoteCountryList" filterable remote multiple
value-key="id"
placeholder="搜索国家" style="width: 100%">
<el-option v-for="(item,index) in countryListOptions" :key="item+index" :label="item"
:value="item"/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label-width="45px" label="小组:" class="postInfo-container-item" prop="pick_group">
<el-select
v-model="pick_group"
:remote-method="getRemoteGroupList"
multiple
filterable
remote
reserve-keyword
clearable
placeholder="搜索小组"
style="width: 100%"
:loading="loading"
value-key="id"
>
<el-option v-for="(item, index) in groupListOptions" :key="item+index" :label="item"
:value="item"/>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-form-item style="margin-bottom: 40px;" label-width="45px" label="简介:" prop="desc">
<el-input :rows="1" v-model="postForm.desc" type="textarea" class="article-textarea" autosize
placeholder="请输入内容"/>
<span v-show="contentShortLength" class="word-counter">{{ contentShortLength }}字</span>
</el-form-item>
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="是否在线:">
<el-radio-group v-model="postForm.is_online">
<el-radio :label="1">是</el-radio>
<el-radio :label="0">否</el-radio>
</el-radio-group>
</el-form-item>
</el-card>
</el-row>
<!--pick明星相关-->
<el-row :gutter="20" style="margin-top:50px;" v-if="this.postForm.pick_type_origin == 1 && this.isEdit">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span v-if="">pick明星相关</span>
</div>
<div style="margin-bottom:50px;">
<div class="filter-container">
<!--<el-select v-model="celebrity_id" :remote-method="getRemoteCelebrityList" filterable remote clearable-->
<!--value-key="id"-->
<!--placeholder="添加明星" style="width: 220px">-->
<!--<el-option v-for="(item,index) in celebrityListOptions" :key="item+index"-->
<!--:label="item" :value="item"/>-->
<!--</el-select>-->
<!--<el-button v-waves class="filter-item" type="primary" icon="el-icon-edit" @click="append">添加-->
<!--</el-button>-->
<!--<el-button v-waves class="filter-item" type="primary" icon="el-icon-delete" @click="del">移除-->
<!--</el-button>-->
</div>
<el-table :data="data" border fit highlight-current-row style="width: 100%"
ref="multipleTable" @selection-change="handleSelectionChange">
<el-table-column type="selection" align="center"></el-table-column>
<el-table-column align="center" label="明星ID">
<template slot-scope="scope">
<router-link :to="'/star/edit/'+scope.row.celebrity_id" class="link-type">
<span>{{ scope.row.celebrity_id }}</span>
</router-link>
</template>
</el-table-column>
<el-table-column align="center" label="明星名称">
<template slot-scope="scope">
<span>{{ scope.row.celebrity_name }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="pick值">
<template slot-scope="scope">
<span>{{ scope.row.pick_nums }}</span>
</template>
</el-table-column>
<el-table-column align="center" min-width="100" label="添加pick值">
<template slot-scope="scope">
<template v-if="scope.row.edit">
<el-input v-model="scope.row.fake_pick_nums" type="number" class="edit-input" size="small"/>
<el-button class="cancel-btn" size="small" icon="el-icon-refresh" type="warning"
@click="cancelEdit(scope.row)">取消
</el-button>
</template>
<span v-else>{{ scope.row.fake_pick_nums }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="操作" width="120">
<template slot-scope="scope">
<el-button v-if="scope.row.edit" type="success" size="small" icon="el-icon-circle-check-outline"
@click="confirmEdit(scope.row)">确认
</el-button>
<el-button v-else type="primary" size="small" icon="el-icon-edit"
@click="scope.row.edit=!scope.row.edit">添加
</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
style="margin-left: 150px;" @pagination="getList"/>
</div>
</el-card>
</el-row>
<!--pick帖子相关-->
<el-row :gutter="20" style="margin-top:50px;" v-if="this.postForm.pick_type_origin == 0 && this.isEdit">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span v-if="">pick帖子相关</span>
</div>
<div style="margin-bottom:50px;">
<div class="filter-container">
<!--<el-select v-model="topic_id" :remote-method="getRemoteTopicList" filterable remote clearable-->
<!--value-key="id"-->
<!--placeholder="添加帖子" style="width: 220px">-->
<!--<el-option v-for="(item, index) in topicListOptions" :key="item+index"-->
<!--:label="item" :value="item"/>-->
<!--</el-select>-->
<!--<el-button v-waves class="filter-item" type="primary" icon="el-icon-edit" @click="append">添加-->
<!--</el-button>-->
<!--<el-button v-waves class="filter-item" type="primary" icon="el-icon-delete" @click="del">移除-->
<!--</el-button>-->
</div>
<el-table :data="data" border fit highlight-current-row style="width: 100%"
ref="multipleTable" @selection-change="handleSelectionChange">
<el-table-column type="selection" align="center"></el-table-column>
<el-table-column align="center" label="帖子ID">
<template slot-scope="scope">
<router-link :to="'/topic/edit/'+scope.row.topic_id" class="link-type">
<span>{{ scope.row.topic_id }}</span>
</router-link>
</template>
</el-table-column>
<el-table-column align="center" label="帖子名称">
<template slot-scope="scope">
<span>{{ scope.row.topic_name }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="pick值">
<template slot-scope="scope">
<span>{{ scope.row.pick_nums }}</span>
</template>
</el-table-column>
<el-table-column align="center" min-width="100" label="添加pick值">
<template slot-scope="scope">
<template v-if="scope.row.edit">
<el-input v-model="scope.row.fake_pick_nums" type="number" class="edit-input" size="small"/>
<el-button class="cancel-btn" size="small" icon="el-icon-refresh" type="warning"
@click="cancelEdit(scope.row)">取消
</el-button>
</template>
<span v-else>{{ scope.row.fake_pick_nums }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="操作" width="120">
<template slot-scope="scope">
<el-button v-if="scope.row.edit" type="success" size="small" icon="el-icon-circle-check-outline"
@click="confirmEdit(scope.row)">确认
</el-button>
<el-button v-else type="primary" size="small" icon="el-icon-edit"
@click="scope.row.edit=!scope.row.edit">添加
</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
style="margin-left: 150px;" @pagination="getList"/>
</div>
</el-card>
</el-row>
</div>
</el-form>
</div>
</template>
<script>
import MDinput from '@/components/MDinput'
import Sticky from '@/components/Sticky' // 粘性header组件
import Pagination from '@/components/Pagination'
import waves from '@/directive/waves'
import {
fetchPickDetail,
CreatePick,
fetchPickTopicList,
fetchPickCelebrityList,
AddFakePickNums,
PickTopicDetail,
PickCelebrityDetail,
delPickTopic,
delPickCelebrity
} from '@/api/pick'
import {groupSearch, citySearch, celebritySearch, topicSearch, countrySearch} from '@/api/remoteSearch'
import {isInArray, removeByvale} from "@/utils";
const defaultForm = {
status: 'draft',
name: '',
desc: '',
gender: '',
city: [],
country: [],
pick_group: [],
pick_type: '',
position: '',
is_online: 0,
}
export default {
name: 'PickDetail',
components: {MDinput, Sticky, Pagination},
directives: {waves},
props: {
isEdit: {
type: Boolean,
default: false
}
},
data() {
const validateRequire = (rule, value, callback) => {
if (value === '') {
this.$message({
message: rule.field + '为必传项',
type: 'error'
})
callback(new Error(rule.field + '为必传项'))
} else {
callback()
}
}
return {
postForm: Object.assign({}, defaultForm),
loading: false,
city: [],
country: [],
pick_group: [],
pick_type_origin: '',
celebrity_id: '',
topic_id: '',
del_list: [],
countryListOptions: [],
groupListOptions: [],
celebrityListOptions: [],
topicListOptions: [],
GenderTypeOptions: [
{'key': 2, 'display_name': '全部'},
{'key': 0, 'display_name': '男'},
{'key': 1, 'display_name': '女'},
],
PickTypeOptions: [
{'key': 1, 'display_name': '明星打榜'},
{'key': 0, 'display_name': 'PICK帖子'},
],
rules: {
name: [{validator: validateRequire, trigger: 'blur'}],
desc: [{validator: validateRequire, trigger: 'blur'}],
gender: [{validator: validateRequire, trigger: 'blur'}],
city: [{validator: validateRequire, trigger: 'blur'}],
pick_type: [{validator: validateRequire, trigger: 'blur'}],
position: [{validator: validateRequire, trigger: 'blur'}],
},
tempRoute: {},
listQuery: {
id: '',
pick_type: '',
page: 1,
limit: 10,
filter: {},
},
list: null,
total: 0,
listLoading: true,
origin_len: 0,
topic_ids: [],
celebrity_ids: [],
new_ids: [],
del_ids: [],
}
},
computed: {
contentShortLength() {
return this.postForm.desc.length
},
data() {
return this.list.filter((d) => {
let is_del = false;
for (let i = 0; i < this.del_list.length; i++) {
if (d.topic_id == this.del_list[i].topic_id) {
is_del = true;
break
}
}
if (!is_del) {
return d
}
})
}
},
created() {
if (this.isEdit) {
const id = this.$route.params && this.$route.params.id
this.fetchData(id)
this.getList()
} else {
this.postForm = Object.assign({}, defaultForm)
}
this.tempRoute = Object.assign({}, this.$route)
},
methods: {
fetchData(id) {
fetchPickDetail(id).then(response => {
// select 回填数据处理,后期再进行优化
let rep = response.data.data.data;
for (let i = 0; i < rep.pick_group.length; i++) {
this.pick_group.push(rep.pick_group[i]['id'] + ':' + rep.pick_group[i]['name'])
}
for (let i = 0; i < rep.country.length; i++) {
this.country.push(rep.country[i]['id'] + ':' + rep.country[i]['name'])
}
this.postForm = rep
this.listQuery.pick_type = rep.pick_type_origin
}).catch(err => {
console.log(err)
})
},
submitForm() {
this.$refs.postForm.validate(valid => {
if (valid) {
this.loading = true;
this.postForm.city = JSON.stringify(this.city);
this.postForm.country = JSON.stringify(this.country)
this.postForm.pick_group = JSON.stringify(this.pick_group);
CreatePick(this.postForm).then(response => {
this.$notify({
title: '成功',
message: response.data.data.message,
type: 'success',
duration: 2000
})
setTimeout(() => {
this.$router.push('/pick/list')
}, 1000)
}).catch(err => {
this.$notify({
title: '失败',
message: '操作失败',
type: 'danger',
duration: 2000
})
});
this.postForm.status = 'published'
this.loading = false
} else {
console.log('error submit!!')
return false
}
})
},
getRemoteCountryList(query){
countrySearch(query).then(response =>{
if (!response.data.data.data) return
this.countryListOptions = response.data.data.data
})
},
getRemoteGroupList(query) {
groupSearch(query).then(response => {
if (!response.data.data.data) return
this.groupListOptions = response.data.data.data
})
},
getRemoteTopicList(query) {
topicSearch(query).then(response => {
if (!response.data.data.data) return
this.topicListOptions = response.data.data.data
})
},
getRemoteCelebrityList(query) {
celebritySearch(query).then(response => {
if (!response.data.data.data) return
this.celebrityListOptions = response.data.data.data
})
},
// 分页相关
handleSelectionChange(val) {
this.multipleSelection = val;
},
getList() {
this.listLoading = true
this.listQuery.id = this.$route.params && this.$route.params.id
if (this.$route.query.pick_type === '1'){
fetchPickCelebrityList(this.listQuery).then(response => {
const items = response.data.data.data
this.list = items.map(v => {
this.$set(v, 'edit', false)
v.original_fake_pick_nums = v.fake_pick_nums
return v
})
this.total = response.data.data.total
this.origin_len = response.data.data.total
this.listLoading = false;
})
} else{
fetchPickTopicList(this.listQuery).then(response => {
const items = response.data.data.data
this.list = items.map(v => {
this.$set(v, 'edit', false)
v.original_fake_pick_nums = v.fake_pick_nums
return v
})
this.total = response.data.data.total
this.origin_len = response.data.data.total
this.listLoading = false;
})
}
},
cancelEdit(row) {
row.fake_pick_nums = row.original_fake_pick_nums
row.edit = false
this.$message({
message: '取消成功',
type: 'warning'
})
},
confirmEdit(row) {
const id = this.$route.params && this.$route.params.id
row.edit = false
row.original_fake_pick_nums = row.fake_pick_nums
row.pick_id = id
this.$message({
message: '添加成功',
type: 'success'
})
AddFakePickNums(row).then(response => {
}).catch(err => {
})
},
append() {
if (this.postForm.pick_type_origin == 0) {
if (this.topic_id == "") {
this.$message.error('请输入搜索内容~~')
this.topic_id = ''
return false
}
let data = {
topic_id: this.topic_id,
pick_id: this.postForm.id,
}
PickTopicDetail(data).then(response => {
this.$message.success(response.data.data.message)
})
this.topic_id = ''
setTimeout(() => {
this.$router.go(0)
}, 1300)
} else if (this.postForm.pick_type_origin == 1) {
if (this.celebrity_id == "") {
this.$message.error('请输入搜索内容~~')
this.celebrity_id = ''
return false;
} else {
let data = {
celebrity_id: this.celebrity_id,
pick_id: this.postForm.id,
}
PickCelebrityDetail(data).then(response => {
this.$message.success(response.data.data.message)
})
this.celebrity_id = ''
setTimeout(() => {
this.$router.go(0)
}, 1300)
}
}
},
del() {
this.total = this.origin_len - this.del_list.length
let select__ids = []
this.del_list.push(...this.multipleSelection)
if (this.postForm.pick_type_origin == 0) {
for (let i = 0; i < this.multipleSelection.length; i++) {
select__ids.push(this.multipleSelection[i].topic_id)
}
let data = {
del_ids: JSON.stringify(select__ids),
pick_id: this.postForm.id,
}
delPickTopic(data).then(response => {
this.$message.success('操作成功')
setTimeout(() => {
this.$router.go(0)
}, 1300)
})
} else {
for (let i = 0; i < this.multipleSelection.length; i++) {
select__ids.push(this.multipleSelection[i].celebrity_id)
}
let data = {
del_ids: JSON.stringify(select__ids),
pick_id: this.postForm.id,
}
delPickCelebrity(data).then(response => {
this.$message.success('操作成功')
setTimeout(() => {
this.$router.go(0)
}, 1300)
})
}
},
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.createPost-container {
position: relative;
.createPost-main-container {
padding: 40px 45px 20px 50px;
.postInfo-container {
position: relative;
@include clearfix;
margin-bottom: 10px;
.postInfo-container-item {
float: left;
}
}
.editor-container {
min-height: 500px;
margin: 0 0 30px;
.editor-upload-btn-container {
text-align: right;
margin-right: 10px;
.editor-upload-btn {
display: inline-block;
}
}
}
}
.word-counter {
width: 40px;
position: absolute;
right: -10px;
top: 0px;
}
}
.edit-input {
padding-right: 100px;
}
.cancel-btn {
position: absolute;
right: 15px;
top: 10px;
}
</style>