performanceScheme.vue
38.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
<!-- 绩效方案 -->
<template>
<d2-container class="performanceScheme" v-loading="$store.state.d2admin.loading.value">
<el-form :model="formData" label-width="280px" class="form" ref="form" :rules="rules">
<div class="warp_box">
<div class="title space-b">
<div class="title-wrap">
<div class="line"></div>
<span>渠道配置</span>
</div>
<div class="merchant-text">当前配置门店:{{ `${routerQuery.merchantName}${routerQuery.merchantId}` }}</div>
</div>
<div class="warp_content">
<el-form-item label="适用招聘类型:" prop="hireType">
<el-radio-group v-model="tempHireType" @change="changePerformance($event, 'hireType', 'tempHireType')">
<el-radio-button size="small" :label="1">校招管培生</el-radio-button>
<el-radio-button size="small" :label="2">社会招聘</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="所属业务:" prop="sceneType">
<el-radio-group v-model="tempSceneType" @change="changePerformance($event, 'sceneType', 'tempSceneType')" aria-hidden="false">
<el-radio :label="1">轻改</el-radio>
<el-radio :label="0">会员权益/升级</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="方案类型:" prop="configType">
<el-radio-group v-model="tempConfigType" @change="changePerformance($event, 'configType', 'tempConfigType')" v-if="formData.hireType == 2 && formData.sceneType == 0" aria-hidden="false">
<el-radio :label="1">按月度产值要求拿提成</el-radio>
<el-radio :label="3">权益延保按渗透率拿提成</el-radio>
</el-radio-group>
<el-radio-group v-model="tempConfigType" v-if="formData.hireType == 2 && formData.sceneType == 1" aria-hidden="false">
<el-radio :label="1">按月度产值要求拿提成</el-radio>
</el-radio-group>
<el-radio-group v-model="tempConfigType" v-if="formData.hireType == 1" aria-hidden="false">
<el-radio :label="2">按渗透率拿提成</el-radio>
</el-radio-group>
</el-form-item>
</div>
</div>
<div class="warp_box" v-if="formData.hireType && isShow">
<div class="title">
<div class="line"></div>
<span>绩效配置</span>
<el-button style="margin-left: 20px;" size="small" type="primary" plain @click="clearConfig">清空配置并提交</el-button>
</div>
<el-form-item label="当前方案名称:" prop="schemeName" class="schemeName" label-width="120px">
<el-input v-model="formData.schemeName" style="width: 432px;" placeholder="请输入方案名称" maxlength="20"></el-input>
</el-form-item>
<div class="warp_content">
<!-- 校招 -->
<template v-if="formData.configType == 2">
<campus ref="configForm" :configInfo="formData.configInfo"></campus>
</template>
<!-- 社招轻改 -->
<template v-if="formData.configType == 1">
<el-tabs type="card" v-model="defaultActiveName">
<el-tab-pane v-for="(subItem, subIndex) in jobLevelData" :key="subItem.jobType" :name="subItem.jobType">
<span slot="label"><i v-if="subItem.validateErrFlag" class="el-icon-warning car-error-txt"></i>{{ subItem.jobTypeName }}</span>
<el-button class="copy_btn" type="primary" size="small" plain @click="copyConfig(subIndex)">复制该配置到{{ defaultActiveName == 4 ? '初级驻店' : jobTypeList[Number(defaultActiveName) + 1] }}</el-button>
<social :ref="`perConfigForm_${subItem.jobType}`" :key="subItem.jobType" :goods-type-list="goodsTypeList" :jobType="subItem.jobType" :per-config-info="subItem.configInfo"></social>
</el-tab-pane>
</el-tabs>
</template>
<!-- 社招会员权益按渗透率 -->
<template v-if="formData.configType == 3">
<el-tabs v-model="carTypeDefaultActiveName">
<el-tab-pane v-for="subItem in carTypeData" :key="subItem.carType" :name="subItem.carType">
<span slot="label"><i v-if="subItem.validateErrFlag" class="el-icon-warning car-error-txt"></i>{{ subItem.carTypeName }}</span>
<warranty-penetration :goods-type-list="goodsTypeList" @resetRadio="resetRadio" :ref="`warrantyForm_${subItem.carType}`" :job-level-data="subItem.performanceInfo"></warranty-penetration>
</el-tab-pane>
</el-tabs>
</template>
</div>
</div>
</el-form>
<div class="footer_box">
<el-button
type="primary"
@click="handleConfirm"
:disabled="$store.state.d2admin.loading.value">提交</el-button>
<el-button class="cancel-btn"
@click="handleClose">取消</el-button>
</div>
</d2-container>
</template>
<script>
import campus from './components/campus.vue'
import social from './components/social.vue'
import warrantyPenetration from './components/warrantyPenetration.vue'
import { configPerformancePlanApi, getPerformancePlanDetailApi, getStoreLastDetailApi, deleteStoreSalaryApi } from '@api/resident'
import { deepClone } from '@/common/util'
import { getAllCategory } from '@api/product'
import { baseConfig } from '@/main'
export default {
name: 'PerformanceScheme',
components: {
campus,
social,
warrantyPenetration
},
data() {
return {
addOrEdit: '',
formData: {},
copyFormData: {
hireType: '',
sceneType: '',
configType: '',
schemeName: '',
configInfo: {
campusList: []
}
},
tempHireType: '',
tempSceneType: '',
tempConfigType: '',
rules: {
hireType: [
{ required: true, message: '请选择适用招聘类型', trigger: 'change' }
],
sceneType: [
{ required: true, message: '请选择所属业务', trigger: 'blur' }
],
configType: [
{ required: true, message: '请选择方案类型', trigger: 'blur' }
]
},
jobLevelData: [],
copyJobLevelData: [
{
jobType: '2',
jobTypeName: '初级驻店',
configInfo: {}
},
{
jobType: '3',
jobTypeName: '中级驻店',
configInfo: {}
},
{
jobType: '4',
jobTypeName: '高级驻店',
configInfo: {}
}
],
jobTypeList: {
2: '初级驻店',
3: '中级驻店',
4: '高级驻店'
},
carTypeData: [],
configItems: ['outputBonus', 'upgradeRateBonus'],
defaultActiveName: '2', // 默认选中初级驻店
carDefaultActive: 'all',
routerQuery: {},
carTypeDefaultActiveName: '',
goodsTypeList: [],
selfBuildGoodsType: baseConfig.selfBuildGoodsType || '' // 服务商自建类目值
}
},
beforeRouteEnter(to, from, next) {
if (to.query.addOrEdit == 'edit') {
to.meta.title = '编辑绩效方案'
} else {
to.meta.title = '新增绩效方案'
}
next()
},
mounted() {
let params = this.$route.query?.params && JSON.parse(this.$route.query?.params)
this.addOrEdit = this.$route.query?.addOrEdit
this.routerQuery = params
// 获取车型
this.getCarType()
},
methods: {
getCarType() {
let performanceInfo = [{
jobType: '2',
jobTypeName: '初级驻店',
configInfo: {
campusList: [],
customerList: []
}
},
{
jobType: '3',
jobTypeName: '中级驻店',
configInfo: {
campusList: [],
customerList: []
}
},
{
jobType: '4',
jobTypeName: '高级驻店',
configInfo: {
campusList: [],
customerList: []
}
}]
let brandIds = this.routerQuery?.brandIds || []
brandIds = brandIds?.filter(v => v != this.baseConfig.brandId) // 去除鸿蒙智行主品牌
const hasMultipleBrands = brandIds.length > 1
const hasSpecificBrand = brandIds.includes(this.baseConfig.childrenBrandId) // 是否包含问界子品牌
this.copyCarTypeData = hasMultipleBrands
? [
...(hasSpecificBrand ? [
{ carType: '1', carTypeName: '单问界', performanceInfo }
] : []),
{ carType: '2', carTypeName: '其他车系', performanceInfo }
]
: (brandIds.length === 1
? (hasSpecificBrand ? [{ carType: '1', carTypeName: '单问界', performanceInfo }]
: [{ carType: '2', carTypeName: '其他车系', performanceInfo }])
: [])
// this.copyCarTypeData = [{
// carType: '1',
// carTypeName: '单问界',
// performanceInfo
// }, {
// carType: '2',
// carTypeName: '其他车系',
// performanceInfo
// }]
this.carTypeDefaultActiveName = this.copyCarTypeData[0]?.carType
// 获取三级类目数据
getAllCategory({ categoryTypeList: this.selfBuildGoodsType, pageSize: 9999, currentPage: 1 }).then(res => {
this.goodsTypeList = res?.list || []
// 获取最新配置的绩效数据
this.getLastConfig()
})
},
getLastConfig() {
this.jobLevelData = deepClone(this.copyJobLevelData)
this.carTypeData = deepClone(this.copyCarTypeData)
getStoreLastDetailApi({ merchantId: this.routerQuery.merchantId }).then(res => {
let params = {
merchantId: this.routerQuery.merchantId,
hireType: !this.routerQuery.hireType ? 2 : this.routerQuery.hireType, // 若该门店无配置任何内容,默认选中社会招聘
sceneType: !this.routerQuery.sceneType ? 0 : this.routerQuery.sceneType, // 若无配置内容,默认选中会员权益
configType: 3 // 若无配置默认选中按延保渗透率
}
if (!res?.length) this.getDetail(params)
let obj = this.splitArrayByProperty(res, 'configType') // 根据绩效方案类型分组
let data = {}
const priorityKeys = ['3', '1', '2'] // 定义优先级顺序 3延保渗透率 1社招轻改 2校招渗透率
for (const key of priorityKeys) {
if (obj[key]?.length) {
// 如果度大于1,取会员权益场景作为默认选中
data = obj[key].length > 1
? obj[key].find(item => item.sceneType === 0) || obj[key][0]
: obj[key][0]
break
}
}
this.setDetailInfo(data)
})
},
splitArrayByProperty(arr, property) {
return arr.reduce((acc, obj) => {
const key = obj[property]
if (!acc[key]) {
acc[key] = []
}
acc[key].push(obj)
return acc
}, {})
},
// 个人均产值根据区间值相同合并数据
mergeArrayObjects(arr) {
const merged = []
arr.forEach(item => {
const { startValue, endValue, calculateValue, oldstartValue, oldendValue, oldcalculateValue, ...rest } = item
const { goodsType, secondaryGoodsType, thirdLevelGoodsType } = rest || {}
rest.productType = [goodsType, secondaryGoodsType, thirdLevelGoodsType].filter(item => item != -1 && Boolean(item))
rest.productTypeFocus = false
const found = merged.find(m => m.startValue === startValue && m.endValue === endValue)
if (found) {
// 直接将其他属性对象推入others数组
found.others.push(rest)
found.productConfig.push({ calculateValue: calculateValue, oldcalculateValue: oldcalculateValue })
} else {
// 创建新对象并初始化
merged.push({
startValue,
endValue,
oldstartValue,
oldendValue,
productConfig: [{ calculateValue: calculateValue, oldcalculateValue: oldcalculateValue }],
others: [rest] // 初始化为包含当前对象的其他属性的数组
})
}
})
return merged
},
setDetailInfo(res, params) {
['hireType', 'sceneType', 'configType'].forEach(key => this.updateData(key, res, params))
this.formData = res || deepClone(this.copyFormData)
if (res?.configType == 2) { // 校招
res?.configItemList?.forEach(val => {
val['oldstartValue'] = val.startValue
val['oldendValue'] = val.endValue
val['oldcalculateValue'] = val.calculateValue
val['oldgrCommissionRatio'] = val.grCommissionRatio
val['olddsCommissionRatio'] = val.dsCommissionRatio
val['oldddCommissionRatio'] = val.ddCommissionRatio
val['oldjlcCommissionRatio'] = val.jlcCommissionRatio
})
this.formData.configInfo = {
campusList: res?.configItemList || []
}
} else if (res?.configType == 1) { // 社招轻改
res?.configItemList?.forEach(item => {
item['oldstartValue'] = item.startValue
item['oldendValue'] = item.endValue
item['oldcalculateValue'] = item.calculateValue
this.jobLevelData?.forEach(v => {
for (let item of this.configItems) {
if (!v.configInfo?.[item + 'List']) v.configInfo[item + 'List'] = []
}
if (v.jobType == item.jobType) {
const performanceTypeMap = {
'2': 'outputBonusList',
'4': 'upgradeRateBonusList'
}
const targetList = performanceTypeMap[`${item.performanceType}`]
if (targetList) {
if (item.performanceType == 2) {
v.configInfo[targetList].push({ ...item, productConfig: [] })
}
else v.configInfo[targetList].push(item)
}
}
})
})
// 处理个人均产值数据
this.jobLevelData?.forEach(v => {
v.configInfo['outputBonusList'] = this.mergeArrayObjects(v.configInfo['outputBonusList'])
v.configInfo['productConfigList'] = (v.configInfo['outputBonusList'][0]?.others) || []
})
} else { // 社招渗透率
res?.configItemList?.forEach(item => {
item['oldstartValue'] = item.startValue
item['oldendValue'] = item.endValue
item['oldoutputCommissionRatio'] = item.outputCommissionRatio
item['oldcalculateValue'] = item.calculateValue
item['oldconditionStartValue'] = item.conditionStartValue
item['oldconditionEndValue'] = item.conditionEndValue
if (item.conditionGoodsType || item.conditionSecondaryGoodsType || item.conditionThirdLevelGoodsType) item.conditionFlag = true
item.selectProductType = this.pushBasedOnPriority(item.goodsType, item.secondaryGoodsType, item.thirdLevelGoodsType)
const { goodsType, secondaryGoodsType, thirdLevelGoodsType } = item || {}
const { conditionGoodsType, conditionSecondaryGoodsType, conditionThirdLevelGoodsType } = item || {}
item.productType = [goodsType, secondaryGoodsType, thirdLevelGoodsType].filter(item => item != -1 && Boolean(item))
item.conditionProductType = [conditionGoodsType, conditionSecondaryGoodsType, conditionThirdLevelGoodsType].filter(item => item != -1 && Boolean(item))
this.carTypeData?.forEach(val => {
if (item.configCarType == val.carType) {
val.performanceInfo?.forEach(v => {
if (v.jobType == item.jobType) {
if (item.performanceType != 5) {
v.configInfo.campusList.push(item)
} else {
v.configInfo.customerList.push(item)
}
}
})
}
})
})
}
if (res?.schemeName) {
this.$set(this.formData, 'schemeName', res.schemeName)
} else {
this.$set(this.formData, 'schemeName', this.formData.configType == 1 ? '按月度产值要求拿提成' : this.formData.configType == 2 ? '按渗透率拿提成' : '权益延保按渗透率拿提成',)
}
// 保留社招产值原始配置数据
this.socialConfigItemList = this.setData(this.jobLevelData, 'social')
// 保留社招渗透率原始配置数据
this.warrantyConfigItemList = this.setData(this.carTypeData, 'warranty')
this.isShow = true
},
pushBasedOnPriority(a, b, c) {
let result = ''
if (!this.isEmpty(c)) {
result = c
} else if (!this.isEmpty(b)) {
result = b
} else if (!this.isEmpty(a)) {
result = a
}
return result
},
// 获取详情
getDetail(params) {
this.isShow = false
this.jobLevelData = deepClone(this.copyJobLevelData)
this.carTypeData = deepClone(this.copyCarTypeData)
getPerformancePlanDetailApi(params).then(res => {
this.setDetailInfo(res, params)
})
},
updateData(key, res, params) {
if (!res) this[`temp${key.charAt(0).toUpperCase() + key.slice(1)}`] = params[key]
const value = res?.[key]
if (!this.isEmpty(value)) {
this[`temp${key.charAt(0).toUpperCase() + key.slice(1)}`] = value
this.$set(this.copyFormData, key, value)
} else {
this.$set(this.copyFormData, key, this[`temp${key.charAt(0).toUpperCase() + key.slice(1)}`])
}
},
isEmpty(data) {
return (data ?? '') === ''
},
compareArrays(arr1, arr2, keys) {
const getValues = (arr, keys) => {
return arr.map(obj => keys.map(key => obj[key]))
}
const values1 = getValues(arr1, keys)
const values2 = getValues(arr2, keys)
if (values1.length !== values2.length) {
return true // 长度不同,认为有变化
}
return values1.some((valueArray, index) => {
return valueArray.some((value, i) => {
const valueToCompare = values2[index][i];
// 处理空字符串与 null/undefined 的比较
if ((value == "" && (valueToCompare == null || valueToCompare == undefined)) ||
(valueToCompare == "" && (value == null || value == undefined))) {
return false
}
return value != valueToCompare
})
})
},
async changePerformance(value, key, oldkey) {
// 获取绩效配置数据
let [result, changeFlag, configItemList] = [null, false, []]
if (this.formData['hireType'] == 1) { // 校招
result = await this.$refs['configForm'].getFormData()
configItemList = this.setData(result, 'campus')
let fields = ['jobType', 'startValue', 'endValue', 'calculateValue', 'grCommissionRatio', 'grCommissionRatio', 'ddCommissionRatio', 'jlcCommissionRatio']
changeFlag = this.compareArrays(configItemList, this.formData.configInfo?.campusList, fields)
} else if (this.formData['hireType'] == 2) { // 社招
if (this.formData['configType'] == 1) { // 按月度产值要求拿提成
for (var j = 0; j < this.jobLevelData?.length; j++) {
const subVal = this.jobLevelData[j]
const node = this.$refs[`perConfigForm_${subVal.jobType}`] && this.$refs[`perConfigForm_${subVal.jobType}`][0]
if (node?.getFormData) {
result = await node.getFormData()
this.$set(this.jobLevelData[j], 'configInfo', result)
}
}
configItemList = this.setData(this.jobLevelData, 'social')
let fields = ['jobType', 'performanceType', 'startValue', 'endValue', 'calculateValue', 'goodsType', 'secondaryGoodsType', 'thirdLevelGoodsType']
changeFlag = this.compareArrays(configItemList, this.socialConfigItemList, fields)
} else { // 按延保权益渗透率
for (var j = 0; j < this.carTypeData?.length; j++) {
const subVal = this.carTypeData[j]
const node = this.$refs[`warrantyForm_${subVal.carType}`] && this.$refs[`warrantyForm_${subVal.carType}`][0]
if (node?.getFormData) {
result = await node.getFormData()
this.$set(this.carTypeData[j], 'performanceInfo', result)
}
}
configItemList = this.setData(this.carTypeData, 'warranty')
let fields = ['configCarType', 'performanceType', 'goodsType', 'secondaryGoodsType', 'thirdLevelGoodsType', 'startValue', 'endValue', 'outputCommissionRatio', 'calculateValue', 'conditionGoodsType', 'conditionSecondaryGoodsType', 'conditionThirdLevelGoodsType', 'conditionStartValue', 'conditionEndValue']
changeFlag = this.compareArrays(configItemList, this.warrantyConfigItemList, fields)
}
}
if (changeFlag) {
try {
await this.$confirm(
'请保存当前绩效配置',
'提示',
{
confirmButtonText: '保存',
type: 'warning',
}
)
this.handleConfirm(value, key, oldkey)
} catch {
this.resetRadio(key, oldkey)
}
} else {
this.setRadio(value, key, oldkey)
}
},
// 修改radio的值
setRadio(value, key, oldkey) {
this.formData[key] = value
this[oldkey] = value
// configType 1:按月度产值要求拿提成,2:按渗透率拿提成,3:权益延保按渗透率拿提成
if (this.formData.hireType == 1) { // 切换到校招默认按渗透率拿提成
this.formData.configType = 2
this.tempConfigType = 2
this.formData.carType = []
}
if (this.formData.hireType == 2 && this.formData.sceneType == 0 && (key != 'configType' && value != 1)) { // 切换到社招会员权益默认选中按渗透率拿提成
this.formData.configType = 3
this.tempConfigType = 3
}
if (this.formData.hireType == 2 && this.formData.sceneType == 1) { // 切换到社招轻改默认选中按月度产值要求拿提成
this.formData.configType = 1
this.tempConfigType = 1
this.formData.carType = []
}
let params = this.getParams()
this.getDetail(params)
},
// 重置radio值
resetRadio(key, oldkey) {
this.$nextTick(() => {
this[oldkey] = this.formData[key]
})
},
getParams() {
return {
merchantId: this.routerQuery.merchantId,
sceneType: this.formData.sceneType,
hireType: this.formData.hireType,
configType: this.formData.configType
}
},
// 处理数据
setData(res, type) {
if (type == 'campus') { // 校招
return res?.campusList.map(v => ({
jobType: v.jobType,
performanceType: 1, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
startValue: v.startValue,
endValue: v.endValue,
calculateValue: v.calculateValue,
grCommissionRatio: v.grCommissionRatio,
dsCommissionRatio: v.dsCommissionRatio,
ddCommissionRatio: v.ddCommissionRatio,
jlcCommissionRatio: v.jlcCommissionRatio
}))
} else if (type == 'social') { // 社招
let configItemList = []
res?.forEach(item => {
const addConfigItems = (items, performanceType) => {
items?.forEach(v => {
// 组合选择产品数据
if (performanceType == 2) {
item?.configInfo?.productConfigList?.forEach((val, index) => {
configItemList.push({
jobType: item.jobType,
performanceType: performanceType,
startValue: v.startValue,
endValue: v.endValue,
calculateValue: v?.productConfig[index]?.calculateValue,
goodsType: val.goodsType,
goodsTypeName: val.goodsTypeName,
secondaryGoodsType: val.secondaryGoodsType,
secondaryGoodsTypeName: val.secondaryGoodsTypeName,
thirdLevelGoodsType: val.thirdLevelGoodsType,
thirdLevelGoodsTypeName: val.thirdLevelGoodsTypeName,
})
})
} else {
configItemList.push({
jobType: item.jobType,
performanceType: performanceType, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
startValue: v.startValue,
endValue: v.endValue,
calculateValue: v.calculateValue
})
}
})
}
addConfigItems(item.configInfo?.outputBonusList, 2)
addConfigItems(item.configInfo?.upgradeRateBonusList, 4)
})
return configItemList
} else {
let configItemList = []
// 先处理渗透率
res?.forEach(item => {
item?.performanceInfo?.forEach(it => {
it?.configInfo?.campusList?.forEach(v => {
const conditionFields = v.conditionFlag ? {
conditionGoodsType: v.conditionGoodsType,
conditionGoodsTypeName: v.conditionGoodsTypeName,
conditionSecondaryGoodsType: v.conditionSecondaryGoodsType,
conditionSecondaryGoodsTypeName: v.conditionSecondaryGoodsTypeName,
conditionThirdLevelGoodsType: v.conditionThirdLevelGoodsType,
conditionThirdLevelGoodsTypeName: v.conditionThirdLevelGoodsTypeName,
conditionStartValue: v.conditionStartValue,
conditionEndValue: v.conditionEndValue
} : {
conditionGoodsType: '',
conditionGoodsTypeName: '',
conditionSecondaryGoodsType: '',
conditionSecondaryGoodsTypeName: '',
conditionThirdLevelGoodsType: '',
conditionThirdLevelGoodsTypeName: '',
conditionStartValue: '',
conditionEndValue: ''
}
configItemList.push({
jobType: it.jobType,
configCarType: item.carType,
performanceType: 1, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
goodsType: v.goodsType,
goodsTypeName: v.goodsTypeName,
secondaryGoodsType: v.secondaryGoodsType,
secondaryGoodsTypeName: v.secondaryGoodsTypeName,
thirdLevelGoodsType: v.thirdLevelGoodsType,
thirdLevelGoodsTypeName: v.thirdLevelGoodsTypeName,
startValue: v.startValue,
endValue: v.endValue,
outputCommissionRatio: v.outputCommissionRatio,
calculateValue: v.calculateValue,
...conditionFields
})
})
})
})
// 再处理售后(为保证与后端数据顺序相同)
res?.forEach(item => {
item?.performanceInfo?.forEach(it => {
it?.configInfo?.customerList?.forEach(v => {
configItemList.push({
jobType: it.jobType,
configCarType: item.carType,
goodsType: v.goodsType,
goodsTypeName: v.goodsTypeName,
secondaryGoodsType: v.secondaryGoodsType,
secondaryGoodsTypeName: v.secondaryGoodsTypeName,
thirdLevelGoodsType: v.thirdLevelGoodsType,
thirdLevelGoodsTypeName: v.thirdLevelGoodsTypeName,
performanceType: 5, // 绩效类型(1:渗透率,2:高产值,3:成交率,4:均客单,5:售后提成)
startValue: v.startValue,
endValue: v.endValue,
calculateValue: v.calculateValue
})
})
})
})
// 按职级进行排序(两个车型配置时后端数据是按职级排序返回的)
configItemList.sort((a, b) => a.jobType - b.jobType)
return configItemList
}
},
// 社招轻改复制方案到别的职级
async copyConfig(subIndex) {
const subVal = this.jobLevelData[subIndex]
const node = this.$refs[`perConfigForm_${subVal.jobType}`] && this.$refs[`perConfigForm_${subVal.jobType}`][0]
if (node?.getFormData) {
let result = await node.getFormData()
if (!result?.outputBonusList?.length && !result?.upgradeRateBonusList?.length) return this.$message.warning('请先配置当前职级绩效方案')
let _index = this.jobLevelData?.findIndex(item => item.jobType == this.defaultActiveName)
this.$confirm('是否确认复制当前配置', '提示', {
confirmButtonText: '确定',
type: 'warning'
}).then(() => {
if (this.defaultActiveName == 4) {
const updatedConfigInfo = {
...this.jobLevelData[0].configInfo,
outputBonusList: deepClone(result?.outputBonusList),
upgradeRateBonusList: deepClone(result?.upgradeRateBonusList),
productConfigList: deepClone(result?.productConfigList) || []
}
this.jobLevelData[0].configInfo = updatedConfigInfo
this.$refs[`perConfigForm_${'2'}`]?.[0]?.$refs['editFormRef']?.$refs['editChildRef']?.clearValidate()
} else {
const updatedConfigInfo = {
...this.jobLevelData[_index + 1].configInfo,
outputBonusList: deepClone(result?.outputBonusList),
upgradeRateBonusList: deepClone(result?.upgradeRateBonusList),
productConfigList: deepClone(result?.productConfigList) || []
}
this.jobLevelData[_index + 1].configInfo = updatedConfigInfo
this.$refs[`perConfigForm_${`${Number(subVal.jobType) + 1}`}`]?.[0]?.$refs['editFormRef']?.$refs['editChildRef']?.clearValidate()
}
}).catch(() => {
})
}
},
// 清空配置相当于删除当前的绩效方案
clearConfig() {
this.$confirm('是否确定清空当前绩效配置方案,清空后无法回退。', '提示', {
confirmButtonText: '确定',
type: 'warning',
}).then(() => {
let params = this.getParams()
// 有id后端已保存配置,调接口删除
if (this.formData.id) {
deleteStoreSalaryApi({id: this.formData.id}).then(res => {
// this.getDetail(params)
// 返回到列表页
this.$router.go(-1)
})
} else {
// 获取当前绩效配置,清空数据
// this.getDetail(params)
// 返回到列表页
this.$router.go(-1)
}
}).catch(() => {
})
},
handleConfirm(value, key, oldkey) {
this.$refs['form'].validate(async (valid) => {
if (valid) {
Promise.all([this.checkPerConfig(key, oldkey)]).then((res) => {
let configItemList = []
// 社会招聘
if (this.formData.configType == 1) { // 社招按产值
const isArrayEmpty = res[0]?.every(item => !item.configInfo?.outputBonusList?.length || !item.configInfo?.productConfigList?.length)
if (isArrayEmpty) {
this.resetRadio(key, oldkey)
return this.$message.warning('请至少配置一个职级的个人月均产值提成')
}
configItemList = this.setData(res[0], 'social')
} else if (this.formData.configType == 2) { // 校招
configItemList = this.setData(res[0], 'campus')
} else { // 社招按渗透率
let arr = []
this.carTypeData?.forEach(item => {
item.performanceInfo?.forEach(item2 => {
if (item2?.configInfo?.campusList?.length || item2?.configInfo?.customerList?.length) arr.push(item2)
})
})
if (!arr.length) {
this.resetRadio(key, oldkey)
return this.$message.warning('至少配置一个职级的绩效数据')
}
configItemList = this.setData(res[0], 'warranty')
}
let params = {
id: this.addOrEdit == 'edit' ? this.formData.id : '',
merchantId: this.routerQuery.merchantId,
hireType: this.formData.hireType,
sceneType: this.formData.sceneType,
configType: this.formData.configType,
schemeName: this.formData.schemeName ? this.formData.schemeName :
this.formData.configType == 1 ? '按月度产值要求拿提成' : this.formData.configType == 2 ? '按渗透率拿提成' : '权益延保按渗透率拿提成',
configItemList
}
configPerformancePlanApi(params).then(res => {
this.notice.okTips()
if (oldkey) {
return this.setRadio(value, key, oldkey)
}
this.$router.go(-1)
}).catch(err => {
this.resetRadio(key, oldkey)
})
})
} else {
this.$nextTick(() => {
this[oldkey] = this.formData[key]
})
}
})
},
// 校验绩效方案配置
checkPerConfig(key, oldkey) {
return new Promise(async (resolve, reject) => {
let valideRes
if (this.formData.configType == 2) { // 校招
valideRes = await this.$refs['configForm'].validateCustomForm()
if (valideRes == 'error') {
this.resetRadio(key, oldkey)
reject()
} else {
resolve(valideRes)
}
} else if (this.formData.configType == 1) { // 社招按产值
// 校验前,将tab的错误提示清除 单独循环处理,下一个循环是一个tab一个tab校验,会跳出循环
for (var j = 0; j < this.jobLevelData?.length; j++) {
this.$set(this.jobLevelData[j], 'validateErrFlag', false)
}
for (var j = 0; j < this.jobLevelData?.length; j++) {
const subVal = this.jobLevelData[j]
const node = this.$refs[`perConfigForm_${subVal.jobType}`] && this.$refs[`perConfigForm_${subVal.jobType}`][0]
if (node?.validateCustomForm) {
valideRes = await node.validateCustomForm()
if ((typeof valideRes == 'string') && valideRes.includes('error')) {
this.$set(this.jobLevelData[j], 'validateErrFlag', true)
this.resetRadio(key, oldkey)
reject()
let message = ''
switch (valideRes) {
case 'error1':
message = '产值区间重复'
break
case 'error2':
message = '请完整配置个人月均产值提成'
break
case 'error3':
message = '请选择个人月均产值提成产品'
break
}
if (message) return this.$message.warning(message)
} else {
this.$set(this.jobLevelData[j], 'configInfo', valideRes)
this.$set(this.jobLevelData[j], 'validateErrFlag', false)
}
}
}
resolve(this.jobLevelData)
} else { // 社招按渗透率
// 校验前,将tab的错误提示清除 单独循环处理,下一个循环是一个tab一个tab校验,会跳出循环
for (var j = 0; j < this.carTypeData?.length; j++) {
this.$set(this.carTypeData[j], 'validateErrFlag', false)
}
for (var j = 0; j < this.carTypeData?.length; j++) {
const subVal = this.carTypeData[j]
const node = this.$refs[`warrantyForm_${subVal.carType}`] && this.$refs[`warrantyForm_${subVal.carType}`][0]
if (node?.validateCustomForm) {
valideRes = await node.validateCustomForm(key, oldkey)
if (valideRes == 'error') {
this.$set(this.carTypeData[j], 'validateErrFlag', true)
this.resetRadio(key, oldkey)
reject()
} else {
this.$set(this.carTypeData[j], 'performanceInfo', valideRes)
this.$set(this.carTypeData[j], 'validateErrFlag', false)
}
}
}
resolve(this.carTypeData)
}
})
},
handleClose() {
this.$router.go(-1)
}
}
}
</script>
<style lang="scss" scoped>
.performanceScheme{
.warp_box{
background: #fff;
margin-bottom: 16px;
position: relative;
.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;
margin-bottom: 16px;
.line {
width: 4px;
height: 16px;
background: #185efe;
border-radius: 2px;
margin-right: 8px;
}
.title-wrap {
display: flex;
align-items: center;
}
.merchant-text {
font-size: 14px;
font-weight: normal;
color: #666666;
}
}
.space-b{
justify-content: space-between;
}
::v-deep .el-form-item__label{
padding: 0;
}
}
.warp_content{
padding: 0 20px 20px;
.add_btn{
margin-top: 10px;
}
.goods_content{
width: 432px;
display: flex;
flex-wrap: wrap;
gap: 4px;
border: 1px solid #E6E6E6;
padding: 4px;
border-radius: 3px;
.goods_item{
display: inline-block;
background: #FAFBFE;
border: 1px solid #E8E8EA;
border-radius: 4px;
height: 20px;
line-height: 20px;
padding: 3px 8px;
font-size: 14px;
color: #666666;
.del_btn{
margin-left: 4px;
cursor: pointer;
}
}
}
}
.footer_box {
text-align: center;
}
::v-deep input[aria-hidden="true"] {
display: none;
}
::v-deep .el-radio:focus:not(.is-focus):not(:active):not(.is-disabled) .el-radio__inner {
box-shadow: none !important;
}
.custom-tabs {
::v-deep .el-tabs__header {
border-bottom: none;
}
::v-deep .el-tabs__nav {
border-radius: 4px;
border: 1px solid #DCDFE6;
height: 36px;
overflow: hidden;
}
::v-deep .el-tabs__item {
height: 36px;
line-height: 36px;
}
::v-deep .el-tabs__item.is-active {
background-color: #2A58AD;
color: #ffffff;
}
::v-deep .el-tabs__item:hover {
color: #2A58AD;
}
::v-deep .el-tabs__item.is-active:hover {
color: #ffffff;
}
}
}
::v-deep #configType {
.el-form-item__label:before {
content: '*';
color: #F56C6C;
margin-right: 4px;
}
}
.copy_btn{
position: absolute;
transform: translate(0, -55px);
right: 0;
z-index: 2;
}
::v-deep .el-tabs__content{
overflow: visible;
}
</style>