rateEdit.js
13.4 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
// packageWorkspace/pages/performanceRating/rateDetail/rateDetail.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'
import dayjs from 'dayjs'
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
navBarHeight: 0,
info: {},
resultInfo: {},
levelList: levelList,
pageQuery: {},
performanceList: [],
isT1DateRange: false,
T1EndDateStr: ''
},
navbarReady(e) {
let navBarHeight = e.detail.height
this.setData({
navBarHeight
})
},
back() {
wx.navigateBack()
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
pageQuery: options,
currentMobile: options.mobilePhone
}, () => {
// 获取当前月份的绩效配置规则
this.getRuleConfig()
// 获取自动检测结果
this.getAutoResult(options.mobilePhone)
// 获取绩效评分详情
this.getDetail(options.mobilePhone)
// 获取全部员工绩效
this.getList()
// 获取算工资的时间节点
this.getCycleTime()
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
getDayOfMonthText(dateStr) {
const date = new Date(dateStr.replace(' ', 'T'))
const day = date.getDate()
return day
},
// t1时间段内可编辑上月绩效
isExpired(endDateStr) {
const now = new Date()
const endDate = new Date(endDateStr)
if (now > endDate) {
return true
}
},
getCycleTime() {
api.getPerformanceTimeCycle({}).then(res => {
let { code, data, message } = res
if (code == 0) {
const T1EndDate = data?.find(val => val.cycleCode == 'T1')?.endDate
this.setData({
isT1DateRange: this.isExpired(T1EndDate),
T1EndDateStr: this.getDayOfMonthText(T1EndDate)
})
} else {
wx.$util.showToast(message)
}
})
},
getAutoResult(mobilePhone) {
let { pageQuery } = this.data
api.autoDetectResult({queryMonth: pageQuery.queryMonth, mobilePhone}).then(res => {
let { code, data, message } = res
if (code == 0) {
data.autoRewardCoefficient = !((data.autoRewardCoefficient ?? '') === '') ? `${data?.autoRewardCoefficient}` : ''
this.setData({
resultInfo: data || {}
})
} else {
wx.$util.showToast(message)
}
})
},
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)
}
})
},
getDetail(mobilePhone) {
let { pageQuery } = this.data
wx.$util.showLoading()
api.performanceDetail({queryMonth: pageQuery.queryMonth, mobilePhone}).then(res => {
wx.$util.hideLoading()
let {code, message, data} = res
if (code == 0) {
this.setData({
info: {
...data,
entryDate: data?.entryDate ? dayjs(data?.entryDate).format('YYYY-MM-DD') : '',
adoptType: data?.isAutoPerformance == 0 || !data?.isAutoPerformance ? 2 : data?.adoptType,
},
autoInfo: {
levelCode: data?.autoGradeCode,
rewardCoefficient: !((data?.autoRewardCoefficient ?? '') === '') ? `${data?.autoRewardCoefficient}` : '',
scoreSymbolValue: data?.autoScoreSymbolValue
}
})
// 非手动维护金额 计算绩效工资数
if (data?.adoptType == 2 && ((data?.manualFinalPerformanceAmount ?? '') === '')) {
this.setData({
'info.performanceSalary': NP.round(NP.times(NP.times(res.data.afterAttendanceTotalBasicSalary, 0.3), res.data.manualRewardCoefficient), 2)
})
}
this.setData({ navigating: false })
} else {
wx.$util.showToast(message)
}
})
},
checkIsFirstOrLast(list, targetMobile) {
if (!Array.isArray(list) || list.length === 0) {
return { isFirst: false, isLast: false }
}
const first = list[0].mobilePhone
const last = list[list.length - 1].mobilePhone
return {
isFirst: targetMobile == first,
isLast: targetMobile == last
}
},
getList() {
let { pageQuery } = this.data
api.getPerformanceList({queryMonth: pageQuery.queryMonth}).then(res => {
let { code, data, message } = res
if (code == 0) {
this.setData({
performanceList: data || [],
showLastBtn: !this.checkIsFirstOrLast(data, pageQuery.mobilePhone).isFirst,
showNextBtn: !this.checkIsFirstOrLast(data, pageQuery.mobilePhone).isLast
})
} else {
wx.$util.showToast(message)
}
})
},
handleHelpPopup() {
this.setData({
showHelpPopup: true
})
},
// 手动评分选择绩效等级
selectLevelCode() {
let {
info,
levelList,
isT1DateRange
} = this.data
if (isT1DateRange || info.submitCount >= 2 || !((info.totalGrossSalary ?? '') === '')) return
this.setData({
showSelectPopup: true,
selectOptions: levelList,
selectTitle: '绩效',
selectMultiple: false,
selectValue: [info.manualGradeCode],
})
},
handlePopupConfirm(e) {
let { values } = e.detail
let { ruleConfigInfo, info } = this.data
const obj = ruleConfigInfo?.performanceLevelDetailDTOS?.find(val => val.levelCode == values[0])
this.setData({
[`info.manualGradeCode`]: values[0],
['info.manualScoreSymbolValue']: obj.scoreSymbolValue,
['info.manualRewardCoefficient']: obj.rewardCoefficient
})
// 未输入手动维护绩效金额 根据评分等级系数计算绩效工资
if (((info.manualFinalPerformanceAmount ?? '') === '')) {
const performanceSalary = NP.round(NP.times(NP.times(info.afterAttendanceTotalBasicSalary, 0.3), obj.rewardCoefficient), 2)
this.setData({
'info.performanceSalary': performanceSalary,
'info.basicSalary': NP.plus(performanceSalary, info.baseSalary)
})
}
this.hideSelectPopup()
},
hideSelectPopup() {
this.setData({
showSelectPopup: false
})
},
priceInput(e) {
let { value } = e.detail
let { info } = 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
// 计算绩效工资,没有手动维护金额按绩效等级系数进行计算
const computedValue = value || (info.manualGradeCode ? NP.round(NP.times(NP.times(info.afterAttendanceTotalBasicSalary, 0.3), info.manualRewardCoefficient), 2) : 0)
this.setData({
'info.manualFinalPerformanceAmount': value,
'info.performanceSalary': computedValue,
'info.basicSalary': NP.plus(computedValue, info.baseSalary)
})
},
// 查看规则
goRule() {
let { info, pageQuery } = this.data
wx.navigateTo({
url: `/packageWorkspace/pages/performanceRating/ruleNote/ruleNote?autoGradeType=${info.autoGradeType}&queryMonth=${pageQuery.queryMonth}`,
})
},
// 切换
changeRadio(e) {
let { value } = e.currentTarget.dataset
let { isT1DateRange, info } = this.data
if (isT1DateRange || info.submitCount >= 2 || !((info.totalGrossSalary ?? '') === '')) return
this.setData({
'info.adoptType': value,
'info.manualFinalPerformanceAmount': ''
})
if (value == 1) {
const computedValue = NP.round(NP.times(NP.times(info.afterAttendanceTotalBasicSalary, 0.3), info.autoRewardCoefficient), 2)
this.setData({
'info.performanceSalary': computedValue,
'info.basicSalary': NP.plus(computedValue, info.baseSalary)
})
} else {
if (info.manualGradeCode) {
const performanceSalary = NP.round(NP.times(NP.times(info.afterAttendanceTotalBasicSalary, 0.3), info.manualRewardCoefficient), 2)
this.setData({
'info.performanceSalary': performanceSalary,
'info.basicSalary': NP.plus(performanceSalary, info.baseSalary)
})
} else {
this.setData({
'info.performanceSalary': 0,
'info.basicSalary': NP.plus(0, info.baseSalary)
})
}
}
},
// 提交
handleConfirm() {
let { info, T1EndDateStr, isT1DateRange } = this.data
if (isT1DateRange || info.submitCount >= 2 || !((info.totalGrossSalary ?? '') === '')) return
if (!((info.totalGrossSalary ?? '') === '')) { // 已出工资条 不能提交
return wx.showModal({
title: '提示',
content: '亲,总部已出首次工资条,如有问题请联系总部运营,统一增加扣减金额',
showCancel: false,
confirmText: '我知道了',
confirmColor: '#222222',
complete: (res) => {
}
})
}
if (info.submitCount < 2) {
if (info.adoptType == 2 && !info.manualGradeCode && !info.manualFinalPerformanceAmount) return wx.$util.showToast('请配置绩效评分')
wx.showModal({
title: '提交绩效确认',
content: `确认提交驻店销售的绩效考核评分吗?当前月${T1EndDateStr}号前可进行修改2次。`,
complete: (res) => {
if (res.confirm) {
wx.$util.showLoading()
let params = {
mobilePhone: info.mobilePhone,
evaluationMonth: info.evaluationMonth,
adoptType: info.adoptType,
amountCalculationType: info.adoptType == 2 && !((info.manualFinalPerformanceAmount ?? '') === '') ? 2 : 1,
manualGradeCode: info.adoptType == 2 ? info.manualGradeCode : '',
manualRewardCoefficient: info.adoptType == 2 ? info.manualRewardCoefficient : '',
manualScoreSymbolValue: info.adoptType == 2 ? info.manualScoreSymbolValue : '',
manualFinalPerformanceAmount: info.manualFinalPerformanceAmount || ''
}
api.singleSubmit(params).then(res => {
wx.$util.hideLoading()
let { code, message } = res
if (code == 0) {
this.getDetail(info.mobilePhone)
wx.showToast({
title: '提交成功',
icon: 'success'
})
} else {
wx.showModal({
title: '提示',
content: message,
showCancel: false,
confirmText: '我知道了',
confirmColor: '#222222'
})
}
})
}
}
})
} else {
wx.showModal({
title: '提示',
content: '亲,每月只有修改2次绩效次数,如有问题请联系总部运营,统一增加扣减金额',
showCancel: false,
confirmColor: '#222222',
confirmText: '我知道了',
complete: (res) => {
}
})
}
},
_getCurrentIndex() {
let { performanceList, currentMobile } = this.data
return performanceList.findIndex(item => item.mobilePhone == currentMobile)
},
// 上一位
handleLast() {
if (this.data.navigating) return
this.setData({ navigating: true })
let { performanceList } = this.data
const currentIndex = this._getCurrentIndex()
const prevPhone = performanceList[currentIndex - 1].mobilePhone
this.setData({
currentMobile: prevPhone,
showLastBtn: !this.checkIsFirstOrLast(performanceList, prevPhone).isFirst,
showNextBtn: !this.checkIsFirstOrLast(performanceList, prevPhone).isLast
})
this.getDetail(prevPhone)
},
// 下一位
handleNext() {
if (this.data.navigating) return
this.setData({ navigating: true })
let { performanceList } = this.data
const currentIndex = this._getCurrentIndex()
const nextPhone = performanceList[currentIndex + 1].mobilePhone
this.setData({
currentMobile: nextPhone,
showLastBtn: !this.checkIsFirstOrLast(performanceList, nextPhone).isFirst,
showNextBtn: !this.checkIsFirstOrLast(performanceList, nextPhone).isLast
})
this.getDetail(nextPhone)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})