From ccee429d379e0108b7445f72ade8d97c110a6fb3 Mon Sep 17 00:00:00 2001
From: ZZJ <zzjdsg2300@163.com>
Date: 星期二, 09 十一月 2021 18:01:59 +0800
Subject: [PATCH] 问题修复

---
 src/pages/datapush/index/RightEvent.vue |  362 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 340 insertions(+), 22 deletions(-)

diff --git a/src/pages/datapush/index/RightEvent.vue b/src/pages/datapush/index/RightEvent.vue
index e02d4dc..f4dce22 100644
--- a/src/pages/datapush/index/RightEvent.vue
+++ b/src/pages/datapush/index/RightEvent.vue
@@ -184,16 +184,64 @@
         <b>瑙勫垯</b>
         <div class="div-border" v-html="taskEditData.eventTxt"></div>
       </div>
+      <div class="config-item">
+        <b>鎺ㄩ�佸瓧娈�</b>
+        <el-button type="primary" size="mini" @click="openPushSetDialog">璁剧疆</el-button>
+      </div>
       <div class="save-btn">
         <el-button type="info" size="small" @click="onCancle" style="color:#222">鍙栨秷</el-button>
         <el-button type="primary" @click="eventPushsSave" size="small">淇濆瓨</el-button>
       </div>
     </div>
+    <el-dialog
+      :visible="pushFieldDialog"
+      :append-to-body="false"
+      :close-on-click-modal="false"
+      class="dialog-push-field"
+      @close="pushFieldDialog=false"
+    >
+      <div slot="title" class="slot-title">
+        <p>璇烽�夋嫨鎯宠鎺ㄩ�佺殑瀛楁</p>
+        <div class="right">
+          <el-checkbox v-model="allFieldChecked" @change="allCheckChange"></el-checkbox>
+        </div>
+      </div>
+      <div class="check-area" v-for="configObj in tempPushSet" :key="configObj.id">
+        <div class="header">
+          <div class="title">{{configObj.name}}</div>
+          <div class="right">
+            <el-checkbox v-model="configObj.checked" @change="toggleConfigCheck(configObj)">鍏ㄩ��</el-checkbox>
+          </div>
+        </div>
+        <div class="flex-box flex-wrap">
+          <div class="param flex-box" v-for="param in configObj.children" :key="param.id">
+            <el-checkbox v-model="param.checked" @change="checkChildren"></el-checkbox>
+            <span class="param-name">{{param.name}}</span>
+            <el-input
+              v-model="param.alias"
+              size="mini"
+              :ref="`input_${param.id}`"
+              @input="varifyField(param)"
+              :style="{color:param.error?'red':'',borderColor:param.error?'red':''}"
+            ></el-input>
+          </div>
+        </div>
+      </div>
+      <div slot="footer" class="text-center">
+        <el-button size="small" @click="canclePushFieldSet">鍙栨秷</el-button>
+        <el-button
+          size="small"
+          type="primary"
+          :disabled="disabledPushFieldSet"
+          @click="submitPushFieldSet"
+        >淇濆瓨</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 <script>
 
-import { eventPushsSave, findByEventTopic } from "@/api/event";
+import { eventPushsSave, findByEventTopic, getPushSet } from "@/api/event";
 import { findDictionaryByType, findDictionaryByID } from "@/api/dictionary";
 import { getTaskList } from "@/api/search";
 
@@ -229,13 +277,17 @@
         rule_values: [],
         topic_arg: "",
         topic_type: "",
-
         topicTypeOptions: {},
         topicArgOptions: {},
         operatorOptions: {},
         operatorTypeOpionts: {},
         ruleValueOptions: []
       },
