From e95d6f2a9141c05903098065b4356d1158c0c4e2 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期六, 28 三月 2026 14:32:35 +0800
Subject: [PATCH] 能耗统计年月日修改

---
 src/views/energyManagement/energyConsumptionStatistical/index.vue |   55 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/src/views/energyManagement/energyConsumptionStatistical/index.vue b/src/views/energyManagement/energyConsumptionStatistical/index.vue
index 8e540b8..df70d25 100644
--- a/src/views/energyManagement/energyConsumptionStatistical/index.vue
+++ b/src/views/energyManagement/energyConsumptionStatistical/index.vue
@@ -657,10 +657,29 @@
 
   // 缁熻缁村害鍒囨崲
   const handleTypeChange = () => {
-    // 閲嶇疆鏃堕棿鑼冨洿
-    searchForm.dateRange = [];
-    searchForm.monthRange = [];
-    searchForm.year = new Date().getFullYear();
+    // 閲嶇疆鏃堕棿鑼冨洿骞惰缃粯璁ゅ��
+    const end = new Date();
+    const start = new Date();
+
+    if (statisticsType.value === "day") {
+      // 榛樿鏈�杩�7澶�
+      start.setDate(start.getDate() - 6);
+      searchForm.dateRange = [
+        start.toISOString().split("T")[0],
+        end.toISOString().split("T")[0],
+      ];
+    } else if (statisticsType.value === "month") {
+      // 榛樿鏈�杩�3涓湀
+      start.setMonth(start.getMonth() - 2);
+      searchForm.monthRange = [
+        start.toISOString().slice(0, 7),
+        end.toISOString().slice(0, 7),
+      ];
+    } else if (statisticsType.value === "year") {
+      // 榛樿褰撳墠骞翠唤
+      searchForm.year = new Date().getFullYear();
+    }
+
     page.current = 1;
     handleQuery();
   };
@@ -670,6 +689,12 @@
     tableLoading.value = true;
     const params = {
       type: "",
+      state:
+        statisticsType.value === "day"
+          ? "鏃�"
+          : statisticsType.value === "month"
+          ? "鏈�"
+          : "骞�",
     };
 
     // 鏋勯�犺姹傚弬鏁�
@@ -689,14 +714,20 @@
     } else if (statisticsType.value === "month") {
       if (searchForm.monthRange && searchForm.monthRange.length === 2) {
         params.startDate = searchForm.monthRange[0] + "-01";
-        params.endDate = searchForm.monthRange[1] + "-01";
-        // 璁$畻鏈堟暟
-        const start = new Date(searchForm.monthRange[0] + "-01");
-        const end = new Date(searchForm.monthRange[1] + "-01");
-        params.days =
-          (end.getFullYear() - start.getFullYear()) * 12 +
-          (end.getMonth() - start.getMonth()) +
-          1;
+        const [endYearStr, endMonthStr] = String(searchForm.monthRange[1]).split(
+          "-"
+        );
+        const endYear = Number(endYearStr);
+        const endMonth = Number(endMonthStr);
+        const lastDay = new Date(endYear, endMonth, 0).getDate();
+        params.endDate = `${endYearStr}-${endMonthStr}-${String(lastDay).padStart(
+          2,
+          "0"
+        )}`;
+        // 璁$畻澶╂暟
+        const start = new Date(params.startDate);
+        const end = new Date(params.endDate);
+        params.days = Math.ceil((end - start) / (1000 * 60 * 60 * 24)) + 1;
       }
     } else if (statisticsType.value === "year") {
       params.startDate = searchForm.year + "-01-01";

--
Gitblit v1.9.3