campus.vue
13.3 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
<!-- 校招绩效配置 -->
<template>
<div class="content">
<el-form :model="infoData" :rules="rules" ref="configForm">
<el-form-item label="" prop="campusList" label-width="0">
<div class="config-table">
<template>
<el-table :data="infoData.campusList" :header-cell-style="rowClass">
<el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
<el-table-column prop="jobType" label="职级" min-width="145">
<template slot-scope="scope">
<el-form-item :prop="`campusList[${scope.$index}].jobType`" :rules="rules.jobType" label-width="0">
<el-select clearable filterable v-model="scope.row['jobType']" @change="handleSelect" style="width: 130px" placeholder="请选择">
<el-option v-for="item in baseData.jobTypeList" :key="item.confId" :label="item.confValue" :value="item.confId">
</el-option>
</el-select>
</el-form-item>
</template>
</el-table-column>
<el-table-column prop="penertrationRate" label="渗透率要求" min-width="215">
<template slot-scope="scope">
<el-form-item :prop="`campusList[${scope.$index}].startValue`" :rules="rules.startValue">
<el-input class="rate_input" @input="handleInput($event, 'startValue', scope)" v-model="scope.row['startValue']" placeholder="请输入">
<span slot="suffix" class="suffix_text">%</span>
</el-input>
</el-form-item> -
<el-form-item :prop="`campusList[${scope.$index}].endValue`" :rules="rules.endValue">
<el-input class="rate_input" @input="handleInput($event, 'endValue', scope)" v-model="scope.row['endValue']" placeholder="请输入">
<span slot="suffix" class="suffix_text">%</span>
</el-input>
</el-form-item>
</template>
</el-table-column>
<el-table-column prop="calculateValue" label="提成系数" min-width="175">
<template slot="header">
<div class="custom-header">
<span>提成系数</span>
<span class="label_tip">(业绩提成点数)</span>
</div>
</template>
<template slot-scope="scope">
<el-form-item :prop="`campusList[${scope.$index}].calculateValue`" :rules="rules.calculateValue">
<el-input class="rate_input" @input="handleInput($event, 'calculateValue', scope)" v-model="scope.row['calculateValue']" placeholder="请输入">
<span slot="suffix" class="suffix_text">%</span>
</el-input>
</el-form-item>
</template>
</el-table-column>
<el-table-column prop="percentage" label="提成分配机制" min-width="580">
<template slot="header">
<div class="custom-header">
<span>提成分配机制</span>
<span class="label_tip">(个人+导师+区域督导+奖励池=100%员工业绩提成金额)</span>
</div>
</template>
<template slot-scope="scope">
个人
<el-form-item :prop="`campusList[${scope.$index}].grCommissionRatio`" :rules="rules.grCommissionRatio">
<el-input class="rate_input" @input="handleInput($event, 'grCommissionRatio', scope)" v-model="scope.row['grCommissionRatio']" placeholder="请输入">
<span slot="suffix" class="suffix_text">%</span>
</el-input> +
</el-form-item>
导师
<el-form-item :prop="`campusList[${scope.$index}].dsCommissionRatio`" :rules="rules.dsCommissionRatio">
<el-input class="rate_input" @input="handleInput($event, 'dsCommissionRatio', scope)" v-model="scope.row['dsCommissionRatio']" placeholder="请输入">
<span slot="suffix" class="suffix_text">%</span>
</el-input> +
</el-form-item>
督导
<el-form-item :prop="`campusList[${scope.$index}].ddCommissionRatio`" :rules="rules.ddCommissionRatio">
<el-input class="rate_input" @input="handleInput($event, 'ddCommissionRatio', scope)" v-model="scope.row['ddCommissionRatio']" placeholder="请输入">
<span slot="suffix" class="suffix_text">%</span>
</el-input> +
</el-form-item>
奖励池
<el-form-item :prop="`campusList[${scope.$index}].jlcCommissionRatio`" :rules="rules.jlcCommissionRatio">
<el-input class="rate_input" @input="handleInput($event, 'jlcCommissionRatio', scope)" v-model="scope.row['jlcCommissionRatio']" placeholder="请输入">
<span slot="suffix" class="suffix_text">%</span>
</el-input>
</el-form-item>
</template>
</el-table-column>
<el-table-column prop="" label="操作" width="60">
<template slot-scope="scope">
<el-button type="text" @click="del(scope.$index)">删除</el-button>
</template>
</el-table-column>
</el-table>
</template>
<div class="add_btn">
<el-button size="small" icon="el-icon-plus" @click="addRow">新增一行</el-button>
</div>
</div>
</el-form-item>
</el-form>
</div>
</template>
<script>
import { deepClone } from '@/common/util'
import { staffLevelList } from '@/common/constants.js'
import { limitPrice } from '@/common/format'
import BigNumber from 'bignumber.js'
export default {
name: 'CampusConfig',
data() {
var endValidator = (rule, value, callback) => {
const index = rule.fullField.match(/\d+/)[0]
const start = this.infoData.campusList[index].startValue
const end = this.infoData.campusList[index].endValue
if ((value - 0) < (start - 0) || (end && (value - 0) > (end - 0))) {
callback(new Error('区间有误'))
} else {
callback();
}
}
return {
rules: {
campusList: [
{required: true, message: '请配置绩效方案', trigger: 'change' },
],
jobType: [
{ required: true, message: '请选择职级', trigger: 'change' }
],
startValue: [
{ required: true, message: '请输入比例', trigger: 'blur' },
{ validator: endValidator, trigger: 'blur' }
],
endValue: [
{ required: true, message: '请输入比例', trigger: 'blur' },
{ validator: endValidator, trigger: 'blur' }
],
calculateValue: [
{ required: true, message: '请输入比例', trigger: 'blur' }
],
grCommissionRatio: [
{ required: true, message: '请输入比例', trigger: 'blur' }
],
dsCommissionRatio: [
{ required: true, message: '请输入比例', trigger: 'blur' }
],
ddCommissionRatio: [
{ required: true, message: '请输入比例', trigger: 'blur' }
],
jlcCommissionRatio: [
{ required: true, message: '请输入比例', trigger: 'blur' }
]
},
baseData: {
jobTypeList: deepClone(staffLevelList.slice(0, staffLevelList.length - 3)) // 剔除区域督导选项
},
infoData: {}
}
},
props: {
configInfo: {
type: Object,
default: () => {
return {}
}
}
},
computed: {},
mounted() {
this.infoData = deepClone(this.configInfo)
},
methods: {
rowClass({ row, rowIndex }) {
return 'background:#F2F4F7;color:#333333;font-size:14px;font-weight:600;'
},
addRow() {
let obj = {
jobType: '',
startValue: '',
endValue: '',
calculateValue: '',
grCommissionRatio: '',
dsCommissionRatio: '',
ddCommissionRatio: '',
jlcCommissionRatio: ''
}
this.infoData.campusList.push(obj)
this.$nextTick(() => {
this.$refs['configForm'].clearValidate()
})
},
del(index) {
this.$confirm('确认删除吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.infoData.campusList.splice(index, 1)
this.$nextTick(() => {
this.$refs['configForm'].clearValidate()
})
}).catch(() => {
})
},
handleInput(e, key, scope) {
e = e.replace(/[^\d.]/g, '')
let index = scope.$index
let oldValue = `${this.infoData.campusList[index]['old' + key]}`
this.$set(this.infoData.campusList[index], key, limitPrice(e, oldValue, 3, key == 'startValue' || key == 'endValue' ? 0 : 2, 0, 100))
this.$set(this.infoData.campusList[index], 'old' + key, this.infoData.campusList[index][key])
},
// 选择职级后将列表顺序排序
handleSelect() {
this.infoData.campusList?.sort((a, b) => a.jobType - b.jobType)
},
// 获取配置数据
getFormData() {
return new Promise((resolve, reject) => {
resolve(this.infoData)
})
},
validateCustomForm() {
return new Promise((resolve, reject) => {
this.$refs['configForm'].validate((valid) => {
if (valid) {
if (!this.validateCoverage()) {
resolve('error')
return
}
resolve(this.infoData)
} else {
resolve('error')
}
})
})
},
// 校验渗透率区间是否覆盖完整和提成分配机制总合是否为100%
validateCoverage() {
const jobTypes = {}
const arr = this.infoData.campusList
// 将campusList按jobType分组
for (const item of arr) {
if (!jobTypes[item.jobType]) {
jobTypes[item.jobType] = []
}
jobTypes[item.jobType].push(item)
}
// 遍历每个jobType
for (const jobType in jobTypes) {
const jobTypeText = this.baseData.jobTypeList.find(item => item.confId == jobType).confValue
const intervals = jobTypes[jobType]
// 按startValue排序
intervals.sort((a, b) => a.startValue - b.startValue)
let values = []
intervals.forEach(item => {
values.push(item.startValue)
values.push(item.endValue)
})
// 检查渗透率区间是否覆盖完整的0-100%
values.sort((a, b) => a - b)
if (values[0] != 0 || values[values.length - 1] != 100) {
this.$message.warning(`绩效配置单个职级渗透率要求需满足100%的比例范围`)
return false
}
// 检查渗透率区间是否连续且无重叠
for (let i = 1; i < intervals.length; i++) {
const startValue = new BigNumber(intervals[i].startValue || 0)
const endValue = new BigNumber(intervals[i - 1]?.endValue || 0)
if (startValue.minus(endValue).toNumber() > 1) {
this.$message.warning(`职级 ${jobTypeText} 渗透率区间不连续`)
return false
}
if (startValue.toNumber() <= endValue.toNumber()) {
this.$message.warning(`职级 ${jobTypeText} 渗透率区间存在重叠`)
return false
}
}
// 检查提成分配机制的总和是否等于100%
for (const item of intervals) {
const grCommissionRatio = new BigNumber(item.grCommissionRatio)
const dsCommissionRatio = new BigNumber(item.dsCommissionRatio)
const ddCommissionRatio = new BigNumber(item.ddCommissionRatio)
const jlcCommissionRatio = new BigNumber(item.jlcCommissionRatio)
const total = grCommissionRatio.plus(dsCommissionRatio).plus(ddCommissionRatio).plus(jlcCommissionRatio).toNumber()
if (total != 100) {
const penertrationRate = `${item.startValue}-${item.endValue}`
this.$message.warning(`职级 ${jobTypeText} 渗透率区间 ${penertrationRate} 的提成分配机制的总和必须等于100%`)
return false
}
}
}
return true
}
}
}
</script>
<style lang="scss" scoped>
.content {
padding-top: 10px;
.config-table{
.custom-header {
.label_tip {
font-size: 12px;
font-weight: normal;
color: #333333;
}
}
.rate_input {
display: inline-block;
width: 90px;
.suffix_text {
display: flex;
align-items: center;
height: 100%;
}
}
.add_btn{
margin-top: 10px;
}
}
::v-deep.config-table {
.el-table .cell {
padding: 0 10px;
}
.el-table__body-wrapper {
.el-table__row td:nth-child(1) {
border-left: 1px solid #ebeef5;
}
.el-table__row td:nth-last-child(1) {
border-right: 1px solid #ebeef5;
}
.el-table__row .cell {
padding: 16px 10px;
}
}
.select {
.el-tag {
width: auto;
}
}
.el-form-item{
display: inline-block;
margin-bottom: 0;
}
}
}
</style>