usageLimitDialog.vue
6.53 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
<template>
<baseDialog :is-show.sync="dialogShow" :dialog-config="dialogConfig.config" class="detail-content-warn"
@handleClick="submit">
<div class="usage-box flex">
<div class="progress-box">
<el-steps direction="vertical" :active="3">
<el-step title="请阅读功能使用注意事项"></el-step>
<el-step title="请填写当期使用额度"></el-step>
<el-step title="请填写预警通知邮箱"></el-step>
</el-steps>
</div>
<div class="form">
<div class="tips">
每次“新增使用额度”都会重置上次限额,且上次未使用额度不会延续叠加使用(仅当期有效);<br>
预警通知触发条件:当额度使用率达到70%、80%、90%、95%时,各触发一次预警;<br>
“使用额度”仅控制二手车业务自动付款,超过当期额度后无法自动付款。
</div>
<el-form label-width="150px" size="small" :model="infoForm" ref="editRef" :rules="formRules">
<el-form-item label="当期使用额度:" class="usage-limit" prop="usageLimit">
<el-input v-model.number="infoForm.usageLimit" class="input-width" :maxlength="15"
@input="handleUsageLimitNum" @blur="handleBlur" placeholder="请输入当前使用额度">
</el-input>
<span class="unit">元</span>
</el-form-item>
<el-form-item label="预警通知邮箱:" prop="warningEmail">
<el-input v-model="infoForm.warningEmail" class="input-width" :maxlength="200"
placeholder="请输入预警通知邮箱(多邮箱用逗号隔开,最多五个)">
</el-input>
</el-form-item>
</el-form>
</div>
</div>
</basedialog>
</template>
<script>
import { addFundUsageLimit } from "@api/usedCarManagement"
import { limitPrice } from '@/common/format'
import { deepClone } from "@/common/util"
export default {
name: "UsageLimitDialog",
inject: ['userInfo'],
props: {
visible: {
type: Boolean,
default: false
},
},
computed: {
dialogShow: {
get() {
return this.visible
},
set(val) {
this.$emit('dialogClose', { flag: this.refreshFlag })
}
},
authPhone() {
return this.userInfo.loginAccount.phone
}
},
watch: {
visible: {
handler(val) {
if (val) {
this.oldVal = ''
this.infoForm = this.$options.data.call(this).infoForm
this.$refs?.editRef?.resetFields()
}
},
immediate: true,
deep: true
}
},
mounted() {
},
data() {
return {
dialogConfig: {
config: {
title: "新增使用额度",
width: "840px"
}
},
infoForm: {
usageLimit: '',
warningEmail: ''
},
oldVal: '',
formRules: {
usageLimit: [
{ required: true, message: "请填写当期使用额度", trigger: "blur" }
],
warningEmail: [{
required: true,
validator: (rule, value, callback) => {
if (!value) {
return callback(new Error(`请填写预警通知邮箱`))
}
// 去除首尾空格,并按逗号分割
const emailArray = value.split(',').map(email => email.trim())
if (emailArray.length > 5) {
return callback(new Error(`最多只能填写5个邮箱`))
}
// 邮箱格式正则(基础版)
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
// 检查每个邮箱是否合法
const invalidEmails = emailArray.filter(email => {
return email && !emailRegex.test(email) // 过滤非法邮箱
})
if (invalidEmails.length > 0) {
return callback(new Error(`以下邮箱格式不正确: ${invalidEmails.join(', ')}`))
}
// 可选:检查是否有重复邮箱
const unique = [...new Set(emailArray)]
if (unique.length !== emailArray.length) {
return callback(new Error('存在重复的邮箱地址'))
}
callback() // 验证通过
},
trigger: "blur"
}]
},
}
},
methods: {
handleBlur(event) {
let { usageLimit } = this.infoForm
this.infoForm.usageLimit = usageLimit <= 0 ? '' : usageLimit
},
handleUsageLimitNum(event) {
this.infoForm.usageLimit = limitPrice(event, this.oldVal, 15, 2)
this.oldVal = this.infoForm.usageLimit
},
submit() {
this.$refs.editRef.validate(async (valid) => {
if (valid) {
let { infoForm, authPhone } = this,
params = deepClone(infoForm)
// 提交前清理末尾逗号
params.warningEmail = params.warningEmail.trim().replace(/,+$/, '')
const data = await addFundUsageLimit({
...params,
authPhone
})
if (data) {
this.notice.okTips('新增使用额度成功')
this.$emit('addUsageLimitSuccess')
} else this.notice.errorTips('新增使用额度失败')
}
})
}
}
}
</script>
<style lang="scss" scoped>
.flex {
display: flex;
align-items: center;
}
.detail-content-warn {
::v-deep .el-dialog {
height: 428px;
.el-dialog__body {
// border-bottom: 1px solid #e6e6e6;
}
}
.usage-box {
height: 263px;
.progress-box {
width: 210px;
height: 244px;
::v-deep .el-step__main {
padding: 4px 0 0 18px;
.el-step__title {
font-size: 14px;
}
}
::v-deep .el-step__line {
left: 15px;
background: none;
.el-step__line-inner {
height: 29px !important;
position: absolute;
top: 54px;
}
}
::v-deep .el-step__icon {
width: 32px;
height: 32px;
}
}
.form {
width: calc(100% - 210px);
height: 263px;
.tips {
border-radius: 4px;
opacity: 1;
border: 1px solid #e5e5e5;
background: #fafafa;
color: #666666;
font-size: 13px;
line-height: 20px;
padding: 8px 16px;
margin-bottom: 41px;
}
.usage-limit {
margin-bottom: 70px;
position: relative;
.unit {
position: absolute;
right: 8px;
top: 6px;
color: #333333;
font-size: 14px;
line-height: 20px;
}
}
}
}
}
</style>