Browse Source

point config

haojianlong 5 years ago
parent
commit
040a89186f
1 changed files with 52 additions and 22 deletions
  1. 52 22
      src/components/point/dynamicdata/delRelationDialog.vue

+ 52 - 22
src/components/point/dynamicdata/delRelationDialog.vue

@@ -52,8 +52,7 @@
     </div>
     <span slot="footer" class="dialog-footer">
       <el-button size="small" @click="handleClose">取消</el-button>
-      <el-button size="small" type="primary" v-show="1" v-loading="loading" @click="handleDelete">确定</el-button>
-      <el-button size="small" type="primary" v-show="0" v-loading="loading">清除已选的对应规则</el-button>
+      <el-button size="small" type="primary" v-loading="loading" @click="handleDelete" :disabled="deleDisabled">清除已选</el-button>
     </span>
   </el-dialog>
 </template>
@@ -65,10 +64,11 @@ export default {
       dialogVisible: false, //弹窗显示与隐藏
       ltableData: [], // 左侧数据
       rtableData: [], // 右侧数据
-      activeName: "first", //当前所在tab页
       loading: false, //loading状态
       dialogWidth: "20%", //弹窗宽度
-      selection: []
+      selection: [],
+      deleDisabled: false,
+      deleParam: []
     };
   },
   methods: {
@@ -79,23 +79,33 @@ export default {
       //需先用对象请求接口返回所需对象
       this.getDynamicQueryPrompt(row)
     },
-    handleClick() { },
     handleClose(done) {
       this.dialogVisible = false;
     },
     //确认清除对应关系
-    handleDelete(i, t) {
-      console.log(i);
-      console.log(t);
-      //param.objs and param.point .length>1
-      dynamicDeleteRelation(this.param, res => {
-        console.log(res);
+    handleDelete() {
+      console.log(2222222222222)
+      console.log(this.deleParam)
+      dynamicDeleteRelation(this.deleParam, res => {
         this.$emit("refresh");
         this.dialogVisible = false;
+        this.$message.success('清除成功');
       });
     },
-    //表格中选择事件
-    changeSelection() { },
+    //表格中选择事件 1-n or n-1 公用
+    changeSelection(selection) {
+      this.deleParam = []
+      let tempObj = {}
+      this.deleDisabled = selection.length <= 0
+      if (this.ltableData.length > this.rtableData.length) {
+        tempObj.Objs = [selection[0]]
+        tempObj.Points = selection
+      } else if (this.ltableData.length < this.rtableData.length) {
+        tempObj.Objs = selection
+        tempObj.Points = [selection[0]]
+      }
+      this.deleParam.push(tempObj)
+    },
     //查询两边数据,同时拼删除param
     getDynamicQueryPrompt(row) {
       let p1 = {
@@ -120,23 +130,43 @@ export default {
         })
       })
       Promise.all([promise1, promise2]).then(res => {
-        console.log(res)
-        this.ltableData = res[1].Content
-        this.rtableData = res[0].Content
+        this.deleParam = [];
+        this.deleDisabled = false;
+        this.ltableData = res[1].Content;
+        this.rtableData = res[0].Content;
         if (this.ltableData.length > 1 || this.rtableData.length > 1) {
           this.dialogWidth = "60%";
+          this.$nextTick(() => {
+            this.toggleSelection(row);
+          })
+        } else {
+          this.dialogWidth = "20%";
+          let tempObj = {
+            Objs: this.ltableData,
+            Points: this.rtableData
+          }
+          this.deleParam.push(tempObj)
         }
-        this.$nextTick(() => {
-          this.toggleSelection(row);
-        })
         this.loading = false;
       })
     },
     //设置默认选中
     toggleSelection(row) {
-      console.log(row)
-      this.ltableData.length > this.rtableData.length ?
-        this.$refs.ltable.toggleRowSelection(row) : this.$refs.rtable.toggleRowSelection(row)
+      if (this.ltableData.length > this.rtableData.length) {
+        this.ltableData.map((t, i) => {
+          if (t.Id == row.Id) {
+            this.$refs.ltable.toggleRowSelection(this.ltableData[i], true)
+            return;
+          }
+        })
+      } else {
+        this.rtableData.map((t, i) => {
+          if (t.Id == row.Id) {
+            this.$refs.rtable.toggleRowSelection(this.ltableData[i], true)
+            return;
+          }
+        })
+      }
     }
   },
   mounted() { },