batchModifySalaryDialog.vue
5.58 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
<!-- 批量修改薪资占比 -->
<template>
<glsk-form-dialog
ref="addResumeDialog"
v-if="isUpdateVisible"
:selectVisible="isUpdateVisible"
:dialogConfig="isUpdateDialogConfig"
label-width="150px"
defaultWidth="290px"
:formRules="isUpdateRules"
:editData="isUpdateForm"
:editFormData="isUpdateFormData"
:baseData="baseData"
@handleClose="closeDialogVisible"
@handleConfirm="handleUpdateConfirm"
:slotArr="slotArr"
class="batch-modify-salary-dialog"
>
<template slot="effectiveMonth">
<el-date-picker
v-model="isUpdateForm.effectiveMonth"
type="month"
placeholder="选择月份"
:picker-options="monthPickerOptions"
size="small"
:clearable="false"
value-format="yyyy-MM"
class="effectiveMonth"
>
</el-date-picker>
</template>
</glsk-form-dialog>
</template>
<script>
import { updateBatchSalary } from "@/api/resident"
import dayjs from "dayjs"
export default {
props: {
visible: {
type: Boolean,
default: false
},
staffPhoneList: {
type: Array,
default: () => []
}
},
computed: {
isUpdateVisible: {
get() {
return this.visible
},
set(val) {
this.$emit("update:visible", val)
}
}
},
data() {
return {
slotArr: ["effectiveMonth"],
monthPickerOptions: {
// 禁用当前月之前的所有月份(仅允许当月及未来)
disabledDate: (date) => dayjs(date).isBefore(dayjs(), "month")
},
isUpdateDialogConfig: {
title: "批量修改薪资占比",
width: "480px",
okText: "确定"
},
isUpdateForm: {
basicSalaryProportion: "",
performanceSalaryProportion: "",
effectiveMonth: ""
},
isUpdateFormData: [
{
label: "基本工资占比",
name: "basicSalaryProportion",
type: "input",
maxlength: "3",
placeholder: "请输入",
append: "%",
isClear: true
},
{
label: "绩效工资占比",
name: "performanceSalaryProportion",
type: "input",
maxlength: "3", // 联动仅需三位,限制为 1-99
placeholder: "请输入",
append: "%",
isClear: true
},
{
label: "生效月份",
name: "effectiveMonth",
addHtml: "effectiveMonth"
}
],
isUpdateRules: {
basicSalaryProportion: [
{ required: true, message: "请输入", trigger: "blur" },
{
validator: (rule, value, callback) =>
this.validatePercent(value, callback),
trigger: "blur"
}
],
performanceSalaryProportion: [
{ required: true, message: "请输入", trigger: "blur" },
{
validator: (rule, value, callback) =>
this.validatePercent(value, callback),
trigger: "blur"
}
],
effectiveMonth: [
{ required: true, message: "请选择", trigger: "change" }
]
},
baseData: {},
// 联动更新锁,避免互相更新时的递归触发
_linkageLock: false
}
},
methods: {
closeDialogVisible() {
this.isUpdateVisible = false
},
handleUpdateConfirm(data) {
let params = {
staffPhoneList: this.staffPhoneList,
...data
}
updateBatchSalary(params)
.then((res) => {
if (res) {
this.$message.success("修改成功")
}
this.$emit("refreshTable")
})
.catch(() => {})
.finally(() => {
this.isUpdateVisible = false
})
},
// 仅允许 1-100 的正整数;返回 null 表示空或无效输入
sanitizePercent(val) {
const s = String(val == null ? "" : val).replace(/\D/g, "")
if (!s) return null
let n = parseInt(s, 10)
if (isNaN(n)) return null
if (n < 0) n = 0
if (n > 100) n = 100
return n
},
// 表单校验规则:1-99 的正整数
validatePercent(value, callback) {
const v = this.sanitizePercent(value)
if (v === null) {
callback(new Error("请输入0-100的正整数"))
return
}
// 联动后总和恒为 100,这里只需校验单项合法
callback()
}
},
watch: {
// 基本工资占比变更时联动绩效工资占比
"isUpdateForm.basicSalaryProportion"(val) {
if (this._linkageLock) return
const v = this.sanitizePercent(val)
if (v === null) {
this._linkageLock = true
this.isUpdateForm.performanceSalaryProportion = ""
this._linkageLock = false
return
}
this._linkageLock = true
this.isUpdateForm.basicSalaryProportion = v
this.isUpdateForm.performanceSalaryProportion = 100 - v
this._linkageLock = false
},
// 绩效工资占比变更时联动基本工资占比
"isUpdateForm.performanceSalaryProportion"(val) {
if (this._linkageLock) return
const v = this.sanitizePercent(val)
if (v === null) {
this._linkageLock = true
this.isUpdateForm.basicSalaryProportion = ""
this._linkageLock = false
return
}
this._linkageLock = true
this.isUpdateForm.performanceSalaryProportion = v
this.isUpdateForm.basicSalaryProportion = 100 - v
this._linkageLock = false
}
}
}
</script>
<style lang="scss" scoped>
.batch-modify-salary-dialog{
::v-deep .el-date-editor.el-input{
width: 290px!important;
}
}
</style>