zhangwencui
7 小时以前 e95d6f2a9141c05903098065b4356d1158c0c4e2
src/views/energyManagement/energyConsumptionStatistical/index.vue
@@ -689,6 +689,12 @@
    tableLoading.value = true;
    const params = {
      type: "",
      state:
        statisticsType.value === "day"
          ? "日"
          : statisticsType.value === "month"
          ? "月"
          : "年",
    };
    // 构造请求参数
@@ -708,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";