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,
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 - this.validateWeight(target.value, "minWeight");
25 - },
26 - // 最大重量失焦事件
27 - inputBlurMaxWeight({ target }) {
28 - this.validateWeight(target.value, "maxWeight");
29 - },
30 - // 最小申报价值
31 - inputBlurMin({ target }, customVal) {
32 - this.validateCustomVal(target.value, customVal);
33 - },
34 - // 最大申报价值
35 - inputBlurMax({ target }, customVal) {
36 - this.validateCustomVal(target.value, customVal);
37 - },
38 - // 校验件数方法 【件数可以为空但件数不得为0】只能输入正整数
39 - validateNumOfPieces(value, pieces) {
40 - if (value.toString().length) {
41 - // 获取当前输入框有值的情况下
42 - this.queryForm[pieces] = Number(value);
43 - let markPieces = false;
44 - if (pieces == "minNumOfPieces" || pieces == "maxNumOfPieces") {
45 - // 最大件数和最小件数都不为空的情况下
46 - if (
47 - this.queryForm.minNumOfPieces.toString() != "" &&
48 - this.queryForm.maxNumOfPieces.toString() != ""
49 - ) {
50 - this.validateForm = true;
51 - this.$refs.minNumOfPieces.innerHTML = "";
52 - markPieces = true;
53 - } else {
54 - markPieces = false;
55 - }
56 - }
57 - if (/^\d+$/.test(this.queryForm[pieces])) {
58 - if (markPieces) {
59 - //当最大件数和最小件数都不为空的情况下,最大件数小于最小件数的时候
60 - if (this.queryForm.maxNumOfPieces < this.queryForm.minNumOfPieces) {
61 - if (Array.isArray(this.$refs.minNumOfPieces)) {
62 - this.msgError("最小件数不得大于最大件数");
63 - this.validateForm = false;
64 - } else {
65 - this.$refs.minNumOfPieces.innerHTML = "";
66 - this.$refs.minNumOfPieces.innerHTML =
67 - "最小件数不得大于最大件数";
68 - this.validateForm = false;
69 - }
70 - }
71 - //当最大件数和最小件数都不为空的情况下,最大件数和最小件数小于1的时候
72 - else if (
73 - this.queryForm.minNumOfPieces < 1 ||
74 - this.queryForm.maxNumOfPieces < 1
75 - ) {
76 - if (Array.isArray(this.$refs.minNumOfPieces)) {
77 - this.msgError("最小件数和最大件数不能小于1");
78 - this.validateForm = false;
79 - } else {
80 - this.$refs.minNumOfPieces.innerHTML = "";
81 - this.$refs.minNumOfPieces.innerHTML =
82 - "最小件数和最大件数不能小于1";
83 - this.validateForm = false;
84 - }
85 - }
86 - //当最大件数和最小件数都不为空的情况下,最大件数和最小件数满足大于1左区间小于等于右区间的时候
87 - else {
88 - this.$refs.minNumOfPieces.innerHTML = "";
89 - this.validateForm = true;
90 - }
91 - } else {
92 - // 当左右区间其中一个有值的情况下
93 - if (value.length) {
94 - if (Number(value) < 1) {
95 - if (Array.isArray(this.$refs.minNumOfPieces)) {
96 - this.msgError("件数不得小于1");
97 - this.$refs.minNumOfPieces.innerHTML = "";
98 - this.$refs.minNumOfPieces.innerHTML = "件数不得小于1";
99 - this.validateForm = false;
100 - } else {
101 - this.msgError("件数不得小于1");
102 - this.$refs.minNumOfPieces.innerHTML = "";
103 - this.$refs.minNumOfPieces.innerHTML = "件数不得小于1";
104 - this.validateForm = false;
105 - }
106 - } else {
107 - if (!Array.isArray(this.$refs.minNumOfPieces)) {
108 - this.$refs.minNumOfPieces.innerHTML = "";
109 - this.validateForm = true;
110 - }
111 - }
112 - }
113 - }
114 - } else {
115 - if (Array.isArray(this.$refs.minNumOfPieces)) {
116 - this.msgError("请输入有效件数");
117 - } else {
118 - this.$refs.minNumOfPieces.innerHTML = "";
119 - this.$refs.minNumOfPieces.innerHTML = "请输入有效件数";
120 - }
121 - this.validateForm = false;
122 - }
123 - } else {
124 - // 【左右区间不是都有值的情况下】
125 - // 最小件数为空最大件数有值的情况下
126 - if (pieces == "minNumOfPieces" && this.queryForm.maxNumOfPieces > 0) {
127 - this.$refs.minNumOfPieces.innerHTML = "";
128 - this.validateForm = true;
129 - } else {
130 - this.$refs.minNumOfPieces.innerHTML = "";
131 - this.$refs.minNumOfPieces.innerHTML = "最大件数不得小于1";
132 - this.validateForm = false;
133 - }
134 - // 最大件数为空最小件数有值的情况下
135 - if (pieces == "maxNumOfPieces" && this.queryForm.minNumOfPieces > 0) {
136 - this.$refs.minNumOfPieces.innerHTML = "";
137 - this.validateForm = true;
138 - } else {
139 - this.$refs.minNumOfPieces.innerHTML = "";
140 - this.validateForm = true;
141 - }
142 - // 左右区间 都为空的情况下
143 - if (
144 - this.queryForm.minNumOfPieces.toString().length == 0 &&
145 - this.queryForm.maxNumOfPieces.toString().length == 0
146 - ) {
147 - this.$refs.minNumOfPieces.innerHTML = "";
148 - this.validateForm = true;
149 - }
150 - }
151 - return this.validateForm;
152 - },
153 - // 校验重量方法 【重量可以为空为0 && 最小/大重量的范围0~34KG】允许保留1~5位小数。
154 - validateWeight(value, weight) {
155 - if (value.length) {
156 - this.queryForm[weight] = Number(value);
157 - let markWeight = false;
158 - if (weight == "minWeight" || weight == "maxWeight") {
159 - if (this.queryForm.minWeight && this.queryForm.maxWeight) {
160 - markWeight =
161 - Number(this.queryForm.maxWeight) <
162 - Number(this.queryForm.minWeight);
163 - }
164 - }
165 - if (/^(0|[1-9]\d*)(.\d{1,5})?$/.test(this.queryForm[weight])) {
166 - if (this.queryForm[weight] >= 0) {
167 - if (markWeight) {
168 - if (Array.isArray(this.$refs.minWeight)) {
169 - this.validateForm = false;
170 - this.msgError("最小重量不得大于最大重量");
171 - } else {
172 - this.validateForm = false;
173 - this.$refs.minWeight.innerHTML = "";
174 - this.$refs.minWeight.innerHTML = "最小重量不得大于最大重量";
175 - }
176 - } else if (this.queryForm[weight] > 34) {
177 - this.validateForm = false;
178 - if (Array.isArray(this.$refs.minWeight)) {
179 - this.msgError("最大重量不能大于34KG");
180 - } else {
181 - this.validateForm = false;
182 - this.$refs.minWeight.innerHTML = "";
183 - this.$refs.minWeight.innerHTML = "最大重量不能大于34KG";
184 - }
185 - } else {
186 - if (!Array.isArray(this.$refs.minWeight)) {
187 - this.validateForm = true;
188 - this.$refs.minWeight.innerHTML = "";
189 - }
190 - }
191 - } else {
192 - if (value.length) {
193 - if (Number(value) > 34) {
194 - if (Array.isArray(this.$refs.minWeight)) {
195 - this.validateForm = false;
196 - this.msgError("最大重量不能大于34KG");
197 - } else {
198 - this.validateForm = false;
199 - this.$refs.minWeight.innerHTML = "";
200 - this.$refs.minWeight.innerHTML = "最大重量不能大于34KG";
201 - }
202 - } else {
203 - if (!Array.isArray(this.$refs.minWeight)) {
204 - this.validateForm = true;
205 - this.$refs.minWeight.innerHTML = "";
206 - }
207 - }
208 - }
209 - }
210 - } else {
211 - if (Array.isArray(this.$refs.minWeight)) {
212 - this.validateForm = false;
213 - this.msgError("请输入正整数,小数保留5位");
214 - } else {
215 - this.validateForm = false;
216 - this.$refs.minWeight.innerHTML = "";
217 - this.$refs.minWeight.innerHTML = "请输入正整数,小数保留5位";
218 - }
219 - }
220 - } else {
221 - this.validateForm = true;
222 - this.$refs.minWeight.innerHTML = "";
223 - }
224 - return this.validateForm;
225 - },
226 - // 报价值【申报价值可以为空为0】
227 - validateCustomVal(value, customVal) {
228 - let coin = {
229 - minCNYCustomVal: "minCNYCustomVal",
230 - maxCNYCustomVal: "minCNYCustomVal",
231 - minSUDCustomVal: "minSUDCustomVal",
232 - maxSUDCustomVal: "minSUDCustomVal",
233 - };
234 - let currency = {
235 - minCNYCustomVal: 2000,
236 - maxCNYCustomVal: 2000,
237 - minSUDCustomVal: 600,
238 - maxSUDCustomVal: 600,
239 - };
240 - let markCoin = false;
241 - if (value.length) {
242 - this[customVal] = Number(value);
243 - // 其中一个有值的情况下人民币
244 - if (customVal == "minCNYCustomVal" || customVal == "maxCNYCustomVal") {
245 - if (this.minCNYCustomVal && this.maxCNYCustomVal) {
246 - this.validateForm = false;
247 - markCoin =
248 - Number(this.maxCNYCustomVal) < Number(this.minCNYCustomVal);
249 - } else {
250 - this.validateForm = true;
251 - this.$refs[coin[customVal]].innerHTML = "";
252 - }
253 - }
254 - // 都有值的情况下美元
255 - else {
256 - if (this.minSUDCustomVal && this.maxSUDCustomVal) {
257 - this.validateForm = false;
258 - markCoin =
259 - Number(this.maxSUDCustomVal) < Number(this.minSUDCustomVal);
260 - }
261 - }
262 - if (/^(0|[1-9]\d*)(.\d{1,2})?$/.test(this[customVal])) {
263 - if (this[customVal] >= 0) {
264 - if (markCoin) {
265 - this.validateForm = false;
266 - this.$refs[coin[customVal]].innerHTML = "";
267 - this.$refs[coin[customVal]].innerHTML =
268 - "最小申报价值不得大于最大申报价值";
269 - }
270 - // 判断申报价值不得大于上限
271 - // else if (this[customVal] > currency[customVal]) {
272 - // this.validateForm = false;
273 - // this.$refs[coin[customVal]].innerHTML = "";
274 - // this.$refs[
275 - // coin[customVal]
276 - // ].innerHTML = `最大申报值不得大于${currency[customVal]}`;
277 - // } else {
278 - // this.validateForm = true;
279 - // this.$refs[coin[customVal]].innerHTML = "";
280 - // }
281 - }
282 - } else {
283 - this.validateForm = false;
284 - this.$refs[coin[customVal]].innerHTML = "";
285 - this.$refs[coin[customVal]].innerHTML = "请输入正确申报价值";
286 - }
287 - } else {
288 - this.validateForm = true;
289 - this.$refs[coin[customVal]].innerHTML = "";
290 - }
291 - return this.validateForm;
292 - },
293 - },
294 -};