+      pushFieldDialog: false,
+      tempPushSet: [],
+      pushFields: [],
+      allFieldChecked: false,
+      disabledPushFieldSet: true,
     };
   },
   watch: {
@@ -261,6 +313,12 @@
             if (!this.taskEditData.urls) {
               this.$set(this.taskEditData, "urls", [])
             }
+            //this.taskEditData.push_set = this.eventObject.push_set;
+            if (!this.eventObject.push_set.length) {
+              this.$set(this.taskEditData, "push_set", this.pushFields)
+            } else {
+              this.$set(this.taskEditData, "push_set", this.eventObject.push_set)
+            }
             if (newVal.rules) {
               newVal.rules.forEach(element => {
                 let newRule = Object.assign(JSON.parse(JSON.stringify(this.baseRule)), element)
@@ -273,18 +331,144 @@
         }
       },
       deep: true
+    },
+    tempPushSet: {
+      handler(n, o) {
+        let _this = this;
+        let flag = false;
+        n.forEach(configObj => {
+          let notChecked = configObj.children.find(param => !param.checked);
+          if (!notChecked) {
+            configObj.checked = true;
+          } else {
+            configObj.checked = false;
+          }
+          let someoneChecked = configObj.children.find(param => param.checked);
+          if (someoneChecked) {
+            flag = true
+          }
+
+        });
+        if (flag) {
+          this.disabledPushFieldSet = false;
+        } else {
+          this.disabledPushFieldSet = true;
+        }
+      },
+      deep: true
     }
   },
   created() {
     this.reAdd();
   },
   mounted() {
-    // 鍔犺浇瀛楀吀瀛楀吀
+    // 鍔犺浇瀛楀吀
     this.findByType();
     this.getCameras();
     this.getTasks();
+    this.getPushFields();
   },
   methods: {
+    openPushSetDialog() {
+      this.pushFieldDialog = true;
+      this.tempPushSet = JSON.parse(JSON.stringify(this.taskEditData.push_set));
+      this.checkFlag()
+    },
+    checkFlag() {
+      // debugger
+      let flag = true
+      this.tempPushSet.forEach(item => {
+        if (item.checked == false) {
+          flag = false
+        }
+      });
+      this.allFieldChecked = flag
+    },
+    checkChildren(val) {
+      console.log(val, 12121);
+      if (val == false) {
+        this.allFieldChecked = false
+      } else if (val == true && this.allFieldChecked == false) {
+        this.$nextTick(() => {
+          this.checkFlag()
+        })
+      }
+
+    },
+    varifyField(param) {
+      var reg = /^[A-Za-z]+[0-9-_]?$/;
+      if (!reg.test(param.alias)) {
+        this.$message('璇疯緭鍏ュ悎娉曞瓧娈靛悕');
+        param.error = true;
+      } else {
+        param.error = false;
+      }
+      // this.pushFields.forEach(configObj => {
+      //   configObj.children.find(param => param.error)
+      // })
+
+    },
+    canclePushFieldSet() {
+      this.pushFieldDialog = false;
+    },
+    allCheckChange(val) {
+
+      this.tempPushSet.forEach(function (item) {
+        item.checked = val
+        item.children.forEach(function (child) {
+          child.checked = val
+        })
+      })
+    },
+    submitPushFieldSet() {
+      let flag = false;
+      //this.pushFields.forEach(configObj => {
+      this.tempPushSet.forEach(configObj => {
+        let errorOne = configObj.children.find(param => param.checked && param.error);
+        if (errorOne) {
+          this.$notify({
+            type: 'error',
+            message: '璇峰皢閫変腑瀛楁杈撳叆鍚堟硶瀛楁鍚�'
+          })
+          flag = true
+        }
+      });
+      if (flag) {
+        //NO SUBMIT
+        return
+      }
+
+      this.taskEditData.push_set = this.tempPushSet;
+      this.pushFieldDialog = false;
+
+      // 淇濆瓨瑙勫垯
+      this.eventPushsSave()
+    },
+    toggleConfigCheck(configObj) {
+
+      configObj.children.forEach(child => {
+        child.checked = configObj.checked
+      })
+      this.checkFlag()
+    },
+    getPushFields() {
+      let _this = this;
+      getPushSet().then(res => {
+        _this.pushFields = res.data;
+      })
+      // this.pushFields = [
+      //   {          id: 'sxjxx', name: '鎽勫儚鏈轰俊鎭�', checked: false, alias: '',
+      //     children: [
+      //       { name: '鎽勫儚鏈篒D', checked: false, alias: 'cameraID', id: 'cameraID', children: null },
+      //       { name: '鎽勫儚鏈哄悕绉�', checked: false, alias: 'cameraName', id: 'cameraName', children: null },
+      //       { name: '鎽勫儚鏈哄湴鍧�', checked: false, alias: 'cameraAddr', id: 'cameraAddr', children: null },
+      //       { name: '鎽勫儚鏈哄潃', checked: false, alias: 'cameraAdr', id: 'cameraAdr', children: null }
+      //     ]        },
+      //   {          id: 'cjxx', name: '鍦烘櫙淇℃伅', checked: false, alias: '',
+      //     children: [{ name: '鍦烘櫙ID', checked: false, alias: 'taskId', id: 'tskId', children: null }]        },
+      // ];
+
+    },
     addUrl() {
       this.taskEditData.urls.push({
         checked: true,
@@ -293,8 +477,8 @@
       });
     },
     delUrl(index) {
-      this.$set(this.taskEditData.urls, index, this.baseRule)
-      this.taskEditData.urls.splice(index, 1)
+      this.$set(this.taskEditData.urls, index, this.baseRule);
+      this.taskEditData.urls.splice(index, 1);
     },
     // 淇濆瓨
     async eventPushsSave() {
@@ -330,10 +514,16 @@
           str += ' = ';
         }
 
-        str += i.rule_value;
+        if (i.rule_value === "all*all") {
+          str += "鍏ㄩ儴";
+        } else if (i.rule_value === "null*null") {
+          str += "绌�";
+        } else {
+          str += i.rule_value;
+        }
 
         if (str.length > 0) {
-          ruleDesc.push(str)
+          ruleDesc.push(str);
         }
       });
       // 澶勭悊瑙勫垯鍒楄〃鏁版嵁缁撴瀯
