Pārlūkot izejas kodu

1.机器设备作价自动保存(60s倒计时,测算内容修改时激活)

GouGengquan 5 mēneši atpakaļ
vecāks
revīzija
169c43b81c
1 mainītis faili ar 102 papildinājumiem un 4 dzēšanām
  1. 102 4
      src/views/assets/workbench/calculate/importInfo.vue

+ 102 - 4
src/views/assets/workbench/calculate/importInfo.vue

@@ -1171,6 +1171,13 @@ export default {
       eqptPriceFilterArr: [],
       // 机器设备表单
       eqptDataForm: {},
+      autoSaveAtive: false,
+      autoSaveTimer: null, // 用于存储 setTimeout 的引用
+      autoSaveImpAtive: false,
+      autoSaveImpTimer: null, // 用于存储 setTimeout 的引用
+      autoSaveNonSAtive: false,
+      autoSaveNonSTimer: null, // 用于存储 setTimeout 的引用
+      countdownDuration: 60000, // 倒计时时间(10秒)
     }
   },
   components: {
@@ -1244,12 +1251,80 @@ export default {
       }, 0)
     },
   },
+  watch: {
+    // 监听 eqptPageData 的变化
+    eqptPageData: {
+      deep: true, // 深度监听数组内容的变化
+      handler() {
+        // 数组变化开启自动保存
+        this.startAutoSave()
+      }
+    },
+    // 监听 eqptImpPageData 的变化
+    eqptImpPageData: {
+      deep: true, // 深度监听数组内容的变化
+      handler() {
+        // 数组变化开启自动保存
+        this.startAutoSaveImp()
+      }
+    },
+    // 监听 eqptNonSPageData 的变化
+    eqptNonSPageData: {
+      deep: true, // 深度监听数组内容的变化
+      handler() {
+        // 数组变化开启自动保存
+        this.startAutoSaveNonS()
+      }
+    }
+  },
   created() {
     this.getBaseInfo()
     this.getEqptDataPage()
     this.getPPI()
   },
   methods: {
+    startAutoSave() {
+      if (this.autoSaveAtive) {
+        // 如果倒计时已经激活,直接返回
+        if (this.autoSaveTimer) {
+          return
+        }
+        // 激活倒计时
+        this.autoSaveTimer = setTimeout(() => {
+          // 倒计时结束,执行方法
+          this.autoSaveTimer = null;
+          this.autoSaveBatch();
+        }, this.countdownDuration)
+      }
+    },
+    startAutoSaveImp() {
+      if (this.autoSaveImpAtive) {
+        // 如果倒计时已经激活,直接返回
+        if (this.autoSaveImpTimer) {
+          return
+        }
+        // 激活倒计时
+        this.autoSaveImpTimer = setTimeout(() => {
+          // 倒计时结束,执行方法
+          this.autoSaveImpTimer = null;
+          this.autoSaveBatchImp();
+        }, this.countdownDuration)
+      }
+    },
+    startAutoSaveNonS() {
+      if (this.autoSaveNonSAtive) {
+        // 如果倒计时已经激活,直接返回
+        if (this.autoSaveNonSTimer) {
+          return
+        }
+        // 激活倒计时
+        this.autoSaveNonSTimer = setTimeout(() => {
+          // 倒计时结束,执行方法
+          this.autoSaveNonSTimer = null;
+          this.autoSaveBatchNonS();
+        }, this.countdownDuration)
+      }
+    },
     getDaysBetween,
     tabChange() {
       this.eqptDataQuery = {
@@ -1289,14 +1364,34 @@ export default {
       this.eqptInstallationRateFilterArr = []
       this.eqptDirectObservationDepreciationRateFilterArr = []
       this.eqptPriceFilterArr = []
+
+      // tab切换时保存测算信息销毁计时器
       if (this.activeName === 'all') {
         this.getEqptDataPage()
+        clearTimeout(this.autoSaveImpTimer);
+        this.autoSaveImpTimer = null;
+        clearTimeout(this.autoSaveNonSTimer);
+        this.autoSaveNonSTimer = null;
+        this.autoSaveBatchImp();
+        this.autoSaveBatchNonS();
       }
       if (this.activeName === 'imported') {
         this.getImpEqptDataPage()
+        clearTimeout(this.autoSaveTimer);
+        this.autoSaveTimer = null;
+        clearTimeout(this.autoSaveNonSTimer);
+        this.autoSaveNonSTimer = null;
+        this.autoSaveBatch();
+        this.autoSaveBatchNonS();
       }
       if (this.activeName === 'nonStandard') {
         this.getNonSEqptDataPage()
+        clearTimeout(this.autoSaveImpTimer);
+        this.autoSaveImpTimer = null;
+        clearTimeout(this.autoSaveTimer);
+        this.autoSaveTimer = null;
+        this.autoSaveBatchImp();
+        this.autoSaveBatch();
       }
     },
     // 新增机器设备信息
@@ -1428,9 +1523,10 @@ export default {
               message: '数据载入成功!',
               type: 'success',
             })
+            this.autoSaveAtive = true;
           })
         }
-        this.getEqptLifeIfrRefs()
+        this.getEqptLifeIfrRefs();
       })
     },
     // 分页查询进口设备信息
@@ -1452,6 +1548,7 @@ export default {
               message: '数据载入成功!',
               type: 'success',
             })
+            this.autoSaveImpAtive = true;
           })
         }
       })
@@ -1475,6 +1572,7 @@ export default {
               message: '数据载入成功!',
               type: 'success',
             })
+            this.autoSaveNonSAtive = true;
           })
         }
         this.getEqptGnEvpList()
@@ -1635,7 +1733,7 @@ export default {
       })
     },
     autoSaveBatch() {
-      updateBatch(this.eqptPageData);
+      updateBatch(this.eqptPageData)
     },
     // 批量更新设备测算
     saveBatch() {
@@ -1794,7 +1892,7 @@ export default {
       })
     },
     autoSaveBatchImp() {
-      updateBatchImpData(this.eqptImpPageData);
+      updateBatchImpData(this.eqptImpPageData)
     },
     // 批量更新进口设备测算
     saveBatchImp() {
@@ -1823,7 +1921,7 @@ export default {
       })
     },
     autoSaveBatchNonS() {
-      updateBatchNonSData(this.eqptNonSPageData);
+      updateBatchNonSData(this.eqptNonSPageData)
     },
     // 批量更新非标设备测算
     saveBatchNonS() {