Explorar o código

单位、人员、测温记录增加用户关联单位查询条件。

zhengqiang %!s(int64=4) %!d(string=hai) anos
pai
achega
55ac025d6e

+ 35 - 9
src/components/SelectTree/index.vue

@@ -84,17 +84,19 @@ export default {
     optionData() {
       //第一个节点为根节点
       if (this.options.length > 0) {
-        var rootId = this.options[0].id;
+        //var rootId = this.options[0].id;
 
         let cloneData = JSON.parse(JSON.stringify(this.options)); // 对源数据深度克隆
-        return cloneData.filter(father => {
-          // 循环所有项,并添加children属性
-          let branchArr = cloneData.filter(
-            child => father.id == child.parentId
-          ); // 返回每一项的子级数组
-          branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性,并赋值
-          return father.id == rootId || father.parentId == null; //返回第一层
-        });
+        
+        // return cloneData.filter(father => {
+        //   // 循环所有项,并添加children属性
+        //   let branchArr = cloneData.filter(
+        //     child => father.id == child.parentId
+        //   ); // 返回每一项的子级数组
+        //   branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性,并赋值
+        //   return father.id == rootId || father.parentId == null; //返回第一层
+        // });
+        return this.listToTree(cloneData);
       } else {
         return [];
       }
@@ -112,6 +114,30 @@ export default {
     this.initHandle();
   },
   methods: {
+    listToTree(list) { // 将普通列表转换为树结构的列表
+      if (!list || !list.length) {
+        return []
+      }
+      
+      let treeListMap = {};
+      
+      for (let item of list) {
+        treeListMap[item.id] = item
+      }
+
+      for (let i = 0; i < list.length; i++) {
+        if (list[i].parentId && treeListMap[list[i].parentId]) {
+          if (!treeListMap[list[i].parentId].children) {
+            treeListMap[list[i].parentId].children = []
+          }
+          treeListMap[list[i].parentId].children.push(list[i]);
+          list.splice(i, 1);
+          i--
+        }
+      }
+
+      return list;
+    },
     // 初始化值
     initHandle() {
       console.log("options.length=" + this.options.length);

+ 5 - 1
src/views/base/companyInfo-department-list.vue

@@ -271,6 +271,7 @@
       @close="onDetailModalClose"
     ></companyInfo-detail>
     <companyDeviceRelation-list
+      :title="deviceRelationTitle"
       v-if="showDeviceModal"
       :companyId="companyId"
       @close="onDetailModalClose"
@@ -392,7 +393,8 @@ export default {
       },
       xlsLoading: false,
       sceneData: [],
-      typeData:[]
+      typeData:[],
+      deviceRelationTitle: ""
     };
   },
   created() {
@@ -599,6 +601,8 @@ export default {
     bindDevice(record) {
       //绑定设备
       this.companyId = record.id;
+      this.deviceRelationTitle = record.name + "关联设备列表";
+
       this.showDeviceModal = true;
     },
     openQRCode(record) {

+ 3 - 0
src/views/base/companyInfo-list.vue

@@ -602,6 +602,9 @@ export default {
       //绑定设备
       this.companyId = record.id;
       this.deviceRelationTitle = record.name + "关联设备列表";
+      
+      console.log(this.deviceRelationTitle);
+
       this.showDeviceModal = true;
     },
     openQRCode(record) {