seimin vor 2 Jahren
Ursprung
Commit
f720422829

+ 54 - 44
assets/js/controllers/inspect/inspectionScopeCtrl.js

@@ -127,7 +127,7 @@ app.controller("inspectionScope", [
127 127
         templateUrl: "assets/views/system/tpl/inspectionchange.html",
128 128
         controller: function ($scope, scope, $modalInstance) {
129 129
           $scope.add1data = {};
130
-          $scope.thisParent={};//当前点击节点的父节点
130
+          $scope.thisParent = {}; //当前点击节点的父节点
131 131
           $scope.filterTree = function (data, id) {
132 132
             data = angular.copy(data);
133 133
             var newTree = data.filter((x) => x.id !== id);
@@ -144,7 +144,7 @@ app.controller("inspectionScope", [
144 144
               .fetchDataList("inspectionType", data)
145 145
               .then(function (response) {
146 146
                 var data = response.list;
147
-                data = data.filter(v=>!v.parent);//只显示一级
147
+                data = data.filter((v) => !v.parent); //只显示一级
148 148
                 var objects = [];
149 149
                 for (var i = 0; i < data.length; i++) {
150 150
                   var object = {};
@@ -171,7 +171,7 @@ app.controller("inspectionScope", [
171 171
                       (v) => v.id == scope.selectedInspection.tree.id
172 172
                     );
173 173
                     if ($scope.thisParent) {
174
-                      $scope.thisParent.label=$scope.thisParent.type;
174
+                      $scope.thisParent.label = $scope.thisParent.type;
175 175
                       $scope.thisParent.isExpanded = true;
176 176
                       $scope.thisParent.selected = true;
177 177
                       $scope.addparent = true;
@@ -180,13 +180,15 @@ app.controller("inspectionScope", [
180 180
                     }
181 181
                   } else if (type == "edit") {
182 182
                     // 编辑
183
-                    console.log($scope.my_1data,'原始数据')
184
-                    $scope.tree_1data = $scope.my_1data.filter(v=>v.id != scope.selectedInspection.tree.id);//过滤本条
183
+                    console.log($scope.my_1data, "原始数据");
184
+                    $scope.tree_1data = $scope.my_1data.filter(
185
+                      (v) => v.id != scope.selectedInspection.tree.id
186
+                    ); //过滤本条
185 187
                     $scope.thisParent = data.find(
186 188
                       (v) => v.id == scope.selectedInspection.tree.pId
187 189
                     );
188 190
                     if ($scope.thisParent) {
189
-                      $scope.thisParent.label=$scope.thisParent.type;
191
+                      $scope.thisParent.label = $scope.thisParent.type;
190 192
                       $scope.thisParent.isExpanded = true;
191 193
                       $scope.thisParent.selected = true;
192 194
                       $scope.addparent = true;
@@ -254,7 +256,7 @@ app.controller("inspectionScope", [
254 256
             if (data && data.type) {
255 257
               if ($scope.addparent) {
256 258
                 data.parent = $scope.add1data.parent;
257
-              }else{
259
+              } else {
258 260
                 data.parent = null;
259 261
               }
260 262
               scope.selectedInspection.tree = {};
@@ -664,6 +666,10 @@ app.controller("inspectionScope", [
664 666
     $scope.changecateObj = {
665 667
       changecate: false,
666 668
     };
669
+    // 缓存的绑定数据-http
670
+    $scope.cacheHttp = {
671
+      value: [],
672
+    };
667 673
   },
668 674
 ]);
669 675
 app.directive("zTree", function () {
@@ -674,6 +680,8 @@ app.directive("zTree", function () {
674 680
       selectInspectionType: "=",
675 681
       copyInspectionType: "=",
676 682
       stateModel: "=",
683
+      changecate: "=",
684
+      cachehttp: "=",
677 685
     },
678 686
     controller: function ($scope, $element, api_bpm_data, api_simple) {
679 687
       console.log($scope);
@@ -722,6 +730,7 @@ app.directive("zTree", function () {
722 730
                 $scope.isShowZtree = true;
723 731
 
724 732
                 var result = response.list || [];
733
+                $scope.cachehttp = angular.copy(result);
725 734
                 result = result.map((v) => v.inspectionType);
726 735
                 console.log(result);
727 736
                 result.forEach((v, i) => {
@@ -822,10 +831,10 @@ app.directive("zTree", function () {
822 831
         console.log(event, treeId, treeNode);
823 832
         $scope.selectInspectionType = treeNode;
824 833
       }
825
-      $scope.isFirstGet = false;
826 834
       // 点击复选框
827 835
       function zTreeOnCheck(event, treeId, treeNode) {
828 836
         console.log(event, treeId, treeNode);
837
+        $scope.changecate = false;
829 838
         var treeObj = $.fn.zTree.getZTreeObj("z-tree");
830 839
         var nodes_arr = treeObj.getCheckedNodes(true);
831 840
         var nodes = angular.copy(nodes_arr);
@@ -841,8 +850,10 @@ app.directive("zTree", function () {
841 850
             }
842 851
           });
843 852
         });
844
-        if (treeNode.checked && $scope.isFirstGet) {
845
-          //如果勾选上
853
+        if ($scope.cachehttp && $scope.cachehttp.length) {
854
+          var result = angular.copy($scope.cachehttp);
855
+          zTreeOnCheckCommon(result, nodes);
856
+        } else {
846 857
           api_simple
847 858
             .fetchDataList("inspectionBind", {
848 859
               idx: 0,
@@ -850,43 +861,42 @@ app.directive("zTree", function () {
850 861
               inspectionBind: { inspection: { id: $scope.stateModel.id } },
851 862
             })
852 863
             .then(function (response) {
853
-              $scope.isFirstGet = true;
854 864
               var result = response.list || [];
855
-              result = result.map((v) => ({
856
-                id: v.inspectionType,
857
-                name: v.inspectionTypeName,
858
-                group: v.group,
859
-                user: v.user,
860
-                parent: v.parent ? { id: v.parent.inspectionType } : undefined,
861
-                pId: v.parent ? v.parent.inspectionType : 0,
862
-              }));
863
-
864
-              for (var i = 0; i < nodes.length; i++) {
865
-                for (var j = 0; j < result.length; j++) {
866
-                  if (nodes[i].id == result[j].id) {
867
-                    nodes[i] = angular.copy(result[j]);
868
-                  }
869
-                }
870
-              }
871
-              var arr = nodes.filter((v) => v.pId === 0);
872
-              arr.forEach((v) => {
873
-                v.children = [];
874
-              });
875
-              arr.forEach((v, i) => {
876
-                nodes.forEach((vv) => {
877
-                  if (vv.pId == v.id) {
878
-                    arr[i].children.push(vv);
879
-                  }
880
-                });
881
-              });
882
-              console.log(arr);
883
-              $scope.copyInspectionType = arr;
865
+              zTreeOnCheckCommon(result, nodes);
884 866
             });
885
-        } else {
886
-          // 取消勾选
887
-          $scope.copyInspectionType = arr;
888 867
         }
889
-        // console.log(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
868
+      }
869
+      // 点击复选框-common
870
+      function zTreeOnCheckCommon(result, nodes) {
871
+        result = result.map((v) => ({
872
+          id: v.inspectionType,
873
+          name: v.inspectionTypeName,
874
+          group: v.group,
875
+          user: v.user,
876
+          parent: v.parent ? { id: v.parent.inspectionType } : undefined,
877
+          pId: v.parent ? v.parent.inspectionType : 0,
878
+        }));
879
+
880
+        for (var i = 0; i < nodes.length; i++) {
881
+          for (var j = 0; j < result.length; j++) {
882
+            if (nodes[i].id == result[j].id) {
883
+              nodes[i] = angular.copy(result[j]);
884
+            }
885
+          }
886
+        }
887
+        var arr = nodes.filter((v) => v.pId === 0);
888
+        arr.forEach((v) => {
889
+          v.children = [];
890
+        });
891
+        arr.forEach((v, i) => {
892
+          nodes.forEach((vv) => {
893
+            if (vv.pId == v.id) {
894
+              arr[i].children.push(vv);
895
+            }
896
+          });
897
+        });
898
+        console.log(arr);
899
+        $scope.copyInspectionType = arr;
890 900
       }
891 901
     },
892 902
   };

+ 1 - 1
assets/views/inspect/inspectionScope.html

@@ -499,7 +499,7 @@
499 499
             </div>
500 500
             <div class="leftBox">
501 501
                 <!-- <span ng-if="!selectedInspection.isShowZtree">...加载中...</span> -->
502
-                <z-tree ng-if="selectedInspection.isShowZtree" id="z-tree" class="ztree" select-inspection-type="selectedInspection.tree" copy-inspection-type="copyInspection.tree" state-model="stateModel"></z-tree>
502
+                <z-tree ng-if="selectedInspection.isShowZtree" id="z-tree" class="ztree" select-inspection-type="selectedInspection.tree" copy-inspection-type="copyInspection.tree" state-model="stateModel" changecate="changecateObj.changecate" cachehttp="cacheHttp.value"></z-tree>
503 503
                 <!-- <abn-tree tree-data="my_1data" tree-control="my_tree" on-select="my_tree_1handler(branch)" expand-level="2" icon-leaf="iconfont icon-fenlei" icon-expand="ti-plus" icon-collapse="ti-minus"></abn-tree> -->
504 504
             </div>
505 505
         </div>