Browse Source

更多关系

YaolongHan 3 years ago
parent
commit
70523eb2b7

+ 46 - 20
src/views/maintain/relationship/relation/components/moreRelationDialog.vue

@@ -1,6 +1,7 @@
 <template>
   <el-dialog
     @open="openEvent"
+    @close="closeLog"
     title="更多关系"
     :visible.sync="dialogTableVisible"
   >
@@ -13,11 +14,11 @@
         align="left"
       >
         <template slot-scope="scope">
-          {{
-            (item[1].includes("objectInfo") && scope.row.objectInfo
-              ? scope.row.objectInfo[0][item[1].split("-")[1]]
-              : scope.row[item[1]]) || "--"
-          }}
+               {{
+          item[1].includes("objectInfo")
+            ? scope.row[item[1].split("-")[1]]
+            :  "--"
+        }}
         </template>
       </el-table-column>
       <el-table-column label="操作" align="left">
@@ -53,7 +54,7 @@ import { zoneQuery, relDel } from "@/api/datacenter";
 })
 export default class extends Vue {
   @Prop({ default: Array }) tableHeader?: [];
-  @Prop({ default: String }) mainId?: ""; //主对象id
+  @Prop({ default: Array }) allRelation?: []; //主对象id
   //    分页
   page: object = {
     total: 0, //总数
@@ -70,26 +71,35 @@ export default class extends Vue {
    * 分页数量切换
    */
 
-  handleSizeChange(val: any) {}
+  handleSizeChange(val: any) {
+    this.page.pageSize = 10;
+    this.page.currentPage = 1;
+    this.getTable()
+  }
 
   /**
    * 分页切换
    */
-  handleCurrentChange(val: any) {}
+  handleCurrentChange(val: any) {
+    this.page.currentPage = val;
+    this.getTable()
+  }
 
   getTable() {
-    const data = {
-      pageSize: this.page.pageSize,
-      pageNumber: this.page.currentPage,
-      orders: "name asc, createTime desc",
-      filters: `buildingId='${this.mainId}'`,
-    };
-    zoneQuery(data).then((res: any) => {
-      if (res.content && res.content.length) {
-        this.gridData = res.content;
-      }
-      this.page.total = res.total;
-    });
+    // const data = {
+    //   pageSize: this.page.pageSize,
+    //   pageNumber: this.page.currentPage,
+    //   orders: "name asc, createTime desc",
+    //   filters: `buildingId='${this.mainId}'`,
+    // };
+    // zoneQuery(data).then((res: any) => {
+    //   if (res.content && res.content.length) {
+    //     this.gridData = res.content;
+    //   }
+    //   this.page.total = res.total;
+    // });
+    this.page.total= this.allRelation?.objectInfo?.length;
+    this.gridData = this.allRelation?.objectInfo.slice((this.page.currentPage-1)*this.page.pageSize,this.page.currentPage*this.page.pageSize);
   }
 
   /**
@@ -97,6 +107,7 @@ export default class extends Vue {
    *
    */
   openEvent() {
+    this.page.pageSize
     // 请求从关系接口
     this.getTable();
   }
@@ -111,15 +122,30 @@ export default class extends Vue {
       fromId: this.mainId, //主对象id
       toId: val.id, //从对象id
     };
+    const delId = val.id
     relDel(data).then((res) => {
       if (res.result == "success") {
         this.$message.success("删除成功!");
+        let delIndex = -1;
+        this.allRelation?.objectInfo.forEach((item:any,index:number)=>{
+             if(item.val == delId) {
+                 delIndex = index
+             }
+        })
+        this.allRelation.objectInfo.splice(delIndex,1) //模拟删除
         this.getTable();
       } else {
         this.$message.error("删除失败!");
       }
     });
   }
+  /**
+   * 关闭按钮
+   */
+  closeLog(){
+   this.$emit('update')
+  }
+
 }
 </script>
 <style lang="">

+ 16 - 6
src/views/maintain/relationship/relation/index.vue

@@ -79,8 +79,9 @@
     <excelDialog :values="values" ref="excelDialog"></excelDialog>
     <editRelationDialog :values="values"></editRelationDialog>
     <moreRelationDialog
-      :mainId="mainId"
-      :tableHeader="tableHeader"
+      :allRelation="allRelation"
+      :tableHeader="tableHeaderTo"
+       @update="addRelationSucess(0)"
       ref="moreRelation"
     ></moreRelationDialog>
   </div>
@@ -116,9 +117,11 @@ export default class extends Vue {
   minorOptions = []; //次关系选项
   vagueFrom = ""; //主关系模糊收索
   vagueTo = ""; //次关系模糊收索
-  mainId: string = ""; //主关系id
+  allRelation: any[] = []; //所有更多从关系
   //表头数据
   tableHeader = [];
+  //从数据表头数据
+  tableHeaderTo =[];
   //表格数据
   tableData = [];
   // 是否添加关系
@@ -172,7 +175,7 @@ export default class extends Vue {
    *
    */
   openMoreRelation(obj: any) {
-    this.mainId = obj.id;
+    this.allRelation = obj;
     this.$refs.moreRelation.dialogTableVisible = true;
   }
 
@@ -246,12 +249,12 @@ export default class extends Vue {
   /**
    * 添加关系成功后
    */
-  addRelationSucess(initPage) {
+  addRelationSucess(initPage:number) {
     if (initPage) {
       this.page.currentPage = 1; //初始化页面
     }
     this.relManualQuery();
-    this.relToTfype(); //重新f获取关系对象
+    this.relToType(); //重新f获取关系对象
   }
 
   /**
@@ -396,6 +399,13 @@ export default class extends Vue {
   created() {
     let relationTypeName = this.$route.query.relationTypeName;
     this.tableHeader = tableHeader[relationTypeName];
+    tableHeader[relationTypeName].forEach((item:any)=>{
+
+      if(item[1].includes('objectInfo')){
+        this.tableHeaderTo.push(item)
+      }
+
+    })                                       //从关系
     this.relTypeStatus = this.$route.query.relTypeStatus;
     // 获取主从对象下拉框数据
     this.relToType();