Browse Source

feature_20250926_数字题型&单行文本题型

zhujindu 2 months ago
parent
commit
5ec2236948
1 changed files with 31 additions and 11 deletions
  1. 31 11
      src/views/agentList/visitTask.vue

+ 31 - 11
src/views/agentList/visitTask.vue

@@ -153,7 +153,7 @@
               <van-field
                 v-model="item.answerValue"
                 :placeholder="item.text"
-                @blur="SZsizeComparison(item)"></van-field>
+                @blur="SZsizeComparison(item, 'A')"></van-field>
               <p
                 style="color: #444; font-size: 12px; margin: 0; padding: 10px 0; text-align: right">
                 <van-field
@@ -346,7 +346,7 @@
               <van-field
                 v-model="item.answerValue"
                 :formatter="dhwbFormatter"
-                @blur="DHWBsizeComparison(item, index)"
+                @blur="DHWBsizeComparison(item, 'A')"
                 :placeholder="item.text"></van-field>
               <p
                 style="
@@ -3617,8 +3617,18 @@ export default {
       }
     },
     // 数字类型最大值最小值校验
-    SZsizeComparison(item, index) {
-      let value = item.answerValue.replace(
+    SZsizeComparison(item, type) {
+      // type == A 是一级,answerValue 在当前层级,否则在子集collectionOptionList
+      let answerValue = null;
+      let itemData = null;
+      if (type == 'A') {
+        answerValue = item.answerValue;
+        itemData = item;
+      } else {
+        answerValue = item.collectionOptionList[0].answerValue;
+        itemData = item.collectionOptionList[0];
+      }
+      let value = answerValue.replace(
         /[^-\d.]|(?<!\d)\.|\.(?!\d)|^[.]$|^[+-]$|^[+-]\.$|(?<=\.\d*)\.|(?<=\d\.\d*)\.(?=\d)/g,
         ''
       );
@@ -3632,7 +3642,7 @@ export default {
             // this.$toast(
             //   this.collectionItemList[index].collectionName + '最大输入值为:' + maxValue
             // );
-            this.$set(item, 'answerValue', '');
+            this.$set(itemData, 'answerValue', '');
             this.$toast('输入内容不合法');
           }
         }
@@ -3644,15 +3654,25 @@ export default {
             // this.$toast(
             //   this.collectionItemList[index].collectionName + '最小输入值为:' + minValue
             // );
-            this.$set(item, 'answerValue', '');
+            this.$set(itemData, 'answerValue', '');
             this.$toast('输入内容不合法');
           }
         }
       }
     },
     // dhwb 单行文本校验
-    DHWBsizeComparison(item, index) {
-      let value = item.answerValue;
+    DHWBsizeComparison(item, type) {
+      // type == A 是一级,answerValue 在当前层级,否则在子集collectionOptionList
+      let answerValue = null;
+      let itemData = null;
+      if (type == 'A') {
+        answerValue = item.answerValue;
+        itemData = item;
+      } else {
+        answerValue = item.collectionOptionList[0].answerValue;
+        itemData = item.collectionOptionList[0];
+      }
+      let value = answerValue;
       if (value) {
         // 最大值
         let maxValue = item.collectionOptionList[0].maxValue;
@@ -3662,7 +3682,7 @@ export default {
             // this.$toast(
             //   this.collectionItemList[index].collectionName + '最大输入值为:' + maxValue
             // );
-            this.$set(item, 'answerValue', '');
+            this.$set(itemData, 'answerValue', '');
             this.$toast('输入内容不合法');
           }
         }
@@ -3674,7 +3694,7 @@ export default {
             // this.$toast(
             //   this.collectionItemList[index].collectionName + '最小输入值为:' + minValue
             // );
-            this.$set(item, 'answerValue', '');
+            this.$set(itemData, 'answerValue', '');
             this.$toast('输入内容不合法');
           }
         }
@@ -3682,7 +3702,7 @@ export default {
         let leastOneChinese = item.collectionOptionList[0].leastOneChinese;
         if (leastOneChinese == '1') {
           if (!/[\u4e00-\u9fa5]/.test(value)) {
-            this.$set(item, 'answerValue', '');
+            this.$set(itemData, 'answerValue', '');
             this.$toast('输入内容不合法,至少有一个汉字');
           }
         }