revisedSalaryDialog.vue
9.19 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
<!-- 修订应发工资 -->
<template>
<baseDialog :dialog-config="dialogConfig" :is-show.sync="visible"
@handleClick="handleAddConfirm">
<div class="detail-dialog">
<glsx-combi-form class="edit-form-container"
ref="editFormRef"
label-width="140px"
:is-block="true"
form-ref="editChildRef"
:form-obj="infoForm"
:form-data="formData"
:form-rules="formRules">
<template slot="syncUnit"><span class="unit">元</span></template>
<template slot="refundOffset">
<el-input style="width: 136px;" prefix-icon="el-icon-minus" @input="handleInput($event, 'refundOffset')" placeholder="请输入" v-model="infoForm.refundOffset"></el-input>
<span class="unit">元</span>
</template>
<template slot="customDeduction">
<el-input style="width: 136px;" @input="handleInput($event, 'customDeduction')" placeholder="输入正负值" v-model="infoForm.customDeduction"></el-input>
<span class="unit">元</span>
</template>
<template slot="correctSalary">
<el-input style="width: 136px;" placeholder="" disabled v-model="computedValue"></el-input>
<span class="unit">元</span>
</template>
</glsx-combi-form>
<div class="history-box" v-if="infoForm['historyRemark'].length">
<div class="line">
<span class="text">历史备注以及备注时间</span>
</div>
<el-timeline>
<el-timeline-item v-for="(reviewInfo, infoId) in infoForm['historyRemark']"
:color="infoId == 0 ? '#2A58AD' : '#999999'"
:key="infoId"
:timestamp="reviewInfo.updatedDateStr">
{{ reviewInfo.reviewMessage }}
</el-timeline-item>
</el-timeline>
</div>
</div>
</baseDialog>
</template>
<script>
import { reviseSalaryApi, getSalaryRecordApi } from '@api/resident'
import { Util} from '@/common/util'
import { limitPrice, limitPriceForNegative } from '@/common/format'
import BigNumber from 'bignumber.js'
import { isEmpty } from '../util.js'
export default {
name: 'RevisedSalaryDialog',
props: {
revisedSalaryVisible: {
type: Boolean,
default: false
},
revisedSalaryRow: {
type: Object,
default: () => ({})
}
},
data() {
var validateRefundOffset = (rule, value, callback) => {
if (!this.isEmpty(value) && Number(value) <= 0) {
callback(new Error('输入值必须大于0'))
} else {
callback()
}
}
var validateCustomDeduction = (rule, value, callback) => {
if (!this.isEmpty(value) && Number(value) == 0) {
callback(new Error('输入值不能为0'))
} else {
callback()
}
}
return {
isEmpty,
dialogConfig: {
title: '修订合计应发工资',
width: '720px'
},
formData: [
{
label: '当前月份合计应发',
name: 'currentSalary',
type: 'input',
isDisabled: true
},
{
label: '退单冲减',
name: 'refundOffset',
addHtml: 'refundOffset'
},
{
label: '正负冲减',
name: 'customDeduction',
addHtml: 'customDeduction'
},
{
label: '实发工资',
name: 'correctSalary',
addHtml: 'correctSalary'
},
{
label: '备注',
name: 'remark',
type: 'input',
inputType: 'textarea',
rows: 5,
maxlength: 500,
showLimit: true
}
],
infoForm: {
correctSalary: '',
refundOffset: '',
customDeduction: '',
remark: '',
historyRemark: [],
oldrefundOffset: '',
oldcustomDeduction: ''
},
formRules: {
correctSalary: [
{ required: true, message: '请输入修订后的应发工资', trigger: 'blur' }
],
refundOffset: [
{ required: false, message: '', trigger: 'blur' },
{ validator: validateRefundOffset, trigger: ['blur', 'change'] }
],
customDeduction: [
{ required: false, message: '', trigger: 'blur' },
{ validator: validateCustomDeduction, trigger: ['blur']}
],
remark: [
{ required: true, message: '请输入备注', trigger: 'blur' }
]
}
}
},
computed: {
visible: {
get() {
return this.revisedSalaryVisible
},
set(newVal) {
this.$emit('dialogClose', { flag: newVal, attrName: 'revisedSalaryVisible' })
}
},
computedValue: {
get() {
let currentSalary = new BigNumber(this.infoForm.currentSalary || 0)
let refundOffset = new BigNumber(this.infoForm.refundOffset || 0)
let customDeduction = new BigNumber(this.infoForm.customDeduction != '-' ? (this.infoForm.customDeduction || 0) : 0)
this.$set(this.infoForm, 'correctSalary', `${currentSalary.minus(refundOffset).plus(customDeduction)}`)
return `${currentSalary.minus(refundOffset).plus(customDeduction)}`
}
}
},
mounted() {
// 获取修订工资备注记录
this.getRecord()
},
methods: {
handleInput(e, key) {
if (key == 'customDeduction') {
this.$set(this.infoForm, key, limitPriceForNegative(e))
} else {
let oldValue = `${this.infoForm['old' + key]}`
let maxlength = key == 'customDeduction' ? 7 : 6
this.$set(this.infoForm, key, limitPrice(e, oldValue, maxlength, 2))
this.$set(this.infoForm, 'old' + key, this.infoForm[key])
}
// 清除与输入框1和输入框2相关的内容
const refundOffsetText = !this.isEmpty(this.infoForm['refundOffset']) && !isNaN(this.infoForm['refundOffset']) ? `退单冲减${this.infoForm['refundOffset']},` : ''
const customDeductionText = !this.isEmpty(this.infoForm['customDeduction']) && !isNaN(this.infoForm['customDeduction']) ? `正负冲减${this.infoForm['customDeduction']},` : ''
let existingText = this.infoForm.remark
.replace(/退单冲减[^,]*/g, '')
.replace(/正负冲减[^,]*/g, '')
.trim()
// 添加新的输入框内容
if (refundOffsetText) {
existingText += refundOffsetText
}
if (customDeductionText) {
existingText += customDeductionText
}
// 更新备注的内容
this.infoForm.remark = existingText
},
limitPriceForNegative(newValue) {
// 用来检索整数且不超过6位数
const limitDigit = /[0-9]{1,6}/
// 用来检索小数且小数点后不超过两位数
const limitDigitdot = /[0-9]{1,6}.[\d]{0,2}/
if (newValue) {
newValue = newValue + ""
let nn = ""
// 正负判断
if (newValue.match("-")) {
nn = newValue.match("-")[0]
}
// 小数判断
if (newValue.indexOf(".") != -1) {
if (newValue.match(limitDigitdot)) {
nn = nn + newValue.match(limitDigitdot)[0] || ""
}
} else {
if (newValue.match(limitDigit)) {
nn = nn + newValue.match(limitDigit)[0] || ""
}
}
return nn
}
},
getRecord() {
getSalaryRecordApi({ staffPhone: this.revisedSalaryRow.staffPhone, salaryMonth: this.revisedSalaryRow.salaryMonth, pageSize: 10, currentPage: 1 }).then(res => {
res?.list?.forEach(item => {
item.reviewMessage = item.remark
item.updatedDateStr = Util.dateFormate(item.createdDate, 'YYYY-MM-DD HH:mm:ss')
})
this.infoForm.historyRemark = res?.list || []
this.$set(this.infoForm, 'currentSalary', this.revisedSalaryRow.correctSalary || this.revisedSalaryRow.salary)
})
},
handleAddConfirm() {
this.$refs.editFormRef?.$refs?.editChildRef?.validate((valid) => {
if (valid) {
let params = {
id: this.revisedSalaryRow.id,
refundOffset: this.infoForm.refundOffset || '',
customDeduction: this.infoForm.customDeduction || '',
correctSalary: this.computedValue,
remark: this.infoForm.remark
}
if (this.computedValue - 0 < 0) return this.$message.warning('实发工资不能小于0')
if (isNaN(params.customDeduction)) return this.$message.warning('正负冲减值需为数字')
reviseSalaryApi(params).then(res => {
this.$message.success('修订成功')
this.$emit('dialogClose', { flag: true, attrName: 'revisedSalaryVisible' })
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.detail-dialog{
.unit{
margin-left: 4px;
}
.line{
width: 100%;
height: 1px;
background: #E6E6E6;
position: relative;
margin: 32px 0;
.text{
position: absolute;
left: 50%;
top: -10px;
transform: translateX(-50%);
background: #fff;
padding: 0 16px;
font-size: 14px;
color: #00000066;
}
}
::v-deep .el-timeline-item__node--normal{
width: 8px;
height: 8px;
}
::v-deep .el-timeline-item__tail{
left: 2px
}
}
</style>