addExpenseDialog.vue
6.9 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
<!-- 新增支出 -->
<template>
<div>
<d2-dialog
:title="'新增支出'"
:is-visible="expenseVisible"
width="700px"
@closeDialog="handleAdd"
@confirmDialog="handleAddConfirm"
>
<glsx-combi-form class="edit-form-container"
ref="editFormRef"
label-width="110px"
:is-block="true"
form-ref="editChildRef"
:form-obj="expenseForm"
:form-data="formData"
:form-rules="formRules">
<template slot="staff">
<el-select v-model="expenseForm.staffPhone" placeholder="请选择员工"
style="width: 432px" remote reserve-keyword @visible-change="visibleChange"
:remote-method="remoteMethod" v-el-select-loadmore="interestsLoadmore" @change="handleStaffChange" filterable>
<el-option v-for="item in baseData.staffList" :key="item.staffPhone" :label="item.staffName" :value="item.staffPhone"></el-option>
</el-select>
</template>
<template slot="syncUnit"><span class="unit">元</span></template>
</glsx-combi-form>
</d2-dialog>
</div>
</template>
<script>
import { mapActions } from "vuex"
import { limitPrice } from '@/common/format'
import { addIncentivePoolApi, getLevelStaffListApi } from '@/api/resident'
import { staffLevelList } from '@/common/constants.js'
import { filterStr } from '../../inStoreManage/util.js'
export default {
name: "AddExpenseDialog",
data() {
return {
expenseForm: {
staffPhone: "",
jobType: "",
merchantName: "",
amount: "",
remark: ""
},
formData: [
{
label: '员工',
name: 'staffName',
addHtml: 'staff',
rules: [{ required: true, message: '请选择员工', trigger: 'change' }]
},
{
label: '员工手机号',
name: 'staffPhone',
type: 'input',
isDisabled: true
},
{
label: '员工职级',
name: 'jobTypeStr',
type: 'input',
isDisabled: true
},
{
label: '归属门店',
name: 'merchantName',
type: 'input',
isDisabled: true
},
{
label: '支出金额',
name: 'amount',
type: 'input',
width: '136px',
inputFn: (e) => {
e = e.replace(/[^\d.]/g, '')
let oldValue = this.expenseForm['oldamount'] || ''
this.$set(this.expenseForm, 'amount', limitPrice(e, oldValue, 6, 2, 0))
this.$set(this.expenseForm, 'oldamount', this.expenseForm['amount'])
},
suffixSlot: 'syncUnit'
},
{
label: '备注',
name: 'remark',
type: 'input',
inputType: 'textarea',
rows: 4,
maxlength: 100,
showLimit: true
}
],
formRules: {
amount: [
{ required: true, message: "请输入支出金额", trigger: "change" },
{
required: true,
trigger: 'blur',
validator: (rule, value, callback) => {
(+value > +this.expensePoolInfo.totalBalance) ? callback(new Error('不得超过激励池总额')) : callback()
}
}
],
remark: [
{ required: true, message: "请输入备注", trigger: "blur" }
]
},
// 基本数据
baseData: {
staffList: []
},
staffName: "",
currentPage: 1,
pageSize: 20
}
},
props: {
expenseVisible: {
type: Boolean,
default: false
},
expensePoolInfo: {
type: Object,
default: () => {}
}
},
watch: {
expenseVisible(val) {
if (val) {
this.$nextTick(() => {
this.$refs.addExpenseForm?.resetFields()
})
}
}
},
directives: {
"el-select-loadmore": {
bind(el, binding) {
setTimeout(() => {
const SELECTWRAP_DOM = el.querySelector(
'.el-select-dropdown .el-select-dropdown__wrap'
)
if (SELECTWRAP_DOM) {
SELECTWRAP_DOM.addEventListener('scroll', function () {
const condition =
this.scrollHeight - this.scrollTop <= this.clientHeight
if (condition) {
binding.value()
}
})
}
}, 500)
}
}
},
mounted() {
},
methods: {
...mapActions({
get: "d2admin/base/get"
}),
visibleChange(data) {
// 获取焦点重新渲染下拉框数据
if (data) {
this.staffName = ""
this.currentPage = 1
this.baseData.staffList = []
this.getSelectingList()
}
},
// 获取配置职级的员工
remoteMethod(query) {
this.staffName = query
this.currentPage = 1
this.baseData.staffList = []
this.getSelectingList()
},
// 获取更多员工
interestsLoadmore() {
setTimeout(() => {
this.currentPage = this.currentPage + 1
if (this.allPages < this.currentPage) {
this.currentPage = this.allPages
return
}
this.getSelectingList()
}, 10)
},
// 获取员工列表
getSelectingList() {
let params = {
currentPage: this.currentPage,
pageSize: this.pageSize,
staffName: this.staffName
}
getLevelStaffListApi(params).then(res => {
this.baseData.staffList = this.baseData.staffList.concat(res.list || [])
this.allPages = res.pages
})
},
// 选择员工 将附带信息赋值到输入框
handleStaffChange(val) {
this.baseData.staffList.forEach(item => {
if (item.staffPhone === val) {
this.$set(this.expenseForm, 'staffPhone', item.staffPhone)
this.$set(this.expenseForm, 'jobTypeStr', filterStr(item.jobType, staffLevelList, item.hireType))
this.$set(this.expenseForm, 'merchantName', item.merchantName)
this.$set(this.expenseForm, 'staffName', item.staffName)
this.$set(this.expenseForm, 'jobType', item.jobType)
}
})
},
handleAdd() {
this.$emit("expenseClose")
},
handleAddConfirm() {
this.$refs.editFormRef?.$refs.editChildRef?.validate((valid) => {
if (valid) {
let params = {
staffPhone: this.expenseForm?.staffPhone,
staffName: this.expenseForm?.staffName,
jobType: this.expenseForm?.jobType,
expensePrice: this.expenseForm?.amount,
remark: this.expenseForm?.remark
}
addIncentivePoolApi(params).then(res => {
this.$message.success('添加成功')
this.$emit("expenseClose", true)
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.unit{
margin-left: 4px;
}
</style>