addDialog.vue
7.68 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
<!-- 新增积分记录 -->
<template>
<baseDialog :dialog-config="dialogConfig"
:is-show.sync="visible"
class="accountDailog"
@handleClick="handleAddConfirm">
<div class="add-dialog">
<glsx-combi-form class="edit-form-container"
ref="addFormRef"
label-width="150px"
default-width="400px"
:form-ref="editChildRef"
:form-obj="infoForm"
:form-data="editFormData"
:form-rules="formRules">
<div slot="pointValueHtml"
slot-scope="scope">
<el-input-number v-model="infoForm.pointValue"
placeholder="输入数值"
:precision="1"
:step="0.1"
:min="-9.9"
:max="9.9"></el-input-number>
</div>
</glsx-combi-form>
</div>
</baseDialog>
</template>
<script>
import { pointRule, pointAdd, pointStaffQuery } from '@api/inStorePoints'
import { Util, deepClone } from '@/common/util'
export default {
name: 'AddDialog',
data() {
// function checkPhone(rule, value, callback) {
// if (!Util.checkPhone(value)) {
// callback(new Error('请输入正确的手机号码'))
// return false
// }
// callback()
// }
function checkPointValue(rule, value, callback) {
if (value == 0) {
callback(new Error('积分值不能为0'))
return false
}
callback()
}
return {
userInfo: this.$store.state.d2admin.user.info,
infoForm: {
staffName: '',
staffPhone: '',
pointClassification: '',
pointType: '',
pointDescription: '',
pointValue: 1
},
oldVal: {
transferTotalAmount: ''
},
dialogConfig: {
title: '新增记录',
width: '720px'
},
editChildRef: 'editChildRef',
formRules: {
staffName: [{ required: true, message: '请填写员工姓名', trigger: 'blur' }],
staffPhone: [{
required: true,
message: '请填写电话号码',
trigger: 'blur'
}, {
validator: this.checkPhone,
trigger: 'blur'
}],
pointClassification: [{ required: true, message: '请选择积分分类', trigger: 'blur' }],
pointType: [{ required: true, message: '请选择积分类型', trigger: 'blur' }],
// pointDescription: [{ required: true, message: '请填写备注', trigger: 'blur' }],
pointValue: [{
required: true,
message: '请填写积分值',
trigger: 'change'
}, {
validator: checkPointValue,
trigger: 'change'
}]
},
editFormData: [{
label: "电话号码",
name: "staffPhone",
type: "input",
inputType: "number",
isClear: true,
maxlength: "11"
}, {
label: '员工姓名',
name: 'staffName',
type: 'input',
maxlength: 8,
isDisabled: true,
placeholder: '请输入电话号码匹配'
// showLimit: true,
// isClear: true
}, {
label: '积分分类',
name: 'pointClassification',
type: 'select',
// isClear: true,
optionList: [],
optionId: 'categoryCode',
optionLabel: 'categoryName',
optionsName: 'pointClassificationOpt',
changeAttr: (value, targetItem) => {
this.baseData.pointTypeOpt = []
if (value) {
this.baseData.pointTypeOpt = this.baseData.pointClassificationOpt.find(item => item.categoryCode == value).typeList
}
this.infoForm.pointType = ""
this.getOptionsList('editFormData', false)
}
}, {
label: '积分类型',
name: 'pointType',
type: 'select',
isClear: true,
noDataText: "请先选择积分分类",
optionList: [],
optionId: 'typeCode',
optionLabel: 'typeName',
optionsName: 'pointTypeOpt'
}, {
label: '积分描述',
name: 'pointDescription',
type: 'input',
maxlength: 50,
inputType: 'textarea',
showLimit: true,
rows: 3
}, {
label: '积分值',
name: 'pointValue',
addHtml: 'pointValueHtml'
// rules: [{ required: true, message: '请输入金额,支持输入0~999999的数字,支持小数点后2位', trigger: 'change' }]
}],
baseData: {
pointClassificationOpt: [],
pointTypeOpt: []
},
uploadFileList: []
}
},
props: {
addVisible: {
type: Boolean,
default: false
}
},
watch: {
},
computed: {
visible: {
get() {
return this.addVisible
},
set(newVal) {
this.$emit('dialogClose', { flag: newVal, attrName: 'addVisible' })
}
}
},
mounted() {
this.pointRule()
},
methods: {
getOptionsList(formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
var item = this[formName].find(k => k.name == refreshSigle)
var index = this[formName].findIndex(k => k.name == refreshSigle)
this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
} else {
this[formName].forEach((item, index) => {
if (item.type === 'select' && this.baseData[item.optionsName].length) {
this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
}
})
}
},
checkPhone(rule, value, callback) {
if (!Util.checkPhone(value)) {
callback(new Error('请输入正确的手机号码'))
return false
}
pointStaffQuery({ staffPhone: value }).then((res) => {
console.log('res', res)
if (res) {
this.infoForm.staffName = res.staffName
}
}).catch((err) => {
console.log('err', err)
this.infoForm.staffName = ''
})
callback()
},
pointRule() {
pointRule({}).then((res) => {
this.baseData.pointClassificationOpt = res
this.getOptionsList('editFormData', false)
})
},
handleAddConfirm() {
this.$refs.addFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) {
var params = deepClone(this.infoForm)
// params.pointValue = params.pointValue + '' // 后台是字符串类型接收
pointAdd(params).then(res => {
this.notice.okTips('操作成功')
this.visible = true
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.add-dialog {
margin: 20px 0;
.reject-input {
::v-deep .el-textarea__inner {
height: 70px;
}
}
.el-textarea .el-input__count {
right: 90px;
bottom: -10px;
font-size: 12px;
color: #999999;
}
.tips {
color: #999999;
}
}
</style>