diff --git a/src/components/PdfContent.vue b/src/components/PdfContent.vue index cb48dc5..70c8021 100644 --- a/src/components/PdfContent.vue +++ b/src/components/PdfContent.vue @@ -1,7 +1,7 @@ - + @@ -29,7 +29,7 @@ - + {{ Three_Phase }} - - - 基本電費-經常契約 - - {{ Regular_Contract_Summer }} - - - - 基本電費-經常契約 - - {{ Regular_Contract_Non_Summer }} - - - - 流動電價-平日尖峰單價 - - {{ Summer_Peak_Prices }} - - - - 流動電價-平日半尖峰單價 - - {{ - isSummerMonth - ? Summer_HalfPeak_Prices_Weekday - : Non_Summer_HalfPeak_Prices_Weekday - }} - - - - 流動電價-平日離峰單價 - - {{ - isSummerMonth - ? Summer_Off_Prices_Weekday - : Non_Summer_Off_Prices_Weekday - }} - - - - 流動電價-週六半尖峰單價 - - {{ - isSummerMonth - ? Summer_HalfPeak_Prices_Saturday - : Non_Summer_HalfPeak_Prices_Saturday - }} - - - - 流動電價-週六離峰單價 - - {{ - isSummerMonth - ? Summer_Off_Prices_Saturday - : Non_Summer_Off_Prices_Saturday - }} - - - - 流動電價-週日離峰單價 - - {{ isSummerMonth ? Summer_Off_Prices : Non_Summer_Off_Prices }} - 契約容量 {{ ContractUse }} + + + + 流動電價-平日尖峰單價 + + + + {{ Summer_Peak_Prices }} + + + + + 基本電費-經常契約 + + + + {{ + isSummerMonth === "summer" + ? Regular_Contract_Summer + : isSummerMonth === "non-summer" + ? Regular_Contract_Non_Summer + : `${Regular_Contract_Summer} / ${Regular_Contract_Non_Summer}` + }} + + + + + + 流動電價-平日半尖峰單價 + + + + {{ + isSummerMonth === "summer" + ? Summer_HalfPeak_Prices_Weekday + : isSummerMonth === "non-summer" + ? Non_Summer_HalfPeak_Prices_Weekday + : `${Summer_HalfPeak_Prices_Weekday} / ${Non_Summer_HalfPeak_Prices_Weekday}` + }} + + + + + 流動電價-平日離峰單價 + + + + {{ + isSummerMonth === "summer" + ? Summer_Off_Prices_Weekday + : isSummerMonth === "non-summer" + ? Non_Summer_Off_Prices_Weekday + : `${Summer_Off_Prices_Weekday} / ${Non_Summer_Off_Prices_Weekday}` + }} + + + + + 流動電價-週六半尖峰單價 + + + + {{ + isSummerMonth === "summer" + ? Summer_HalfPeak_Prices_Saturday + : isSummerMonth === "non-summer" + ? Non_Summer_HalfPeak_Prices_Saturday + : `${Summer_HalfPeak_Prices_Saturday} / ${Non_Summer_HalfPeak_Prices_Saturday}` + }} + + + + + 流動電價-週六離峰單價 + + + + {{ + isSummerMonth === "summer" + ? Summer_Off_Prices_Saturday + : isSummerMonth === "non-summer" + ? Non_Summer_Off_Prices_Saturday + : `${Summer_Off_Prices_Saturday} / ${Non_Summer_Off_Prices_Saturday}` + }} + + + + + 流動電價-週日離峰單價 + + + + {{ + isSummerMonth === "summer" + ? Summer_Off_Prices + : isSummerMonth === "non-summer" + ? Non_Summer_Off_Prices + : `${Summer_Off_Prices} / ${Non_Summer_Off_Prices}` + }} + - + @@ -199,6 +235,11 @@ + + + 本系統所提供之時間電價計算結果,係以未超過契約容量為前提所進行之估算,僅供用電分析與管理參考之用。 + + @@ -239,12 +280,26 @@ const loading = computed(() => { }); const isSummerMonth = computed(() => { - const month = dayjs(props.form?.date).month(); // month() 返回 0-11,代表一月到十二月 - return month >= 5 && month <= 8; // 月份範圍,6月是 5,9月是 8 + const date = dayjs(props.form?.date); + const month = date.month() + 1; // 代表一月到十二月 + + if (month > 5 && month < 10) { + return "summer"; + } else if (month === 5 || month === 10) { + return "half-summer"; + } else { + return "non-summer"; + } }); const priceTitle = computed(() => { - return isSummerMonth.value ? "單價(NTD/kWh)-夏月" : "單價(NTD/kWh)-非夏月"; + if (isSummerMonth.value === "summer") { + return "單價(NTD/kWh)-夏月"; + } else if (isSummerMonth.value === "non-summer") { + return "單價(NTD/kWh)-非夏月"; + } else { + return "單價(NTD/kWh)-夏月/非夏月"; + } }); const formattedElecCostSummary = computed(() => { diff --git a/src/utils/CalcuEleCost.ts b/src/utils/CalcuEleCost.ts index b16baa0..e4df135 100644 --- a/src/utils/CalcuEleCost.ts +++ b/src/utils/CalcuEleCost.ts @@ -60,7 +60,9 @@ export const CalcuEleCost = (input: Map): ElecCostSummary => { const sampleDate = entries[0].time; const dayOfWeek = sampleDate.getDay(); - const month = sampleDate.getMonth() + 1; + const year = sampleDate.getFullYear(); + const summerStart = new Date(`${year}-05-16`); + const summerEnd = new Date(`${year}-10-15`); let off = 0; //離峰用電 let half = 0; //半尖峰用電 @@ -71,7 +73,7 @@ export const CalcuEleCost = (input: Map): ElecCostSummary => { let dailyFlowCost = 0; //當日電價 let dailyEleCost = 0; //當日用電 - const isSummer = month >= 6 && month <= 9; + const isSummer = sampleDate >= summerStart && sampleDate <= summerEnd; entries.forEach(({ time, value }) => { const hour = time.getHours(); @@ -191,10 +193,14 @@ export const CalcuEleStandCost = ( for (const [ym, entries] of monthMap.entries()) { if (!entries || entries.length === 0) continue; - + const sampleDate = entries[0].time; - const month = sampleDate.getMonth() + 1; - const isSummer = month >= 6 && month <= 9; + //const month = sampleDate.getMonth() + 1; + // 修改 isSummer 判斷方式:從月改為日期範圍 5/16 ~ 10/15 + const year = sampleDate.getFullYear(); + const summerStart = new Date(`${year}-05-16`); + const summerEnd = new Date(`${year}-10-15`); + const isSummer = sampleDate >= summerStart && sampleDate <= summerEnd; let Phase = Three_Phase; let Contract = isSummer ? Summer_Regular_Use : Non_Summer_Regular_Use; diff --git a/src/views/EnergyPricing.vue b/src/views/EnergyPricing.vue index 2623a65..4bc098c 100644 --- a/src/views/EnergyPricing.vue +++ b/src/views/EnergyPricing.vue @@ -43,7 +43,7 @@ 分類 - 夏月(6/1~9/30) + 夏月(5/16~10/15) 非夏月(夏月以外的時間) diff --git a/src/views/MonthlyReport.vue b/src/views/MonthlyReport.vue index 87ec679..f4664db 100644 --- a/src/views/MonthlyReport.vue +++ b/src/views/MonthlyReport.vue @@ -52,7 +52,7 @@ :show-layout="false" :float-layout="true" :enable-download="true" - :preview-modal="true" + :preview-modal="false" :filename="pdfFileName" :pdf-quality="2" :manual-pagination="false" @@ -121,8 +121,12 @@ const handleClose = () => { // 觸發 PDF 生成和下載 const generatePDF = async () => { - if (html2Pdf.value) { - await html2Pdf.value.generatePdf(); + try { + if (html2Pdf.value) { + await html2Pdf.value.generatePdf(); + } + } catch (error) { + console.error("PDF生成失敗:", error); } };
+ 本系統所提供之時間電價計算結果,係以未超過契約容量為前提所進行之估算,僅供用電分析與管理參考之用。 +