Bläddra i källkod

室内温度tree-table

zhulizhen 5 år sedan
förälder
incheckning
866ff2dcc1
2 ändrade filer med 33 tillägg och 33 borttagningar
  1. 20 23
      src/views/evaluate/evTwoLevelMenu.vue
  2. 13 10
      src/views/evaluate/evTwoTable.vue

+ 20 - 23
src/views/evaluate/evTwoLevelMenu.vue

@@ -138,33 +138,30 @@ export default {
     // 室内温度table @
     queryTdbDayMethod(date) {
       this.dataList = [];
-      let arr1 = [],
-        arr2 = [];
+      let obj = {
+        // 'Fl44130300016569b876ba5311e990f9592e6484ca96': {
+        //   id: 'Fl44130300016569b876ba5311e990f9592e6484ca96',
+        //   name: '1F',
+        //   children: []
+        // }
+      }
       queryTdbDay(date, {}).then(res => {
         this.tindoorFillRate = res.tindoorFillRate;
         console.log("室内温度满足率", res);
         let content = res.content;
-        if (content.length > 0) {
-          content.forEach(item => {
-            arr1.push(item.spaceDayRpt.floorLocalName);
-          });
-          arr1 = Array.from(new Set(arr1));
-          arr1.forEach(el => {
-            let obj = {
-              floor: el,
-              floorArr: []
-            };
-            arr2.push(obj);
-          });
-          content.forEach(item2 => {
-            arr2.forEach(item => {
-              if (item2.spaceDayRpt.floorLocalName == item.floor) {
-                item.floorArr.push(item2.spaceDayRpt);
-              }
-            });
-          });
-        }
-        this.dataList = arr2;
+        content.forEach(({ spaceDayRpt }) => {
+          if(obj.hasOwnProperty(spaceDayRpt.floorId)) {
+            obj[spaceDayRpt.floorId].children.push(spaceDayRpt)
+          } else {
+            obj[spaceDayRpt.floorId] = {
+              id: spaceDayRpt.floorId,
+              name: spaceDayRpt.floorLocalName,
+              children: []
+            }
+          }
+        })
+        
+        this.dataList = Object.values(obj);
         console.log(this.dataList);
       });
     },

+ 13 - 10
src/views/evaluate/evTwoTable.vue

@@ -4,11 +4,11 @@
     :data="dataList"
     style="width: 100%;z-index:1"
     :row-key="getRowKeys"
-    :expand-row-keys="expands"
+     :expand-row-keys="expands"
   >
     <el-table-column type="expand">
       <template slot-scope="props">
-        <el-table :data="props.row.floorArr" style="width: 100%;">
+        <el-table :data="props.row.children" style="width: 100%;">
           <el-table-column type="selection" width="50" align="right"></el-table-column>
           <el-table-column prop label align="right" width="150">
             <template slot-scope="{row}">
@@ -35,7 +35,7 @@
         </el-table>
       </template>
     </el-table-column>
-    <el-table-column prop="floor" label align="right" width="50"></el-table-column>
+    <el-table-column prop="name" label align="right" width="50"></el-table-column>
     <el-table-column prop label="位置详情" align="right" width="100"></el-table-column>
     <el-table-column prop label="温度要求范围(℃)" align="right"></el-table-column>
     <el-table-column prop label="平均温度(℃)" align="right"></el-table-column>
@@ -51,18 +51,21 @@ export default {
     return {
       getRowKeys(row) {
         return row.id;
-      },
-      expands: []
+      },  
     };
   },
   props: ["dataList"],
+  computed: {
+    expands() {
+      return this.dataList.map(i => {
+          // 增加 isExpand 属性
+          i.isExpand = i.children.some(c => c.isSatisfy == false)
+          return i
+        }).filter(j => j.isExpand).map(i => i.id)
+    }
+  },
   methods: {
     init() {
-      this.dataList.forEach((item, index) => {
-        if (item.floorArr[index].isSatisfy == false) {
-          this.expands.push(item.id);
-        }
-      });
     }
   },
   mounted() {