Sfoglia il codice sorgente

refactor(programRulesDialog): 优化表单数据处理逻辑

liujt 6 mesi fa
parent
commit
1eb6c7d822
1 ha cambiato i file con 26 aggiunte e 13 eliminazioni
  1. 26 13
      src/views/maintenance/components/programRulesDialog.vue

+ 26 - 13
src/views/maintenance/components/programRulesDialog.vue

@@ -796,8 +796,7 @@ export default {
       try {
         const res = await getById(id);
         console.log('res----------', res);
-        this.addForm = res.data;
-        this.addForm.id = res.data.planId;
+        const data = res.data;
         // if (this.dialogTitle === '派单') {
         //   this.addForm.autoOrder = 1;
         // }
@@ -829,22 +828,22 @@ export default {
         console.log(this.ruleIdList);
 
         // 处理回显数据
-        if (this.addForm.executeUserType === 0) {
+        if (data.executeUserType === 0) {
           // 个人
-          this.addForm.executeIdList = this.addForm.executeUsers.map(
+          data.executeIdList = data.executeUsers.map(
             (item) => item.userId
           );
 
-          let groupIds = this.addForm.executeUsers
+          let groupIds = data.executeUsers
             .map((i) => i.groupId)
             .filter((i) => i);
           groupIds = Array.from(new Set(groupIds));
 
           if (groupIds.includes('1')) {
             // 包含全部部门,置空
-            this.addForm.groupId = '1';
+            data.groupId = '1';
           } else {
-            this.addForm.groupId = this.addForm.executeUsers[0]?.groupId || '1';
+            data.groupId = data.executeUsers[0]?.groupId || '1';
           }
 
           groupIds.map((item) => {
@@ -852,11 +851,16 @@ export default {
           });
         } else {
           // 班组
-          this.addForm.teamId = this.addForm.executeUsers?.[0]?.teamId || '';
+          data.teamId = data.executeUsers?.[0]?.teamId || '';
         }
 
         this.tabsValue = this.ruleIdList[0].ruleId;
 
+        // this.addForm = res.data;
+        // this.addForm.id = res.data.planId;
+        this.$set(this, 'addForm', data);
+        this.$set(this.addForm, 'id', data.planId);
+
         // this._getMatterRulesDetails(res.ruleId);
         this.$set(this.addForm, 'code', res.data.code);
         this.$set(this.addForm, 'urgent', JSON.stringify(res.data.urgent));
@@ -888,11 +892,20 @@ export default {
         console.log(error);
       }
     },
-    typeChange() {
-      this.addForm.groupId = '';
-      this.addForm.executeIdList = [];
-      this.addForm.teamId = '';
-      this.addForm.executorId = [];
+    typeChange(v) {
+      console.log('typeChange', v, this.addForm.executeIdList);
+      // this.addForm.groupId = '';
+      // this.addForm.executeIdList = [];
+      // this.addForm.teamId = '';
+      // this.addForm.executeUsers = [];
+      this.$set(this.addForm, 'executeUsers', []);
+      if(v == 0) {
+        this.$set(this.addForm, 'groupId', '');
+        this.$set(this.addForm, 'executeIdList', []);
+      } else {
+        this.$set(this.addForm, 'teamId', '');
+      }
+      this.$forceUpdate();
     },
     // 获取设备分类数据
     async categoryEquipment(id) {