@@ -358,7 +548,8 @@
         time_end: this.taskEditData.time[1],
         urls: this.taskEditData.urls,
         is_satisfy_all: this.taskEditData.radioValue === "1",
-        link_type: this.taskEditData.lineWay
+        link_type: this.taskEditData.lineWay,
+        push_set: this.taskEditData.push_set
       };
 
       let res = await eventPushsSave(json);
@@ -389,7 +580,7 @@
     async getCameras() {
       let rsp = await findByEventTopic({ topic: 'camera', type: 'name' });
       if (rsp && rsp.success) {
-        this.dictionary['camera'] = rsp.data
+        this.dictionary['camera'] = rsp.data;
       }
 
       rsp = await findByEventTopic({ topic: 'dbtable' });
@@ -413,7 +604,7 @@
               value: task.name,
               name: task.name
             })
-            hash[task.name] = true
+            hash[task.name] = true;
           }
         })
       }
@@ -439,35 +630,52 @@
         if (element.value === rule.topic_type) {
           rule.topicArgOptions = element.children;
           if (resetNext) {
-            rule.topic_arg = rule.topicArgOptions[0].value
-            this.selectArg(rule, resetNext)
+            rule.topic_arg = rule.topicArgOptions[0].value;
+            this.selectArg(rule, resetNext);
           }
         }
       });
     },
     selectArg(rule, resetNext = false) {
+      debugger
       let argInfo = rule.topicArgOptions.filter(arg => {
-        return arg.value === rule.topic_arg
+        return arg.value === rule.topic_arg;
       })
 
       if (argInfo.length > 0) {
-        let desc = argInfo[0].description.split(",")
+        let desc = argInfo[0].description.split(",");
         if (desc.length > 0) {
           rule.operatorTypeOpionts = this.dictionary.EVENTTYPECOMPUTE.filter(el => {
-            return desc.indexOf(el.value) >= 0
+            return desc.indexOf(el.value) >= 0;
           })
         }
       }
 
       if (resetNext) {
-        rule.operator_type = rule.operatorTypeOpionts[rule.operatorTypeOpionts.length - 1].value
-        this.selectOperator(rule, resetNext)
+        rule.operator_type = rule.operatorTypeOpionts[rule.operatorTypeOpionts.length - 1].value;
+        this.selectOperator(rule, resetNext);
       }
     },
     selectOperator(rule, resetNext = false) {
       if (rule.operator_type === "option") {
-        rule.ruleValueOptions = this.dictionary[rule.topic_type] ? this.dictionary[rule.topic_type] : []
-        rule.rule_values = rule.rule_value.split(",")
+        rule.ruleValueOptions = this.dictionary[rule.topic_type] ? this.dictionary[rule.topic_type] : [];
+
+        if (rule.rule_value != "") {
+          rule.rule_values = rule.rule_value.split(",");
+        }
+
+        // 澶勭悊 鍏ㄩ儴/绌�
+        for (let i = 0; i < rule.rule_values.length; i++) {
+          if (rule.rule_values[i] === "all*all") {
+            rule.rule_values[i] = "鍏ㄩ儴";
+          }
+
+          if (rule.rule_values[i] === "null*null") {
+            rule.rule_values[i] = "绌�";
+          }
+        }
+
+        this.setOptionsDisable(rule);
       }
 
       if (resetNext) {
@@ -476,7 +684,44 @@
       }
     },
     selectValue(rule, val) {
-      rule.rule_value = val.join(",")
+      if (rule.operator_type === "option") {
+        this.setOptionsDisable(rule);
+
+        if (val.indexOf("鍏ㄩ儴") >= 0) {
+          rule.rule_value = "all*all";
+          return;
+        }
+
+        if (val.indexOf("绌�") >= 0) {
+          rule.rule_value = "null*null";
+          return;
+        }
+      }
+
+      rule.rule_value = val.join(",");
+    },
+    setOptionsDisable(rule) {
+      let isAllSelect = (rule.rule_values.indexOf("鍏ㄩ儴") >= 0);
+      let isNullSelect = (rule.rule_values.indexOf("绌�") >= 0);
+
+      rule.ruleValueOptions.forEach(opt => {
+        if (!rule.rule_values.length) {
+          opt.disabled = false;
+          return
+        }
+
+        if (opt.name === "鍏ㄩ儴") {
+          opt.disabled = !isAllSelect;
+          return
+        }
+
+        if (opt.name === "绌�") {
+          opt.disabled = !isNullSelect;
+          return
+        }
+
+        opt.disabled = (isAllSelect || isNullSelect);
+      })
     },
     // 鏍规嵁value杩斿洖瀵瑰簲鐨刵ame
     getNameByValue(arr, value) {
@@ -512,7 +757,8 @@
           }
         ],
         radioValue: "1",
