contentAdd.vue
22.7 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
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
<!-- 规则配置 -->
<template>
<d2-container class="edit-content">
<div class="content-form">
<div class="content-info">
<div class="title">
<div class="line"></div>
<span>内容信息</span>
</div>
<div class="info-form-main">
<el-form :model="formData" :rules="rules" ref="ruleForm">
<el-form-item
prop="title"
label="标题:"
label-width="120px"
class="dis-in-block"
:style="{ 'margin-bottom': '22px' }">
<el-input
v-model.trim="formData.title"
placeholder="请输入标题"
maxlength="20"
:style="{ width: '432px' }"
clearable>
</el-input>
</el-form-item>
<el-form-item label-width="120px" label="类型:" prop="type">
<el-radio-group
v-model="formData.type"
@change="changeFileType()">
<el-radio :label="0">图片</el-radio>
<el-radio :label="1">视频</el-radio>
<el-radio :label="2">pdf</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label-width="120px" label="封面:" prop="cover">
<glsx-preview
:pic-options="coverOptions"
:image-url-arr="formData.cover"
limit="1"></glsx-preview>
</el-form-item>
<el-form-item
prop="subtitle"
label="副标题:"
label-width="120px"
class="dis-in-block"
:style="{ 'margin-bottom': '22px' }">
<el-input
type="textarea"
v-model.trim="formData.subtitle"
placeholder="200个字符以内"
maxlength="200"
:style="{ width: '580px' }"
clearable
show-word-limit>
</el-input>
</el-form-item>
<el-form-item label-width="120px" label="内容:" prop="imageList">
<div v-if="formData.type == 0">
<glsx-preview
:pic-options="picOptions"
@beforeUpload="beforeUpload"
@afterUpload="afterUpload"
:image-url-arr="formData.imageList"
limit="10"></glsx-preview>
<p
class="photo-top-tips"
v-if="formData.imageList && formData.imageList.length">
图片按照以上排序进行展示,可拖动调整排序
<span class="tip-btn" @click="showEffect()">查看效果</span>
</p>
<p class="photo-top-tips" v-else>
支持 .jpg .jpeg .png,单个文件不超过10M,最多上传10个文件
</p>
</div>
<div v-if="formData.type == 1">
<glsx-preview
:pic-options="videoOptions"
@beforeUpload="beforeUpload"
@afterUpload="afterUpload"
:image-url-arr="formData.imageList"
limit="1"></glsx-preview>
<p class="photo-top-tips">支持 .mp4,大小不超过200M</p>
</div>
<div v-if="formData.type == 2">
<uploadPdf
:pic-options="pdfOptions"
:image-url-arr="formData.imageList"
@beforeUpload="beforeUpload"
@afterUpload="afterUpload"
limit="1"></uploadPdf>
<p class="photo-top-tips">支持 .pdf,大小不超过50M</p>
</div>
</el-form-item>
</el-form>
</div>
</div>
<div class="publish-channel-form">
<div class="title">
<div class="line"></div>
<span>发布渠道</span>
</div>
<div class="publish-info">
<el-form :model="formData" :rules="rules" ref="channelForm">
<el-form-item
prop="scene"
label="业务场景:"
label-width="120px"
class="dis-in-block"
:style="{ 'margin-bottom': '22px' }">
<el-select
@change="clearTableFn(1)"
:style="{ width: '432px' }"
v-model="formData.scene"
placeholder="请选择">
<el-option
v-for="(i, indx) in sceneList"
:key="indx"
:label="i.label"
:value="i.id"></el-option>
</el-select>
</el-form-item>
<el-form-item
label-width="120px"
label="可见渠道:"
prop="showChannel">
<el-radio-group v-model="formData.showChannel">
<el-radio :label="0">培训资料</el-radio>
<el-radio :label="1">营销素材</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item
label-width="120px"
label="可见门店:"
prop="showMerchant">
<div>
<el-radio-group
v-model="formData.showMerchant"
@change="clearTableFn(2)">
<el-radio :label="0">全部门店</el-radio>
<el-radio :label="2">指定门店</el-radio>
<el-radio :label="1">指定品牌</el-radio>
</el-radio-group>
</div>
<div>
<el-button
class="btn-class"
size="small"
@click="openMerchantDialog"
v-if="formData.showMerchant == 2">选择门店</el-button>
<el-button
class="btn-class"
size="small"
@click="openMerchantDialog"
v-if="formData.showMerchant == 1">选择品牌</el-button>
</div>
<div
class=""
v-if="formData.showMerchant != 0 && tableData.length">
<d2-table
ref="recordTable"
:table-params="
formData.showMerchant == 1 ? brandTableParams : tableParams
"
:table-data="tableData"
:has-page="false"
:height="tableData.length > 10 ? 350 : ''">
<div slot="auth-button" slot-scope="scope">
<el-button
type="text"
size="mini"
@click="delMerchant(scope.scope, scope.index)">
删除
</el-button>
</div>
</d2-table>
</div>
</el-form-item>
</el-form>
</div>
</div>
<div style="margin-top: 40px; text-align: center">
<el-button type="primary" class="width_100" @click="checkValidData(1)">保存并使用</el-button>
<el-button
type="primary"
plain
class="width_100"
@click="checkValidData(0)"
v-if="!routeInfo.status">存草稿</el-button>
<el-button class="width_100 cancel-btn" @click="handleCancel">取消</el-button>
</div>
</div>
<relate-store-dialog
v-if="relateStoreVisible"
ref="formRelateStore"
title="选择门店"
:relate-store-visible="relateStoreVisible"
:store-api="
[1, 2, 3].includes(formData.scene) ? getList : getAccountMerchantList
"
:store-search-form="storeSearchForm"
:store-selected="storeSelected"
:selected-scene="formData.scene"
@handleRelateStoreConfirm="handleRelateStoreConfirm"
@handleRelateStoreClose="handleRelateStoreClose">
<el-row slot>
<el-form :model="storeSearchForm" ref="relate" :inline="true">
<el-form-item label="门店名称:">
<el-input
v-model.trim="storeSearchForm.merchantName"
placeholder="门店名称"
@keydown.native="handleStoreInput"
max-length="50"
clearable />
</el-form-item>
<el-form-item label="门店商户号:">
<el-input
v-model.trim="storeSearchForm.merchantId"
placeholder="门店商户号"
@input="
(value) =>
(storeSearchForm.merchantId = value.replace(/[^\d]/g, ''))
"
@keydown.native="handleStoreInput"
clearable />
</el-form-item>
<el-form-item label="服务对接:">
<el-input
v-model.trim="storeSearchForm.yqMerchantName"
placeholder="服务对接"
max-length="50"
@keydown.native="handleStoreInput"
clearable />
</el-form-item>
<el-form-item label="服务对接商户号:">
<el-input
v-model.trim="storeSearchForm.yqMerchantId"
placeholder="服务对接商户号"
@input="
(value) =>
(storeSearchForm.yqMerchantId = value.replace(/[^\d]/g, ''))
"
@keydown.native="handleStoreInput"
clearable />
</el-form-item>
<el-button type="primary" @click="handleSearchStore">搜索</el-button>
</el-form>
</el-row>
</relate-store-dialog>
<brandDialog
v-if="brandVisible"
ref="brandRef"
:relate-store-visible="brandVisible"
:store-selected="storeSelected"
@handleRelateStoreConfirm="handleRelateStoreConfirm"
@handleRelateStoreClose="handleRelateStoreClose">
</brandDialog>
<previewEffectDialog
v-if="showImageView"
:visible="showImageView"
:list="formData.imageList"
@closeDialog="closeDialog"></previewEffectDialog>
<el-dialog :visible.sync="lookImgVisible">
<img width="100%" :src="dialogObj.url" alt="图片" />
</el-dialog>
</d2-container>
</template>
<script>
import { Util, deepClone } from "@/common/util"
import { SCENE_OPTIONS } from "./constant"
import preview from "./components/preview"
import uploadPdf from "./components/uploadPdf"
import previewEffectDialog from "./components/previewEffectDialog"
import relateStoreDialog from "@/views/goods/grounding/components/relateStoreDialog.vue"
import brandDialog from "./components/brandDialog"
import { getList, getAccountMerchantList } from "@/api/merchant"
import {
addContent,
updateContent,
getContentDetail
} from "@api/contentManager"
export default {
name: "ContentAdd",
components: {
glsxPreview: preview,
uploadPdf,
brandDialog: brandDialog,
relateStoreDialog,
previewEffectDialog
},
data() {
return {
getList,
getAccountMerchantList,
showImageView: false,
relateStoreVisible: false,
uploading: false,
storeSearchForm: {
merchantName: "",
merchantId: "",
yqMerchantName: "",
yqMerchantId: ""
},
storeSelected: [],
merchantVisible: false,
brandVisible: false,
tableData: [],
coverOptions: {
width: "88px",
height: "88px",
isClose: true,
limitSize: 1
},
picOptions: {
width: "88px",
height: "88px",
isClose: true,
limitSize: 10,
type: "img",
isDrag: true
},
videoOptions: {
width: "88px",
height: "88px",
isClose: true,
limitSize: 200,
type: "video"
},
pdfOptions: {
width: "104px",
height: "104px",
isClose: true,
limitSize: 50
},
formData: {
title: "",
type: 0,
cover: [],
subtitle: "",
imageList: [],
scene: "",
showChannel: 0,
showMerchant: 0
},
rules: {
title: [{ required: true, message: "请输入标题", trigger: "change" }],
type: [{ required: true, message: "请选择类型", trigger: "change" }],
// cover: {
// required: true,
// validator: (rule, value, callback) => {
// if (value && value[0]) {
// callback()
// } else {
// callback("请上传封面")
// }
// },
// trigger: "change"
// },
// subtitle: [
// { required: true, message: "请输入副标题", trigger: "change" }
// ],
imageList: {
required: true,
validator: (rule, value, callback) => {
if (value && value.length) {
callback()
} else {
callback("请上传内容文件")
}
},
trigger: "change"
},
scene: [
{ required: true, message: "请选择业务场景", trigger: "change" }
],
showChannel: [
{ required: true, message: "请选择可见渠道", trigger: "change" }
],
showMerchant: {
required: true,
validator: (rule, value, callback) => {
const showMerchant = this.formData.showMerchant
if (this.tableData.length || showMerchant == 0) {
callback()
} else {
callback(`请选择${showMerchant == 1 ? "品牌" : "门店"}`)
}
},
trigger: "change"
}
},
dialogObj: {},
lookImgVisible: false,
sceneList: SCENE_OPTIONS,
tableSearchForm: {},
tableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: "list",
tableOption: true,
tableColumns: [
{
label: "门店名称",
prop: "merchantName"
},
{
label: "门店商户号",
prop: "merchantId"
}
]
},
brandTableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: "brandList",
tableOption: true,
tableColumns: [
{
label: "品牌名称",
prop: "label"
}
]
},
routeInfo: {}
}
},
mounted() {
const { id } = this.$route.query
this.routeInfo = this.$route.query
if (id) this.getDetail()
},
methods: {
// 切换文件类型
changeFileType(e) {
this.formData.imageList = []
this.uploading = false
},
getDetail() {
getContentDetail({ id: this.$route.query.id }).then((res) => {
if (res) {
for (const key in this.formData) {
if (key == "cover") {
this.formData[key] = res[key] ? [res[key]] : []
} else if (key == "imageList") {
if (res.type != 2) {
// type = 2 是pdf,pdf的imageList数据结构为['url','url']
this.formData[key] = res.detailInfos?.map((item) => item.image)
} else {
// type = 2 是pdf,pdf的imageList数据结构为[image: '',imageName: '']
this.formData[key] = res.detailInfos
}
} else {
this.formData[key] = res[key]
}
}
if (res.showMerchant) {
this.tableData =
res?.assignInfos.map((item) => {
const { assignId, assignName } = item
return res.showMerchant == 2
? {
merchantId: assignId,
merchantName: assignName
}
: {
id: assignId,
label: assignName
}
}) || []
}
}
})
},
// 切换业务场景并且是指定门店 或者 切换可见门店 就清空已选的
clearTableFn(type) {
if ((type == 1 && this.formData.showMerchant == 2) || type == 2) {
this.storeSelected = []
this.tableData = []
}
},
getParams(type) {
const params = deepClone(this.formData)
params.cover = params.cover[0]
if (params.showMerchant != 0) {
const list = this.tableData?.map((item) => {
return {
assignName:
params.showMerchant == 2 ? item.merchantName : item.label,
assignId: params.showMerchant == 2 ? item.merchantId : item.id
}
})
params.assignInfoList = list
}
if (params.type != 2) {
params.imageList = params.imageList.map((item) => {
return {
image: item,
imageName: ""
}
})
}
params.status = type
if (this.$route.query.id) params.id = this.$route.query.id
return params
},
// 草稿和保存都先检验
checkValidData(type) {
if (this.uploading) { return this.$message.error(`文件上传中,请耐心等待文件上传完成`) }
this.$refs.ruleForm.validate((valid) => {
this.$refs.channelForm.validate((cvalid) => {
if (valid && cvalid) {
if (type) {
this.confirmAdd(type)
} else {
this.commitFn(type)
}
}
})
})
},
beforeUpload() {
this.uploading = true
},
afterUpload() {
this.uploading = false
},
// 保存需要二次弹窗
confirmAdd(type) {
this.$confirm("是否确认保存", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then((end) => {
if (end == "confirm") {
this.commitFn(type)
}
})
},
//
commitFn(type) {
const params = this.getParams(type)
const _api = params.id ? updateContent : addContent
_api(params).then((res) => {
if (res) {
this.$message.success(
`${!type ? "保存草稿" : params.id ? "修改" : "新增"}成功`
)
this.handleCancel()
}
})
},
// 取消按钮返回列表页
handleCancel() {
this.$router.push({
name: "contentManagerList"
})
},
// 打开门店弹窗或者品牌弹窗
openMerchantDialog() {
if (this.formData.showMerchant == 1) {
this.brandVisible = true
} else {
if (!this.formData.scene && this.formData.scene !== 0) {
return this.$message.error("请先选择业务场景")
// 接口不同,门店要先选择业务场景
}
this.relateStoreVisible = true
}
this.storeSelected = deepClone(this.tableData)
},
// 确认门店弹窗或者品牌弹窗
handleRelateStoreConfirm(selectedData) {
if (!selectedData.length) {
return this.$message.error(
`请选择${this.formData.showMerchant == 1 ? "品牌" : "门店"}`
)
}
const maxMerNum = 200
const maxBrandNum = 10
if (
this.formData.showMerchant == 1 &&
selectedData?.length > maxBrandNum
) {
return this.$message.error(`品牌最多只能选择${maxBrandNum}个`)
}
if (this.formData.showMerchant == 2 && selectedData?.length > maxMerNum) {
return this.$message.error(`门店最多只能选择${maxMerNum}个`)
}
this.$refs.channelForm.clearValidate("showMerchant")
this.tableData = selectedData
this.handleRelateStoreClose()
},
// 关闭门店弹窗或者品牌弹窗
handleRelateStoreClose() {
this.relateStoreVisible = false
this.brandVisible = false
},
// 门店弹窗按回车查询
handleStoreInput(e) {
e.keyCode === 13 && this.handleSearchStore()
},
// 门店弹窗点击查询
handleSearchStore() {
this.$refs.formRelateStore.handleCurrentChange(1)
},
// 删除table 门店或者品牌
delMerchant(row, idx) {
this.tableData.splice(idx, 1)
},
// 关闭查看效果
closeDialog() {
this.showImageView = false
},
// 点击查看效果 图片预览
showEffect() {
this.showImageView = true
}
}
}
</script>
<style scoped lang="scss">
.content-form {
.title {
height: 50px;
line-height: 50px;
padding: 0 20px;
border-bottom: 1px solid #e5e5e5;
font-size: 16px;
font-weight: 600;
color: #333333;
display: flex;
align-items: center;
.line {
width: 4px;
height: 16px;
background: #185efe;
border-radius: 2px;
margin-right: 8px;
}
}
}
.content-info {
background: #fff;
.info-form-main {
padding: 16px 20px;
.dis-in-block {
display: inline-block;
}
.photo-top-tips {
margin: 0 0;
color: #999999;
.tip-btn {
color: #185efe;
cursor: pointer;
}
}
.activity-img {
position: relative;
cursor: pointer;
background: #f4f4f4;
}
.wrap {
width: 88px;
height: 88px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.img-w-h {
width: 88px;
height: 88px;
}
.add {
font-size: 24px;
height: 24px;
color: #999999;
}
.number {
font-weight: 400;
font-size: 12px;
color: #999999;
}
.muti-imgs {
display: inline-block;
position: relative;
}
.muti-imgs:hover .img-btns {
display: block;
}
.img-btns {
display: none;
height: 100%;
position: absolute;
width: 88px;
height: 88px;
left: 0;
top: 0;
z-index: 2;
color: #fff;
background: rgba(0, 0, 0, 0.5);
}
.btn-item {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
width: 70%;
justify-content: space-around;
}
.el-icon-delete,
.el-icon-zoom-in {
cursor: pointer;
}
.pdf_box {
width: 98px;
height: 32px;
background: #f8f8f8;
border: 1px solid #e6e6e6;
border-radius: 4px;
position: relative;
cursor: pointer;
.pdf_wrap {
width: 98px;
height: 32px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: flex;
align-items: center;
justify-content: center;
.add {
font-size: 24px;
color: #999999;
}
.number {
font-weight: 400;
font-size: 12px;
color: #999999;
}
}
}
}
}
.publish-channel-form {
background: white;
margin-top: 16px;
.publish-info {
padding: 16px 20px;
}
.btn-class {
background: #f8f8f8;
}
}
</style>