Parcourir la source

温箱1历史数据导出前判断是否在3个月内

LLL il y a 1 an
Parent
commit
a179b99855

+ 43 - 32
itdmWeb/src/views/module-iTDM/itdmWenxiangHistory/ItdmWenxiangHistory1List.vue

@@ -315,9 +315,10 @@
 
       // 判断时间段是否在3个月内,在的话导出,超出的话提示
       dc(fileName){
-        console.log(11111,this.queryParam)
+        let param = this.getQueryParams();
+        console.log(11111,param)
         //判断时间段是否在3个月内
-        let flag = this.completeDate(queryParam.createTime_begin,queryParam.createTime_end,3)
+        let flag = this.completeDate(param.createTime_begin,param.createTime_end,3)
 
         if(flag){
           this.handleExportXls(fileName)
@@ -359,36 +360,46 @@
 
       //判断时间段是否在3个月内,是的话返回true,否则返回false
       completeDate (time1, time2, m) {
-        const year1 = time1.getFullYear()
-        const year2 = time2.getFullYear()
-        const month1 = time1.getMonth() + 1
-        const month2 = time2.getMonth() + 1
-        const day1 = time1.getDate()
-        const day2 = time2.getDate()
-        if (year2 === year1) { // 判断两个日期 是否是同年
-          if (month2 - month1 > m) { // 相差是否 在m个月中
-            return false
-          } else if (month2 - month1 === m) { // 如果正好为 m月 判断天数
-            if (day2 > day1) {
-              return false
-            }
-          }
-        } else { // 不同年
-          if (year2 - year1 > 1) {
-            return false
-          }
-          else if (year2 - year1 === 1) {
-            if (month2 > m || month1 + m - month2 < 12) {
-              return false
-            }
-            else if (month1 + m - month2 === 12) { // 正好为m月 判断天数
-              if (day2 > day1) {
-                return false
-              }
-            }
-          }
-        }
-        return true
+
+        var date1 = new Date(time1);
+        var date2 = new Date(time2);
+
+        // 计算时间差
+        var diffMonths = (date2.getFullYear() - date1.getFullYear()) * 12 + date2.getMonth() - date1.getMonth();
+
+        // 判断时间差是否小于等于m个月
+        return diffMonths <= m;
+
+        // const year1 = time1.getFullYear()
+        // const year2 = time2.getFullYear()
+        // const month1 = time1.getMonth() + 1
+        // const month2 = time2.getMonth() + 1
+        // const day1 = time1.getDate()
+        // const day2 = time2.getDate()
+        // if (year2 === year1) { // 判断两个日期 是否是同年
+        //   if (month2 - month1 > m) { // 相差是否 在m个月中
+        //     return false
+        //   } else if (month2 - month1 === m) { // 如果正好为 m月 判断天数
+        //     if (day2 > day1) {
+        //       return false
+        //     }
+        //   }
+        // } else { // 不同年
+        //   if (year2 - year1 > 1) {
+        //     return false
+        //   }
+        //   else if (year2 - year1 === 1) {
+        //     if (month2 > m || month1 + m - month2 < 12) {
+        //       return false
+        //     }
+        //     else if (month1 + m - month2 === 12) { // 正好为m月 判断天数
+        //       if (day2 > day1) {
+        //         return false
+        //       }
+        //     }
+        //   }
+        // }
+        // return true
       },
 
       initDictConfig(){