-        eventTxt: ""
+        eventTxt: "",
+        push_set: this.pushFields
       };
       this.dataList = [];
     },
@@ -574,7 +820,12 @@
       margin-left: 895px;
     }
   }
-
+  .config-item {
+    margin: 20px 0;
+    b {
+      margin-right: 10px;
+    }
+  }
   .el-button--text {
     text-decoration: unset;
   }
@@ -604,5 +855,72 @@
     color: #3d68e1;
     line-height: 39px;
   }
+  .dialog-push-field {
+    .el-button--primary.is-disabled,
+    .el-button--primary.is-disabled:hover {
+      background-color: #9eb4f0 !important;
+      border-color: #9eb4f0 !important;
+    }
+    .el-dialog {
+      width: 910px;
+      height: 700px;
+      .el-dialog__body {
+        padding-top: 14px;
+        height: 540px;
+        overflow-y: auto;
+      }
+    }
+    .text-center {
+      text-align: center;
+    }
+    .slot-title {
+      position: relative;
+      .right {
+        position: absolute;
+        top: 0;
+        right: 30px;
+      }
+    }
+    .check-area {
+      padding-bottom: 10px;
+      .header {
+        position: relative;
+        background: #efefef;
+        line-height: 30px;
+        margin-bottom: 14px;
+        font-weight: bold;
+        .title {
+          border-left: 3px solid #2481fa;
+          padding-left: 10px;
+        }
+        .right {
+          position: absolute;
+          top: 0;
+          right: 30px;
+        }
+      }
+      .flex-box.flex-wrap {
+        flex-wrap: wrap;
+      }
+      .param.flex-box {
+        word-break: keep-all;
+        align-items: center;
+        margin: 0 10px;
+        min-width: 260px;
+        margin-bottom: 10px;
+        .param-name {
+          margin: 0 5px;
+        }
+        .el-input {
+          border-color: #dcdfe6;
+          color: #606266;
+          .el-input__inner {
+            color: inherit;
+            border-color: inherit;
+          }
+        }
+      }
+    }
+  }
 }
 </style>

--
Gitblit v1.8.0