index.vue
36.5 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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
<template>
<div class="task-box">
<div class="task-content">
<div class="task-title">基础信息</div>
<!-- 基础信息表单 -->
<el-form
:model="basicForm"
:rules="basicRules"
ref="basicForm"
label-width="154px"
>
<el-form-item label="业务场景:" prop="businessScene">
<el-select
v-model="basicForm.businessScene"
placeholder="请选择业务场景"
size="small"
:disabled="isEditor"
>
<el-option label="1.3存量用户众筹" :value="3"></el-option>
</el-select>
</el-form-item>
<el-form-item label="商户:" prop="merchantId">
<el-select
v-model="basicForm.merchantId"
filterable
remote
:remote-method="filterMethod"
no-data-text="暂无数据"
placeholder="请选择商户"
size="small"
@change="changeMerchant"
@focus="selectMerchant"
:loading="merchantLoading"
:disabled="isEditor"
>
<el-option
v-for="(item, index) in merchantList"
:key="index"
:label="item.merchantName"
:value="item.merchantId"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="活动/产品:" prop="activityId">
<el-input
v-model="basicForm.activityName"
placeholder="请选择活动/产品"
size="small"
@focus="openActivityDia"
:disabled="isEditor"
readonly
></el-input>
</el-form-item>
<el-form-item label="任务指定人群:" prop="crowd">
<el-select
v-model="basicForm.crowd"
multiple
placeholder="请选择任务指定人群"
size="small"
>
<el-option label="1.0新车权益销售" value="0"></el-option>
<el-option label="1.1次新车精品升级" value="1"></el-option>
<el-option label="1.2次新车线上转化" value="2"></el-option>
<el-option label="1.3存量用户众筹" value="3"></el-option>
</el-select>
</el-form-item>
<el-form-item label="发放渠道:" prop="channel">
<el-radio-group v-model="basicForm.channel">
<el-radio :label="1">广联</el-radio>
<el-radio :label="2">门店</el-radio>
<el-radio :label="3">服务商</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注:">
<el-input
type="textarea"
v-model="basicForm.remark"
size="small"
></el-input>
</el-form-item>
</el-form>
<template v-if="basicForm.activityName || isClone || isEditor">
<div class="task-title">任务计划</div>
<!-- 任务计划tab栏 -->
<el-tabs v-model="activeName" type="card" @tab-click="handleClick">
<el-tab-pane
v-for="(item, index) in taskList"
:key="index"
:label="
item.activityTime == -1
? '完整周期'
: `${item.activityTime + '(第' + (index + 1) + '天)'}`
"
:name="index + ''"
>
<el-button
type="primary"
size="small"
@click="addTaskType(item, index)"
:disabled="item.timeFlag"
>添加</el-button
>
<el-alert
type="info"
title="当前时间在已选活动开始时间之后,无法再次编辑"
:closable="false"
v-if="item.timeFlag"
></el-alert>
<div>
<el-form
ref="taskForm"
:model="item"
:rules="taskFormRules"
label-width="154px"
:disabled="item.timeFlag"
>
<div v-for="(itm, index1) in item.missionList" :key="index1">
<div class="task-date-box">
<div class="task-date-box-left">
<el-form-item
label="任务类型:"
:prop="'missionList.' + index1 + '.missonType'"
:rules="taskFormRules.missonType"
>
<el-select
v-model="itm.missonType"
placeholder="请选择任务类型:"
@change="selectTaskType(item, index, itm, index1)"
size="small"
>
<el-option label="注册认证" :value="1"></el-option>
<el-option label="分享指标" :value="2"></el-option>
<el-option label="浏览指标" :value="3"></el-option>
<el-option label="访客指标" :value="4"></el-option>
<el-option
v-if="item.activityTime == -1"
label="成单指标"
:value="5"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="任务名称:"
:prop="'missionList.' + index1 + '.missionName'"
:rules="taskFormRules.missionName"
>
<el-input
v-model="itm.missionName"
maxlength="20"
show-word-limit
size="small"
></el-input>
</el-form-item>
<el-form-item
label="任务说明:"
:prop="'missionList.' + index1 + '.missonDesc'"
:rules="taskFormRules.missonDesc"
>
<el-input
type="textarea"
v-model="itm.missonDesc"
maxlength="50"
show-word-limit
size="small"
></el-input>
</el-form-item>
<el-form-item
:prop="'missionList.' + index1 + '.missionMaterialList'"
:rules="taskFormRules.attachmentList"
v-if="itm.missonType == 2"
>
<label slot="label" class="required">分享素材:</label>
<GLEditor
:key="'missionList' + itm.id + 'welcome'"
ref="welcome"
:form="'customer'"
style="line-height: 12px"
:btnList="btnList"
:previewData="itm.missionMaterialList"
@getEditor="getEditor(item, index, itm, index1)"
@shareMatrial="shareMatrial"
></GLEditor>
</el-form-item>
<el-form-item
v-if="itm.missonType && itm.missonType != 1"
label="奖励模式:"
:prop="'missionList.' + index1 + '.rewardType'"
:rules="taskFormRules.rewardType"
>
<el-radio-group
v-model="itm.rewardType"
@change="rewardTypeChange(itm)"
>
<el-radio :label="1">累计奖励</el-radio>
<el-radio :label="2">排名奖励</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item
v-if="itm.rewardType && itm.rewardType == 1"
label="奖励次数:"
:prop="'missionList.' + index1 + '.rewardCount'"
:rules="taskFormRules.rewardCount"
>
<el-radio-group
v-model="itm.rewardCount"
@change="rewardCountChange(itm)"
>
<el-radio :label="1">单次</el-radio>
<el-radio :label="2">重复累计</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item
v-if="itm.rewardType == 2"
label="触发排名:"
:prop="'missionList.' + index1 + '.triggerValue'"
:rules="taskFormRules.triggerValue"
>
<el-radio-group v-model="itm.triggerValue">
<el-radio :label="1">第一名</el-radio>
<el-radio :label="2">第二名</el-radio>
<el-radio :label="3">第三名</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item
v-if="itm.rewardCount == 2"
label="重复次数:"
:prop="'missionList.' + index1 + '.repeatCount'"
:rules="taskFormRules.repeatCount"
>
<el-input
:disabled="itm.repeatFlag"
v-model.trim="itm.repeatCount"
@blur="handleBlur(itm)"
type="number"
:min="1"
oninput="value=value.replace(/^0|[^0-9]/g, '')"
size="small"
></el-input>
<el-checkbox
:disabled="
itm.repeatCount != '' && itm.repeatCount != -1
"
style="margin-left: 8px"
v-model="itm.repeatFlag"
@change="
repeatChange(index, itm, itm.repeatFlag, index1)
"
>不限制</el-checkbox
>
</el-form-item>
<el-form-item
v-if="itm.rewardType == 1"
label="触发值:"
:prop="'missionList.' + index1 + '.triggerValue'"
:rules="taskFormRules.triggerValue"
>
<el-input
v-model="itm.triggerValue"
type="number"
:min="0"
oninput="value=value.replace(/^0|[^0-9]/g, '')"
size="small"
></el-input>
</el-form-item>
<el-form-item
label="奖励积分:"
:prop="'missionList.' + index1 + '.rewardScore'"
:rules="taskFormRules.rewardScore"
>
<el-input
v-model="itm.rewardScore"
size="small"
></el-input>
</el-form-item>
</div>
<div class="task-date-box-right">
<el-button
type="text"
@click="delTask(item, index, itm, index1)"
:disabled="item.timeFlag"
>删除</el-button
>
</div>
</div>
</div>
</el-form>
</div>
</el-tab-pane>
</el-tabs>
</template>
</div>
<!-- 活动弹框 -->
<ActivityDia
ref="activityDia"
:activityDiaVisible="activityDiaVisible"
@selectActivity="selectActivity"
></ActivityDia>
<div class="footer-close">
<el-button type="primary" @click="submitTask" size="small"
>提交</el-button
>
<el-button @click="cancelSubmit" size="small">取消</el-button>
</div>
</div>
</template>
<script>
import { commonApi } from '../../../api/commonApi'
import { taskApi } from '../../../api/task'
import ActivityDia from './components/activityDia.vue'
import { utils } from 'glsx-common'
export default {
components: {
ActivityDia,
},
data() {
// 奖励积分校验规则
const validateAwardIntegral = (rule, value, callback) => {
let reg = /(^[1-9]{1}[0-9]*$)|(^([0]{1}|[1-9]+)\.{1}[0-9]{1,2}$)/
if (!value) {
callback(new Error('奖励积分不能为空'))
} else if (!reg.test(value)) {
callback(new Error('仅支持输出大于或等于0的数字,可支持小数点后两位'))
} else if (value == 0) {
callback(new Error('奖励积分应大于0'))
} else if (value > 999999) {
callback(new Error('奖励积分应小于999999'))
} else {
callback()
}
}
return {
// 基础信息表单
basicForm: {
businessScene: 3,
merchantId: '',
merchantName: '',
activityId: '',
activityName: '',
crowd: ['3'],
channel: 1,
remark: '',
},
// 商户列表
merchantList: [],
// tab值(默认第一个)
activeName: '0',
repeatChecked: false,
// 子组件传来的分享素材
shareEditor: '',
// 是否是编辑
isEditor: false,
// 是否是克隆
isClone: false,
// 活动弹框
activityDiaVisible: false,
// 活动日期天数
taskDateNum: 0,
merchantLoading: false,
dayIndex: 0,
btnList: [
{
name: '表情',
funcName: '',
type: 'expression',
limitSize: 10,
},
{
name: '图片',
funcName: '',
type: 'img',
limitNum: 9,
uploadApi: commonApi.uploadImgApi,
},
{
name: '视频',
funcName: '',
type: 'video',
limitSize: 10, // 限制视频大小
// togetherItem: [ATT_TYPE.TEXT], // 只允许文本和图片
limitNum: 1, // 限制视频数量
// limitWidth: 1280, // 限制视频宽度
// limitHeight: 720, // 限制视频高度
// limitTime: 30, // 限制视频时长
uploadApi: commonApi.uploadImgApi,
},
{
name: '活动专属链接',
funcName: 'link',
type: 'link',
// uploadApi: this.$apis.common.pictureUpload
},
],
// 任务计划
taskList: [],
// 任务id
taskId: '',
// 活动开始/结束时间
startTime: '',
endTime: '',
validFlag: true,
// 活动图片
activityImage: '',
// 公共任务类型
basicObj: {
id: '',
missonType: '',
missionName: '',
missonDesc: '',
rewardScore: '',
},
// 分享指标任务类型
shareObj: {
missionMaterialList: [],
rewardType: '',
rewardCount: '',
triggerValue: '',
},
// 浏览指标任务类型
browseObj: {
rewardType: '',
rewardCount: '',
repeatCount: '',
triggerValue: '',
},
// 访客指标任务类型
visitorObj: {
rewardType: '',
triggerValue: '',
},
// 成单指标任务类型
orderObj: {
rewardType: '',
triggerValue: '',
},
// 编辑任务计划数据
taskEditList: {},
// 基础信息表单验证
basicRules: {
businessScene: [
{ required: true, message: '请选择业务场景', trigger: 'change' },
],
merchantId: [
{ required: true, message: '请选择活动商户', trigger: 'change' },
],
activityId: [
{ required: true, message: '请选择活动/产品', trigger: 'change' },
],
crowd: [
{ required: true, message: '请选择任务指定人群', trigger: 'change' },
],
channel: [
{ required: true, message: '请选择发放渠道', trigger: 'change' },
],
},
// 任务计划表单验证
taskFormRules: {
missonType: [
{ required: true, message: '请选择任务类型', trigger: 'change' },
],
missionName: [
{ required: true, message: '请输入任务名称', trigger: 'blur' },
],
missonDesc: [
{ required: true, message: '请输入任务说明', trigger: 'blur' },
],
rewardType: [
{ required: true, message: '请选择奖励模式', trigger: 'change' },
],
rewardCount: [
{ required: true, message: '请选择奖励次数', trigger: 'change' },
],
triggerValue: [
{ required: true, message: '请选择触发排名', trigger: 'change' },
],
repeatCount: [
{ required: true, message: '请输入重复次数', trigger: 'blur' },
],
triggerValue: [
{ required: true, message: '请输入触发值', trigger: 'blur' },
],
rewardScore: [
{ required: true, trigger: 'blur', validator: validateAwardIntegral },
],
attachmentList: [
{ required: true, message: '请输入入群欢迎语' },
// { validator: validatorAttachment, trigger: 'change' }
],
},
}
},
mounted() {
this.$root.eventBus.$on('params', (params) => {
// 判断是否是编辑
if (params && params.type) {
this.isEditor = true
this.findMissionDeail(params.task.id)
this.taskId = params.task.id
}
// 判断是否是复制
if (params && params.id) {
this.isClone = true
this.findMissionDeail(params.id)
}
if (this.isClone || this.isEditor) this.selectMerchant()
})
},
computed: {},
methods: {
// 点击选择活动/任务
openActivityDia() {
if (!this.basicForm.businessScene) {
this.$message({
message: '请先选择业务场景',
type: 'warning',
})
return
}
if (!this.basicForm.merchantId) {
this.$message({
message: '请先选择商户',
type: 'warning',
})
return
}
this.activityDiaVisible = true
this.$refs.activityDia.init(
this.basicForm.merchantId,
this.isClone,
this.taskDateNum
)
// this.$refs.activityDia.init(44209390)
},
// 选择商户
selectMerchant(query) {
if (!this.basicForm.businessScene) {
this.$message({
message: '请先选择业务场景',
type: 'warning',
})
return
}
this.merchantLoading = true
let params = {}
params.merchantAccountType = 4
params.merchantName = query
taskApi.findMerchantByScene(params).then((res) => {
if (res.code == 0) {
this.merchantList = res.data
}
this.merchantLoading = false
})
},
// 商户改变获取商户名
changeMerchant(val) {
this.basicForm.merchantName =
val &&
this.merchantList.find((item) => item.merchantId == val).merchantName
// 清空活动
this.basicForm.activityId = ''
this.basicForm.activityName = ''
this.taskList = []
},
// 根据商户名搜索商户
filterMethod: utils.debounce(function (val) {
this.searchValue = val
this.basicForm.merchantName = val
this.selectMerchant(val)
}, 1000),
// 选择活动
selectActivity(selectItem) {
this.basicForm.activityId = selectItem.id
this.basicForm.activityName = selectItem.activityName
this.startTime = selectItem.startTime
this.endTime = selectItem.endTime
this.activityImage = selectItem.activityImg
this.setHouseRatesColumn(selectItem.startTime, selectItem.endTime)
},
// 任务tab切换
handleClick() {},
// 任务克隆获取克隆任务计划
getCloneTaskList() {
// 处理克隆日期数据
this.taskList.map((item) => {
if (item.activityTime != -1) {
item.activityTime = ''
}
})
},
// 任务编辑处理任务计划数据
getEditTaskList() {
// 若当前时间在已选活动开始时间之后,无法在对当前时间前一天开始的日期进行任务编辑(包含添加、删除、编辑任务的操作);
let myDate = new Date()
let now = myDate.valueOf()
this.taskList.map((item, index) => {
if (this.taskList.length != index + 1) {
var dateTime = new Date(item.activityTime)
dateTime = dateTime.setDate(dateTime.getDate() + 1)
let time = new Date(dateTime).valueOf()
now >= time ? (item.timeFlag = true) : (item.timeFlag = false)
}
})
},
// 遍历日期
setHouseRatesColumn(startTime, endTime) {
this.taskList = []
startTime = new Date(startTime)
endTime = new Date(endTime)
let num = 0
while (endTime.getTime() - startTime.getTime() >= 0) {
const year = startTime.getFullYear()
const month =
startTime.getMonth() + 1 < 10
? '0' + (startTime.getMonth() + 1)
: startTime.getMonth() + 1
const day =
startTime.getDate().toString().length == 1
? '0' + startTime.getDate()
: startTime.getDate()
this.taskList.push({
activityTime: `${year}-${month}-${day}`,
missionList: [],
})
num++
startTime.setDate(startTime.getDate() + 1)
}
// 多添加一个完整周期tab
this.taskList.push({
activityTime: '-1',
missionList: [],
})
// 如果是编辑/复制页面,任务计划回显
if (this.isEditor || this.isClone) this.dealEcho()
// 如果是如果是编辑/新建页面,还需处理当前日期之前是否可编辑处理
if (!this.isClone) this.getEditTaskList()
// 如果是克隆,还需处理克隆时间
if (this.isClone && !this.basicForm.activityName) this.getCloneTaskList()
return this.taskList
},
// 处理任务计划回显
dealEcho() {
for (var i = 0; i < this.taskList.length; i++) {
for (var j = 0; j < this.taskEditList.missionDateList.length; j++) {
if (
this.taskList[i].activityTime ==
this.taskEditList.missionDateList[j].activityTime
) {
this.taskList[i].missionList =
this.taskEditList.missionDateList[j].missionList
}
}
}
},
// 根据日期获取天数
getDateByDays(startDate, endDdate) {
let d1 = Date.parse(new Date(startDate))
let d2 = Date.parse(new Date(endDdate))
// 时间戳相减 / 天数
let day = parseInt((d2 - d1) / (1000 * 60 * 60 * 24)) + 1
return day
},
// 添加任务
addTaskType(item, index) {
this.taskList[index].missionList.unshift({
...this.basicObj,
})
this.taskList[index].missionList[0].id = this.getUuid()
console.log(this.taskList[index].missionList[0])
},
// 任务选择类型切换
selectTaskType(dateTask, dateTaskIndex, task, taskIndex) {
// dateTask -- 具体哪一天的任务对象
// dateTaskIndex -- 具体哪一天的任务对象索引
// task -- 具体哪个任务
// taskIndex -- 具体任务索引
// 如果当前选择的是注册认证类型,遍历当天配置的任务类型,判断是否已经选择过了注册认证任务类型,如果是,则弹出错误(注册任务类型一天只允许添加一个)
if (task.missonType == 1) {
var typeIndex = 0
dateTask.missionList.map((taskInfo) => {
if (taskInfo.missonType == 1) {
typeIndex = typeIndex + 1
}
})
}
if (typeIndex > 1) {
this.$alert('每个时间标签下最多只能有1个该类型任务', '警告', {
confirmButtonText: '知道了',
callback: (action) => {
this.taskList[dateTaskIndex].missionList[taskIndex].missonType = ''
},
})
return
}
// 判断任务类型,将任务类型参数push进taskList
let taskItem
switch (task.missonType) {
case '1':
taskItem = { ...this.basicObj }
break
case '2':
taskItem = { ...this.basicObj, ...this.shareObj }
break
case '3':
taskItem = { ...this.basicObj, ...this.browseObj }
break
case '4':
taskItem = { ...this.basicObj, ...this.visitorObj }
break
case '5':
taskItem = { ...this.basicObj, ...this.orderObj }
break
default:
taskItem = { ...this.basicObj }
}
taskItem.missonType = task.missonType
taskItem.id = task.id
this.$set(this.taskList[dateTaskIndex].missionList, taskIndex, taskItem)
console.log(this.taskList[dateTaskIndex].missionList)
},
// 获取分享素材内容
getEditor(dateTask, dateTaskIndex, task, taskIndex) {
// dateTask -- 具体哪一天的任务对象
// dateTaskIndex -- 具体哪一天的任务对象索引
// task -- 具体哪个任务
// taskIndex -- 具体任务索引
this.$set(
this.taskList[dateTaskIndex].missionList[taskIndex],
'missionMaterialList',
this.shareEditor
)
},
shareMatrial(val) {
this.shareEditor = val
// this.getEditor()
},
// 删除任务
delTask(dateTask, dateTaskIndex, task, taskIndex) {
// dateTask -- 具体哪一天的任务对象
// dateTaskIndex -- 具体哪一天的任务对象索引
// task -- 具体哪个任务
// taskIndex -- 具体任务索引
this.taskList[dateTaskIndex].missionList.splice(taskIndex, 1)
this.$refs['taskForm'][dateTaskIndex].clearValidate()
},
handleBlur(dateTask) {
if (dateTask.repeatCount) {
dateTask.repeatFlag = false
}
},
// 重复次数选择框改变
repeatChange(listindex, dateTask, type, taskIndex) {
// dateTask.repeatFlag = !dateTask.repeatFlag
// this.$nextTick(() => {
if (type) {
// dateTask.repeatCount = -1
// 去除校验
this.$refs['taskForm'][listindex].fields.map((i) => {
if (i.prop === 'missionList.' + taskIndex + '.repeatCount') {
i.clearValidate()
}
})
} else {
// this.$nextTick(() => {
// dateTask.repeatCount = ''
// dateTask.repeatFlag = false
// })
this.$nextTick(() => {
dateTask.repeatCount = ''
this.$set(dateTask, 'repeatFlag', false)
})
}
// })
// // dateTask -- 具体哪一天的任务对象
// // dateTaskIndex -- 具体哪一天的任务对象索引
// // task -- 具体哪个任务
// // taskIndex -- 具体任务索引
// if (task.repeatCount) {
// // this.taskList[dateTaskIndex].missionList[taskIndex].repeatCount = ''
// this.$set(
// this.taskList[dateTaskIndex].missionList[taskIndex],
// 'repeatCount',
// ''
// )
// } else {
// // this.taskList[dateTaskIndex].missionList[taskIndex].repeatCount = -1
// this.$set(
// this.taskList[dateTaskIndex].missionList[taskIndex],
// 'repeatCount',
// -1
// )
// }
},
// 获取任务信息详情
findMissionDeail(taskId) {
var params = { id: taskId }
taskApi.findMissionDeail(params).then((res) => {
if (res && res.code == 0) {
const {
activityId,
activityName,
businessScene,
channel,
crowd,
remark,
merchantId,
merchantName,
startTime,
endTime,
} = res.data
this.basicForm.activityId = this.isEditor ? activityId : ''
this.basicForm.activityName = this.isEditor ? activityName : ''
this.basicForm.businessScene = businessScene
this.basicForm.channel = channel
this.basicForm.crowd = crowd.split(',')
this.basicForm.remark = remark
this.basicForm.merchantId = merchantId
this.basicForm.merchantName = merchantName
this.startTime = startTime
this.endTime = endTime
this.taskEditList = res.data
// 处理空素材数据
this.taskEditList.missionDateList.map((item) => {
item.missionList.map((itm) => {
if (!itm.missionMaterialList) {
delete itm.missionMaterialList
}
if (itm.repeatCount && itm.repeatCount == -1) {
this.$set(itm, 'repeatFlag', true)
itm.repeatCount = ''
}
})
})
// this.taskList = res.data.missionDateList
this.setHouseRatesColumn(startTime, endTime)
if (this.isClone) {
this.taskDateNum = this.getDateByDays(startTime, endTime)
}
}
})
},
// 奖励模式切换
rewardTypeChange(itm) {
console.log(itm)
if (itm.rewardType == 2) {
this.$nextTick(() => {
this.$set(itm, 'triggerValue', '')
this.$set(itm, 'rewardCount', '')
// itm.triggerValue = ''
})
} else {
this.$nextTick(() => {
this.$set(itm, 'rewardCount', 1)
// itm.rewardCount = ''
})
}
},
// 奖励次数切换
rewardCountChange(itm) {
if (itm.rewardCount == 2) {
this.$nextTick(() => {
this.$set(itm, 'repeatCount', '')
this.$set(itm, 'triggerValue', '')
// itm.repeatCount = ''
// itm.triggerValue = ''
})
} else {
this.$nextTick(() => {
this.$set(itm, 'triggerValue', '')
// itm.triggerValue = ''
})
}
},
// 基础信息表单验证
basicFormValidate() {
this.$refs['basicForm'].validate((valid) => {
if (!valid) {
// return all
throw '必须选定一个值'
}
})
},
// 任务计划表单验证
taskFormValidate() {
// var validFlag = 0
// var dayIndex = 0
this.taskList.map((item, index) => {
this.$refs['taskForm'][index].validate((valid) => {
console.log(valid)
// if (!valid) validFlag = validFlag + 1
if (!valid) {
console.log(111)
this.validFlag = false
this.dayIndex = index
return
}
})
// 检测到未填写跳转到未填写页面
})
// if (validFlag > 0) {
// return [validFlag, dayIndex]
// }
},
// 任务计划是否为空验证
taskFormEmptyValidate() {
let taskItemFlag = 0
this.taskList.map((item) => {
if (item.missionList.length) taskItemFlag = taskItemFlag + 1
})
if (taskItemFlag == 0) {
this.$message({
message: '请至少填写一条任务计划',
type: 'error',
})
return false
}
},
// 提交任务
submitTask() {
// 遍历重复次数
this.taskList.map((item) => {
item.missionList.map((itm) => {
// itm.repeatCount = itm.repeatCount ? itm.repeatCount : -1
if (itm.repeatCount || itm.repeatFlag) {
itm.repeatCount = itm.repeatCount ? itm.repeatCount : -1
}
delete itm.id
})
})
try {
this.basicFormValidate()
} catch (err) {
if (err) return
}
this.taskFormValidate()
if (!this.validFlag) {
this.$alert('第' + (this.dayIndex + 1) + '天填写未完成', '警告', {
confirmButtonText: '知道了',
callback: (action) => {
this.validFlag = true
this.activeName = this.dayIndex + ''
},
})
return
}
this.taskFormEmptyValidate()
let params = JSON.parse(JSON.stringify(this.basicForm))
params.startTime = this.startTime
params.endTime = this.endTime
params.activityImage = this.activityImage
params.crowd = params.crowd.join(',')
// 删除判断是否可编辑的日期标识
if (this.isEditor) {
this.taskList.map((item) => {
delete item.timeFlag
})
}
params.missionDateList = this.taskList
params.id = this.taskId
// 创建
if (!this.isEditor) {
taskApi.creatMission(params).then((res) => {
if (res && res.code == 0) {
this.$root.to([
'任务中心',
'任务平台',
'任务管理',
'任务模板管理',
'任务管理列表',
])
this.$root.close('*添加任务模板')
} else {
this.$message({
message: res.message,
type: 'error',
})
}
})
return
}
// 编辑
taskApi.updateMission(params).then((res) => {
if (res && res.code == 0) {
this.$root.to([
'任务中心',
'任务平台',
'任务管理',
'任务模板管理',
'任务管理列表',
])
this.$root.close('*添加任务模板')
} else {
this.$message({
message: res.message,
type: 'error',
})
}
})
},
// 取消s
cancelSubmit() {
;(this.basicForm = {
businessScene: 3,
merchantId: '',
merchantName: '',
activityId: '',
activityName: '',
crowd: ['3'],
channel: 1,
remark: '',
}),
this.$root.to([
'任务中心',
'任务平台',
'任务管理',
'任务模板管理',
'任务管理列表',
])
this.$root.close('*添加任务模板')
},
// 生成唯一uuid
getUuid() {
if (typeof crypto === 'object') {
if (typeof crypto.randomUUID === 'function') {
return crypto.randomUUID()
}
if (
typeof crypto.getRandomValues === 'function' &&
typeof Uint8Array === 'function'
) {
const callback = (c) => {
const num = Number(c)
return (
num ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (num / 4)))
).toString(16)
}
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(
/[018]/g,
callback
)
}
}
let timestamp = new Date().getTime()
let perforNow =
(typeof performance !== 'undefined' &&
performance.now &&
performance.now() * 1000) ||
0
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
let random = Math.random() * 16
if (timestamp > 0) {
random = (timestamp + random) % 16 | 0
timestamp = Math.floor(timestamp / 16)
} else {
random = (perforNow + random) % 16 | 0
perforNow = Math.floor(perforNow / 16)
}
return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
})
},
},
}
</script>
<style lang="scss" scoped>
.task-box {
padding: 0 20px 20px 0;
.task-content {
margin-bottom: 120px;
}
}
.task-title {
padding: 20px;
font-size: 16px;
font-weight: 600;
color: rgb(51, 51, 51);
line-height: 16px;
border-bottom: 1px solid rgb(216, 216, 216);
margin-bottom: 20px;
}
.task-date-box {
display: flex;
width: 100%;
padding: 20px 0;
margin: 20px 0;
border: 1px solid #ccc;
&-left {
width: 80%;
}
&-right {
width: 20%;
position: relative;
.el-button {
color: red;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
}
.el-select,
.el-input,
.el-textarea {
width: 475px;
}
.el-form-item {
margin-bottom: 15px;
}
.footer-close {
text-align: center;
width: 100%;
background-color: #fff;
position: fixed;
bottom: 0;
left: 0;
height: 64px;
line-height: 64px;
}
.el-alert {
margin-top: 10px;
}
</style>