Browse Source

添加递归遍历所有表单项方法

sunny 3 weeks ago
parent
commit
7e5b22a685
1 changed files with 16 additions and 11 deletions
  1. 16 11
      src/views/deviceWithin/addStoreVisit.vue

+ 16 - 11
src/views/deviceWithin/addStoreVisit.vue

@@ -5638,6 +5638,21 @@ export default {
         }
       }
     },
+    // 递归遍历所有表单项
+    traverseCollectionItems(items) {
+      // 处理一层子项(如果有)
+      if (items.collectionOptionList && items.collectionOptionList.length > 0) {
+        items.collectionOptionList.forEach((item) => {
+          // 处理二层子项(如果有)
+          if (item.collectionItems && item.collectionItems.length > 0) {
+            item.collectionItems.forEach((option) => {
+              this.filterCollectionInfos(option);
+              this.traverseCollectionItems(option);
+            });
+          }
+        });
+      }
+    },
     onSubmit() {
       this.validatorFlag = true;
       var checkUnManage = 'Y';
@@ -5679,17 +5694,7 @@ export default {
         for (var b = 0; b < this.collectionItemList.length; b++) {
           this.filterCollectionInfos(this.collectionItemList[b], 'A');
           const collectionItem = this.collectionItemList[b];
-          if (collectionItem.collectionOptionList) {
-            for (let c = 0; c < collectionItem.collectionOptionList.length; c++) {
-              const collectionOption = collectionItem.collectionOptionList[c];
-              this.filterCollectionInfos(collectionOption);
-              if (collectionOption.collectionItems) { 
-                for (let d = 0; d < collectionOption.collectionItems.length; d++) {
-                    this.filterCollectionInfos(collectionOption.collectionItems[d]);
-                }
-              }
-            }
-          }
+          this.traverseCollectionItems(collectionItem);
           if (
             this.collectionItemList[b].answerType == 'sz' ||
             this.collectionItemList[b].answerType == 'sm' ||