Procházet zdrojové kódy

fix(规则管理): 优化计算公式逻辑,修复数据更新不及时问题并移除调试日志

yusheng před 6 měsíci
rodič
revize
009140ff0a

+ 18 - 14
src/views/rulesManagement/releaseRules/components/experimentationProcess.vue

@@ -262,27 +262,16 @@
       // 计算
       calculation() {
         this.getValue();
-        let data = {};
         let equation = [];
         this.list.forEach((item) => {
-          if (item.type == 'customText') {
-            data = { ...item.valueObj, ...data };
-          } else {
-            item.valueObj.rows.forEach((row) => {
-              row.cells.forEach((cell) => {
-                data[cell.id] = cell.value;
-              });
-            });
-          }
           equation.push({
             id: item.id,
             equation: item.equation
           });
         });
         equation.forEach((item) => {
-          console.log(item.equation);
-
           for (const key in item.equation) {
+            let data=this.getObjValue() //每次计算都获取最新的值
             let value = '';
             if (item.equation[key].length) {
               item.equation[key].forEach((equationItem) => {
@@ -304,6 +293,23 @@
           }
         });
       },
+      getObjValue() {
+        this.getValue();
+        let data = {};
+        this.list.forEach((item) => {
+          if (item.type == 'customText') {
+            data = { ...item.valueObj, ...data };
+          } else {
+            item.valueObj.rows.forEach((row) => {
+              row.cells.forEach((cell) => {
+                data[cell.id] = cell.value;
+              });
+            });
+          }
+        });
+        return data || {};
+      },
+
       setEquation() {
         this.getValue();
         this.idList = [];
@@ -413,7 +419,6 @@
       },
       editShowFn({ templateDivRef, domObj }) {
         this.templateDivRef = templateDivRef;
-        console.log(domObj, 'domObj');
         this.$set(this, 'domObj', domObj);
         this.editShow = true;
       },
@@ -441,7 +446,6 @@
       },
       getValue() {
         this.list.forEach((item, index) => {
-          console.log(item);
           let { form, valueObj, equation } =
             this.$refs['customTextRef' + item.id][0].getValue();
           this.$set(this.list[index], 'value', form);

+ 6 - 7
src/views/rulesManagement/releaseRules/components/templateDiv/customTable.vue

@@ -32,7 +32,7 @@
       </thead>
       <tbody>
         <tr v-for="(row, rowIndex) in rows">
-          <td v-for="item in row.cells" 
+          <td v-for="item in row.cells"
             ><input
               v-model="item.value"
               type="text"
@@ -80,9 +80,7 @@
         equation: {}
       };
     },
-    created(){
-         console.log(1)
-    },
+    created() {},
     methods: {
       // 方法:添加新列
       addColumn() {
@@ -138,11 +136,14 @@
       },
       calculation() {
         this.$emit('calculation');
+
       },
       equationValue({ domId, value }) {
         this.rows.forEach((item, index) => {
           let cellIndex = item.cells.findIndex((cell) => cell.id == domId);
-          this.$set(this.rows[index].cells[cellIndex], 'value', value);
+          if (cellIndex != '-1') {
+            this.$set(this.rows[index].cells[cellIndex], 'value', value);
+          }
         });
       },
       getValue() {
@@ -162,8 +163,6 @@
         this.equation = equation || {};
       },
       editInputChange(domObj) {
-        // let dom = document.getElementById(domObj.id);
-        // dom.parentElement.width = domObj.width;
         if (domObj.equation) {
           this.equation[this.domId] = domObj.equation;
         }

+ 9 - 7
src/views/rulesManagement/releaseRules/components/templateDiv/customText.vue

@@ -104,7 +104,6 @@
           '#' + this.id + ' .templateInput'
         );
         let data = {};
-        console.log(inputs, 'inputs');
         if (inputs.length) {
           inputs.forEach((item) => {
             data[item.id] = item.value;
@@ -117,14 +116,18 @@
         };
       },
       equationValue({ domId, value }) {
-        let dom = document.getElementById(domId);
-        this.valueObj[domId] = value;
-        dom.value = value;
+        if (domId) {
+          let dom = document.getElementById(domId);
+          if (dom) {
+            this.valueObj[domId] = value;
+            dom.value = value;
+          }
+        }
       },
       init({ form, valueObj, equation }) {
         this.form = form;
         this.valueObj = valueObj;
-        this.equation = equation||{};
+        this.equation = equation || {};
         this.$nextTick(() => {
           if (!this.edit) {
             let inputs = document.querySelectorAll('.templateInput');
@@ -190,10 +193,9 @@
 
     mounted() {
       this.$nextTick(() => {
-        console.log(document.getElementById(this.id), 'dsd');
         document
           .getElementById(this.id)
-          .addEventListener('change', this.inputChange);
+          .addEventListener('input', this.inputChange);
 
         document
           .getElementById(this.id)