batchOperation.js
10.6 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
// packageWorkspace/pages/performanceRating/batchOperation/batchOperation.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/regional-assistant/'
import { levelList } from '~/packageWorkspace/pages/performanceRating/constant'
import api from '~/packageWorkspace/pages/performanceRating/api'
import NP from 'number-precision'
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
selectedStaffList: [],
staffList: [],
batchConfigType: 1,
batchInfo: {
manualGradeCode: ''
},
levelList: levelList
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
pageQuery: options
}, () => {
// 获取员工列表
this.getStaffList()
// 获取当前月份的绩效配置规则
this.getRuleConfig()
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
getRuleConfig() {
let { pageQuery } = this.data
api.getPerformanceRule({queryMonth: pageQuery.queryMonth}).then(res => {
let { code, data, message } = res
if (code == 0) {
this.setData({
ruleConfigInfo: data
})
} else {
wx.$util.showToast(message)
}
})
},
getStaffList() {
let { pageQuery } = this.data
wx.$util.showLoading()
api.getStaffListAPI({queryMonth: pageQuery.queryMonth}).then(res => {
wx.$util.hideLoading()
let { code, data, message } = res
if (code == 0) {
data?.forEach(val => {
val.levelCode = val.adoptType == 1 ? val.autoGradeCode : val.adoptType == 2 ? val.manualGradeCode : ''
})
this.setData({
staffList: data || []
})
} else {
wx.$util.showToast(message)
}
})
},
// 批量选择员工
handleSelectStaff() {
let {
selectedStaffList,
staffList
} = this.data
this.setData({
showSelectPopup: true,
selectOptions: staffList,
selectTitle: '选择员工',
selectMultiple: true,
selectValues: selectedStaffList?.map(val => { return val.mobilePhone }),
selectType: 'staff'
})
},
handleMaxTips() {
wx.$util.showToast('最多支持选择20位员工')
},
handlePopupConfirm(e) {
let { selectType, singleSelectIndex, batchSingleList } = this.data
if (selectType == 'staff') {
let { items } = e.detail
this.setData({
selectedStaffList: items
}, () => {
// 获取批量员工的绩效数据
this.getBatchStaffPerformance()
})
} else {
let { values } = e.detail
let { ruleConfigInfo, batchInfo, batchFlag } = this.data
const obj = ruleConfigInfo?.performanceLevelDetailDTOS?.find(val => val.levelCode == values[0])
if (batchFlag) { // 统一设置等级
this.setData({
'batchInfo.manualGradeCode': values[0],
'batchInfo.manualScoreSymbolValue': obj.scoreSymbolValue,
'batchInfo.manualRewardCoefficient': obj.rewardCoefficient
})
} else {
this.setData({
[`batchSingleList[${singleSelectIndex}].manualGradeCode`]: values[0],
[`batchSingleList[${singleSelectIndex}].manualScoreSymbolValue`]: obj.scoreSymbolValue,
[`batchSingleList[${singleSelectIndex}].manualRewardCoefficient`]: obj.rewardCoefficient
})
// 未输入手动维护绩效金额 根据评分等级系数计算绩效工资
if (((batchSingleList[singleSelectIndex].manualFinalPerformanceAmount ?? '') === '')) {
const performanceSalary = NP.round(NP.times(NP.times(batchSingleList[singleSelectIndex].afterAttendanceTotalBasicSalary, 0.3), obj.rewardCoefficient), 2)
this.setData({
[`batchSingleList[${singleSelectIndex}].performanceSalary`]: performanceSalary,
[`batchSingleList[${singleSelectIndex}].basicSalary`]: NP.round(NP.plus(performanceSalary, batchSingleList[singleSelectIndex].baseSalary), 2)
})
}
}
}
this.hideSelectPopup()
},
hideSelectPopup() {
this.setData({showSelectPopup: false})
},
getBatchStaffPerformance() {
let { selectedStaffList, pageQuery } = this.data
if (!selectedStaffList.length) return
api.getBatchPerformanceInfo({queryMonth: pageQuery.queryMonth, mobilePhoneList: selectedStaffList?.map(val => { return val.mobilePhone })}).then(res => {
let { code, data, message } = res
if (code == 0) {
data?.forEach(val => {
val.gradeCode = val.adoptType == 1 ? val.autoGradeCode : val.adoptType == 2 ? val.manualGradeCode : '',
val.performanceSalary = !((val.manualFinalPerformanceAmount ?? '') === '') ? val.manualFinalPerformanceAmount : val.performanceSalary // 最终绩效工资
val.rewardCoefficient = val.adoptType == 1 ? val.autoRewardCoefficient : val.adoptType == 2 ? val.manualRewardCoefficient : '' // 最终奖励系数
val.scoreSymbolValue = val.adoptType == 1 ? val.autoScoreSymbolValue : val.adoptType == 2 ? val.manualScoreSymbolValue : '' // 最终分数范围
})
this.setData({
batchSingleList: data || []
})
} else {
wx.$util.showToast(message)
}
})
},
changeRadio(e) {
let { value } = e.currentTarget.dataset
let { selectedStaffList } = this.data
if (value == 2 && !selectedStaffList.length) return wx.$util.showToast('请选择员工')
this.setData({
batchConfigType: value
})
},
// 手动评分选择绩效等级
selectLevelCode(e) {
let { batch, index } = e.currentTarget.dataset
let {
batchInfo,
levelList,
batchSingleList
} = this.data
this.setData({
showSelectPopup: true,
selectOptions: levelList,
selectTitle: '绩效',
selectMultiple: false,
selectValue: batch ? [batchInfo.manualGradeCode] : [batchSingleList[index].manualGradeCode],
batchFlag: batch,
selectType: 'level',
singleSelectIndex: !batch ? index : null
})
},
priceInput(e) {
let { value } = e.detail
let { index } = e.currentTarget.dataset
let { batchConfigType, batchSingleList } = this.data
let cleanValue = value.replace(/[^\d.]/g, '')
const firstDotIndex = cleanValue.indexOf('.')
if (firstDotIndex != -1) {
cleanValue = cleanValue.substring(0, firstDotIndex + 1) + cleanValue.substring(firstDotIndex + 1).replace(/\./g, '')
}
if (cleanValue == '.') {
cleanValue = '0.'
}
if (cleanValue.length > 1 && cleanValue.startsWith('0') && !cleanValue.startsWith('0.')) {
cleanValue = cleanValue.replace(/^0+/, '')
if (cleanValue == '') {
cleanValue = '0'
}
}
const numericValue = parseFloat(cleanValue)
if (numericValue > 100000) {
cleanValue = '100000'
} else if (numericValue == 100000 && cleanValue.includes('.')) {
cleanValue = '100000'
}
const dotIndexAfterCheck = cleanValue.indexOf('.');
if (dotIndexAfterCheck != -1 && cleanValue.length > dotIndexAfterCheck + 3) {
cleanValue = cleanValue.substring(0, dotIndexAfterCheck + 3)
}
value = cleanValue
if (batchConfigType == 1) {
this.setData({
'batchInfo.manualFinalPerformanceAmount': value
})
} else {
// 计算绩效工资,没有手动维护金额按绩效等级系数进行计算
const computedValue = value || (batchSingleList[index]?.manualGradeCode ? NP.round(NP.times(NP.times(batchSingleList[index]?.afterAttendanceTotalBasicSalary, 0.3), batchSingleList[index].manualRewardCoefficient), 2) : 0)
this.setData({
[`batchSingleList[${index}].manualFinalPerformanceAmount`]: value,
[`batchSingleList[${index}].performanceSalary`]: computedValue,
[`batchSingleList[${index}].basicSalary`]: NP.round(NP.plus(computedValue, batchSingleList[index]?.baseSalary), 2)
})
}
},
handleHelpPopup() {
this.setData({
showHelpPopup: true
})
},
handleConfirm() {
const { batchConfigType, batchInfo, batchSingleList, selectedStaffList, pageQuery } = this.data
if (!selectedStaffList.length) {
return wx.$util.showToast('请选择员工')
}
const mapStaffToSubmitItem = (staff, source) => ({
mobilePhone: staff.mobilePhone,
evaluationMonth: pageQuery.queryMonth,
manualGradeCode: source.manualGradeCode,
manualRewardCoefficient: source.manualRewardCoefficient,
manualScoreSymbolValue: source.manualScoreSymbolValue,
manualFinalPerformanceAmount: source.manualFinalPerformanceAmount,
adoptType: 2,
amountCalculationType: !((source.manualFinalPerformanceAmount ?? '') === '') ? 2 : 1
})
let perfAppraisalSubmitReqDTO = []
if (batchConfigType == 1) {
// 批量统一设置
if (!batchInfo.manualGradeCode && !batchInfo.manualFinalPerformanceAmount) {
return wx.$util.showToast('请配置绩效评分')
}
perfAppraisalSubmitReqDTO = selectedStaffList.map(staff =>
mapStaffToSubmitItem(staff, batchInfo)
)
} else {
for (const staff of batchSingleList) {
const hasGrade = (staff.manualGradeCode ?? '') !== '';
const hasAmount = (staff.manualFinalPerformanceAmount ?? '') !== ''
if (!hasGrade && !hasAmount) {
wx.$util.showToast(`请配置【${staff.name}】的绩效评分`)
}
}
perfAppraisalSubmitReqDTO = batchSingleList.map(staff =>
mapStaffToSubmitItem(staff, staff)
)
}
if (this.data.confirmFlag) return
this.setData({ confirmFlag: true })
wx.$util.showLoading()
const params = {
evaluationMonth: pageQuery.queryMonth,
perfAppraisalSubmitReqDTO
}
api.batchSubmit(params)
.then(res => {
wx.$util.hideLoading();
this.setData({ confirmFlag: false })
const { code, message } = res
if (code == 0) {
wx.navigateBack()
} else {
wx.showModal({
title: '提示',
content: message,
showCancel: false,
confirmText: '我知道了',
confirmColor: '#222222'
})
}
})
.catch(() => {
wx.$util.hideLoading()
this.setData({ confirmFlag: false })
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})