Elements-SY

modify

1 +export const inputBlurValidate = {
2 + data() {
3 + return {
4 + queryForm: {
5 + minWeight: "",
6 + maxWeight: "",
7 + minNumOfPieces: "",
8 + maxNumOfPieces: "",
9 + },
10 + validateForm: true, // form表单节流阀
11 + };
12 + },
13 + methods: {
14 + // 最小件数失焦事件
15 + inputBlurMinPieces({ target }) {
16 + this.validateNumOfPieces(target.value, "minNumOfPieces");
17 + },
18 + // 最大件数失焦事件
19 + inputBlurMaxPieces({ target }) {
20 + this.validateNumOfPieces(target.value, "maxNumOfPieces");
21 + },
22 + // 最小重量失焦事件
23 + inputBlurMinWeight({ target }) {
24 + // 重量最小值和最大值都为空的情况下
25 + if (this.queryForm.minWeight == "" && this.queryForm.maxWeight == "") {
26 + this.validateForm = true;
27 + this.$refs.minWeight.innerHTML = "";
28 + }
29 + // 鼠标聚焦最小重量,最小重量无值的情况下去校验最大重量
30 + if (target.value == "" && this.queryForm.maxWeight) {
31 + if (
32 + /^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(this.queryForm.maxWeight))
33 + ) {
34 + this.validateForm = true;
35 + this.$refs.minWeight.innerHTML = "";
36 + }
37 + }
38 + // 最小重量有值的情况下
39 + if (target.value && Number(target.value) >= 0) {
40 + if (/^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(target.value))) {
41 + if (this.queryForm.maxWeight) {
42 + if (
43 + Number(this.queryForm.maxWeight) <
44 + Number(this.queryForm.minWeight)
45 + ) {
46 + this.validateForm = false;
47 + this.$refs.minWeight.innerHTML = "最小重量不得大于最大重量";
48 + } else if (
49 + /^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(this.queryForm.maxWeight))
50 + ) {
51 + this.validateForm = true;
52 + this.$refs.minWeight.innerHTML = "";
53 + } else {
54 + this.validateForm = false;
55 + this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
56 + }
57 + } else {
58 + this.validateForm = true;
59 + this.$refs.minWeight.innerHTML = "";
60 + }
61 + } else {
62 + this.validateForm = false;
63 + this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
64 + }
65 + }
66 + },
67 + // 最大重量失焦事件
68 + inputBlurMaxWeight({ target }) {
69 + // 重量最小值和最大值都为空的情况下
70 + if (this.queryForm.minWeight == "" && this.queryForm.maxWeight == "") {
71 + this.validateForm = true;
72 + this.$refs.minWeight.innerHTML = "";
73 + }
74 + // 鼠标聚焦最大重量,最大重量无值的情况下去校验最小重量
75 + if (target.value == "" && this.queryForm.minWeight) {
76 + if (
77 + /^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(this.queryForm.minWeight))
78 + ) {
79 + this.validateForm = true;
80 + this.$refs.minWeight.innerHTML = "";
81 + } else {
82 + this.validateForm = false;
83 + this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
84 + // this.msgError("请输入有效重量,小数保留5位");
85 + }
86 + }
87 + if (target.value && Number(target.value) >= 0) {
88 + if (/^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(target.value))) {
89 + if (this.queryForm.minWeight) {
90 + if (
91 + Number(this.queryForm.maxWeight) <
92 + Number(this.queryForm.minWeight)
93 + ) {
94 + this.validateForm = false;
95 + this.$refs.minWeight.innerHTML = "最小重量不得大于最大重量";
96 + } else if (
97 + /^(0|[1-9]\d*)(.\d{1,5})?$/.test(Number(this.queryForm.minWeight))
98 + ) {
99 + this.validateForm = true;
100 + this.$refs.minWeight.innerHTML = "";
101 + } else {
102 + this.validateForm = false;
103 + this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
104 + }
105 + } else {
106 + this.validateForm = true;
107 + this.$refs.minWeight.innerHTML = "";
108 + }
109 + } else {
110 + this.validateForm = false;
111 + this.$refs.minWeight.innerHTML = "请输入有效重量,小数保留5位";
112 + }
113 + }
114 + },
115 + // 人民币最小申报价值
116 + inputCNYBlurMin({ target }, customVal) {
117 + // 申报价值最小值和最大值都为空的情况下
118 + if (
119 + this.queryForm.minCustomVal == "" &&
120 + this.queryForm.maxCustomVal == ""
121 + ) {
122 + this.validateForm = true;
123 + this.$refs.minCNYCustomVal.innerHTML = "";
124 + }
125 + // 鼠标聚焦最小申报价值,最小申报价值无值的情况下去校验最大申报价值
126 + if (target.value == "" && this.queryForm.maxCustomVal) {
127 + if (
128 + /^(0|[1-9]\d*)(.\d{1,2})?$/.test(Number(this.queryForm.maxCustomVal))
129 + ) {
130 + this.validateForm = true;
131 + this.$refs.minCNYCustomVal.innerHTML = "";
132 + }
133 + }
134 + // 最小申报价值有值的情况下
135 + if (target.value && Number(target.value) >= 0) {
136 + if (/^(0|[1-9]\d*)(.\d{1,2})?$/.test(Number(target.value))) {
137 + if (this.queryForm.maxCustomVal) {
138 + if (
139 + Number(this.queryForm.maxCustomVal) <
140 + Number(this.queryForm.minCustomVal)
141 + ) {
142 + this.validateForm = false;
143 + this.$refs.minCNYCustomVal.innerHTML =
144 + "最小申报价值不得大于最大申报价值";
145 + } else if (
146 + /^(0|[1-9]\d*)(.\d{1,2})?$/.test(
147 + Number(this.queryForm.maxCustomVal)
148 + )
149 + ) {
150 + this.validateForm = true;
151 + this.$refs.minCNYCustomVal.innerHTML = "";
152 + } else {
153 + this.validateForm = false;
154 + this.$refs.minCNYCustomVal.innerHTML =
155 + "请输入有效申报价值,小数保留2位";
156 + }
157 + } else {
158 + this.validateForm = true;
159 + this.$refs.minCNYCustomVal.innerHTML = "";
160 + }
161 + } else {
162 + this.validateForm = false;
163 + this.$refs.minCNYCustomVal.innerHTML =
164 + "请输入有效申报价值,小数保留2位";
165 + }
166 + }
167 + },
168 + // 人民币最大申报价值
169 + inputCNYBlurMax({ target }, customVal) {
170 + // 申报价值最小值和最大值都为空的情况下
171 + if (
172 + this.queryForm.minCustomVal == "" &&
173 + this.queryForm.maxCustomVal == ""
174 + ) {
175 + this.validateForm = true;
176 + this.$refs.minCNYCustomVal.innerHTML = "";
177 + }
178 + // 鼠标聚焦最大申报价值,最大申报价值无值的情况下去校验最小申报价值
179 + if (target.value == "" && this.queryForm.minCustomVal) {
180 + if (
181 + /^(0|[1-9]\d*)(.\d{1,2})?$/.test(Number(this.queryForm.minCustomVal))
182 + ) {
183 + this.validateForm = true;
184 + this.$refs.minCNYCustomVal.innerHTML = "";
185 + } else {
186 + this.validateForm = false;
187 + this.$refs.minCNYCustomVal.innerHTML =
188 + "请输入有效申报价值,小数保留2位";
189 + }
190 + }
191 + // 最大申报价值有值的情况下
192 + if (target.value && Number(target.value) >= 0) {
193 + if (/^(0|[1-9]\d*)(.\d{1,2})?$/.test(Number(target.value))) {
194 + if (this.queryForm.minCustomVal) {
195 + if (
196 + Number(this.queryForm.maxCustomVal) <
197 + Number(this.queryForm.minCustomVal)
198 + ) {
199 + this.validateForm = false;
200 + this.$refs.minCNYCustomVal.innerHTML =
201 + "最小申报价值不得大于最大申报价值";
202 + } else if (
203 + /^(0|[1-9]\d*)(.\d{1,2})?$/.test(
204 + Number(this.queryForm.minCustomVal)
205 + )
206 + ) {
207 + this.validateForm = true;
208 + this.$refs.minCNYCustomVal.innerHTML = "";
209 + } else {
210 + this.validateForm = false;
211 + this.$refs.minCNYCustomVal.innerHTML =
212 + "请输入有效申报价值,小数保留2位";
213 + }
214 + }
215 + } else {
216 + this.validateForm = false;
217 + this.$refs.minCNYCustomVal.innerHTML =
218 + "请输入有效申报价值,小数保留2位";
219 + }
220 + }
221 + },
222 + // 美元最小申报价值
223 + inputSUDBlurMin({ target }, customVal) {
224 + // 申报价值最小值和最大值都为空的情况下
225 + if (
226 + this.queryForm.minUsdCustomVal == "" &&
227 + this.queryForm.maxUsdCustomVal == ""
228 + ) {
229 + this.validateForm = true;
230 + this.$refs.minSUDCustomVal.innerHTML = "";
231 + }
232 + // 鼠标聚焦最小申报价值,最小申报价值无值的情况下去校验最大申报价值
233 + if (target.value == "" && this.queryForm.maxUsdCustomVal) {
234 + if (
235 + /^(0|[1-9]\d*)(.\d{1,2})?$/.test(
236 + Number(this.queryForm.maxUsdCustomVal)
237 + )
238 + ) {
239 + this.validateForm = true;
240 + this.$refs.minSUDCustomVal.innerHTML = "";
241 + }
242 + }
243 + // 最小申报价值有值的情况下
244 + if (target.value && Number(target.value) >= 0) {
245 + if (/^(0|[1-9]\d*)(.\d{1,2})?$/.test(Number(target.value))) {
246 + if (this.queryForm.maxUsdCustomVal) {
247 + if (
248 + Number(this.queryForm.maxUsdCustomVal) <
249 + Number(this.queryForm.minUsdCustomVal)
250 + ) {
251 + this.validateForm = false;
252 + this.$refs.minSUDCustomVal.innerHTML =
253 + "最小申报价值不得大于最大申报价值";
254 + } else if (
255 + /^(0|[1-9]\d*)(.\d{1,2})?$/.test(
256 + Number(this.queryForm.maxUsdCustomVal)
257 + )
258 + ) {
259 + this.validateForm = true;
260 + this.$refs.minSUDCustomVal.innerHTML = "";
261 + } else {
262 + this.validateForm = false;
263 + this.$refs.minSUDCustomVal.innerHTML =
264 + "请输入有效申报价值,小数保留2位";
265 + }
266 + } else {
267 + this.validateForm = true;
268 + this.$refs.minSUDCustomVal.innerHTML = "";
269 + }
270 + } else {
271 + this.validateForm = false;
272 + this.$refs.minSUDCustomVal.innerHTML =
273 + "请输入有效申报价值,小数保留2位";
274 + }
275 + }
276 + },
277 + // 美元最大申报价值
278 + inputSUDBlurMax({ target }, customVal) {
279 + // 申报价值最小值和最大值都为空的情况下
280 + if (
281 + this.queryForm.minUsdCustomVal == "" &&
282 + this.queryForm.maxUsdCustomVal == ""
283 + ) {
284 + this.validateForm = true;
285 + this.$refs.minSUDCustomVal.innerHTML = "";
286 + }
287 + // 鼠标聚焦最大申报价值,最大申报价值无值的情况下去校验最小申报价值
288 + if (target.value == "" && this.queryForm.minUsdCustomVal) {
289 + if (
290 + /^(0|[1-9]\d*)(.\d{1,2})?$/.test(
291 + Number(this.queryForm.minUsdCustomVal)
292 + )
293 + ) {
294 + this.validateForm = true;
295 + this.$refs.minSUDCustomVal.innerHTML = "";
296 + } else {
297 + this.validateForm = false;
298 + this.$refs.minSUDCustomVal.innerHTML =
299 + "请输入有效申报价值,小数保留2位";
300 + }
301 + }
302 + // 最大申报价值有值的情况下
303 + if (target.value && Number(target.value) >= 0) {
304 + if (/^(0|[1-9]\d*)(.\d{1,2})?$/.test(Number(target.value))) {
305 + if (this.queryForm.minUsdCustomVal) {
306 + if (
307 + Number(this.queryForm.maxUsdCustomVal) <
308 + Number(this.queryForm.minUsdCustomVal)
309 + ) {
310 + this.validateForm = false;
311 + this.$refs.minSUDCustomVal.innerHTML =
312 + "最小申报价值不得大于最大申报价值";
313 + } else if (
314 + /^(0|[1-9]\d*)(.\d{1,2})?$/.test(
315 + Number(this.queryForm.minUsdCustomVal)
316 + )
317 + ) {
318 + this.validateForm = true;
319 + this.$refs.minSUDCustomVal.innerHTML = "";
320 + } else {
321 + this.validateForm = false;
322 + this.$refs.minSUDCustomVal.innerHTML =
323 + "请输入有效申报价值,小数保留2位";
324 + }
325 + }
326 + } else {
327 + this.validateForm = false;
328 + this.$refs.minSUDCustomVal.innerHTML =
329 + "请输入有效申报价值,小数保留2位";
330 + }
331 + }
332 + },
333 + // 校验件数方法 【件数可以为空但件数不得为0】只能输入正整数
334 + validateNumOfPieces(value, pieces) {
335 + if (value.toString().length) {
336 + // 获取当前输入框有值的情况下
337 + this.queryForm[pieces] = Number(value);
338 + let markPieces = false;
339 + if (pieces == "minNumOfPieces" || pieces == "maxNumOfPieces") {
340 + // 最大件数和最小件数都不为空的情况下
341 + if (
342 + this.queryForm.minNumOfPieces.toString() != "" &&
343 + this.queryForm.maxNumOfPieces.toString() != ""
344 + ) {
345 + this.validateForm = true;
346 + this.$refs.minNumOfPieces.innerHTML = "";
347 + markPieces = true;
348 + } else {
349 + markPieces = false;
350 + }
351 + }
352 + if (/^\d+$/.test(this.queryForm[pieces])) {
353 + if (markPieces) {
354 + //当最大件数和最小件数都不为空的情况下,最大件数小于最小件数的时候
355 + if (this.queryForm.maxNumOfPieces < this.queryForm.minNumOfPieces) {
356 + if (Array.isArray(this.$refs.minNumOfPieces)) {
357 + this.msgError("最小件数不得大于最大件数");
358 + this.validateForm = false;
359 + } else {
360 + this.$refs.minNumOfPieces.innerHTML = "";
361 + this.$refs.minNumOfPieces.innerHTML =
362 + "最小件数不得大于最大件数";
363 + this.validateForm = false;
364 + }
365 + }
366 + //当最大件数和最小件数都不为空的情况下,最大件数和最小件数小于1的时候
367 + else if (
368 + this.queryForm.minNumOfPieces < 1 ||
369 + this.queryForm.maxNumOfPieces < 1
370 + ) {
371 + if (Array.isArray(this.$refs.minNumOfPieces)) {
372 + this.msgError("最小件数和最大件数不能小于1");
373 + this.validateForm = false;
374 + } else {
375 + this.$refs.minNumOfPieces.innerHTML = "";
376 + this.$refs.minNumOfPieces.innerHTML =
377 + "最小件数和最大件数不能小于1";
378 + this.validateForm = false;
379 + }
380 + }
381 + //当最大件数和最小件数都不为空的情况下,最大件数和最小件数满足大于1左区间小于等于右区间的时候
382 + else {
383 + this.$refs.minNumOfPieces.innerHTML = "";
384 + this.validateForm = true;
385 + }
386 + } else {
387 + // 当左右区间其中一个有值的情况下
388 + if (value.length) {
389 + if (Number(value) < 1) {
390 + if (Array.isArray(this.$refs.minNumOfPieces)) {
391 + this.msgError("件数不得小于1");
392 + this.$refs.minNumOfPieces.innerHTML = "";
393 + this.$refs.minNumOfPieces.innerHTML = "件数不得小于1";
394 + this.validateForm = false;
395 + } else {
396 + this.msgError("件数不得小于1");
397 + this.$refs.minNumOfPieces.innerHTML = "";
398 + this.$refs.minNumOfPieces.innerHTML = "件数不得小于1";
399 + this.validateForm = false;
400 + }
401 + } else {
402 + if (!Array.isArray(this.$refs.minNumOfPieces)) {
403 + this.$refs.minNumOfPieces.innerHTML = "";
404 + this.validateForm = true;
405 + }
406 + }
407 + }
408 + }
409 + } else {
410 + if (Array.isArray(this.$refs.minNumOfPieces)) {
411 + this.msgError("请输入有效件数");
412 + } else {
413 + this.queryForm[pieces] = value;
414 + this.$refs.minNumOfPieces.innerHTML = "";
415 + this.$refs.minNumOfPieces.innerHTML = "请输入有效件数";
416 + }
417 + this.validateForm = false;
418 + }
419 + } else {
420 + // 【左右区间不是都有值的情况下】
421 + // 最小件数为空最大件数有值的情况下
422 + if (pieces == "minNumOfPieces" && this.queryForm.maxNumOfPieces > 0) {
423 + this.$refs.minNumOfPieces.innerHTML = "";
424 + this.validateForm = true;
425 + } else {
426 + this.$refs.minNumOfPieces.innerHTML = "";
427 + this.$refs.minNumOfPieces.innerHTML = "最大件数不得小于1";
428 + this.validateForm = false;
429 + }
430 + // 最大件数为空最小件数有值的情况下
431 + if (pieces == "maxNumOfPieces" && this.queryForm.minNumOfPieces > 0) {
432 + this.$refs.minNumOfPieces.innerHTML = "";
433 + this.validateForm = true;
434 + } else {
435 + this.$refs.minNumOfPieces.innerHTML = "";
436 + this.validateForm = true;
437 + }
438 + // 左右区间 都为空的情况下
439 + if (
440 + this.queryForm.minNumOfPieces.toString().length == 0 &&
441 + this.queryForm.maxNumOfPieces.toString().length == 0
442 + ) {
443 + this.$refs.minNumOfPieces.innerHTML = "";
444 + this.validateForm = true;
445 + }
446 + }
447 + return this.validateForm;
448 + },
449 + },
450 +};