From be49892e4c919fa2fab04387c16b7a4926447a6b Mon Sep 17 00:00:00 2001 From: "Joanne.Chuang" Date: Wed, 14 Jan 2026 20:20:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=E9=80=81=E5=87=BA=E5=BE=8C=E7=9A=84?= =?UTF-8?q?=E9=A1=AF=E7=A4=BA=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Altob.NtuInvoiceGateway/Pages/Invoice.cshtml | 23 ---------------- Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs | 36 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml b/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml index 6d3f814..c6a3a17 100644 --- a/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml +++ b/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml @@ -176,15 +176,6 @@ const successAlert = document.getElementById('formSuccessMessage'); const submitButtonContainer = document.getElementById('submitButtonContainer'); - const showError = (message) => { - if (!errorAlert || !errorText) { - alert(message); - return; - } - errorText.textContent = message; - errorAlert.classList.remove('d-none'); - }; - const hideError = () => { if (!errorAlert || !errorText) { return; @@ -195,13 +186,6 @@ errorCloseBtn?.addEventListener('click', hideError); - const requiredGroup = [ - document.querySelector('input[name="InvoiceData.Email"]'), - document.querySelector('input[name="InvoiceData.CarrierID"]'), - document.querySelector('input[name="InvoiceData.BuyerIdentifier"]'), - document.querySelector('select[name="InvoiceData.LoveCode"]') - ]; - const form = document.querySelector('form[method="post"]'); if (!form) { return; @@ -234,13 +218,6 @@ return; } - const hasValue = requiredGroup.some(field => field && field.value.trim() !== ''); - if (!hasValue) { - event.preventDefault(); - showError('Email、手機條碼、購買者統編、捐贈碼至少需填寫一項。'); - return; - } - hideError(); lockForm(); }); diff --git a/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs b/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs index 1be545f..0fddc12 100644 --- a/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs +++ b/Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs @@ -20,6 +20,7 @@ public class InvoiceModel : PageModel private readonly DonateCodeApiOptions _donateCodeApiOptions; private const string ServiceName = "NtuInvoiceGateway"; private const string DonateCodeCacheKey = "DonateCodeList"; + private const string InvoiceDataTempKey = "InvoiceFormData"; public InvoiceModel( ILogger logger, @@ -52,11 +53,17 @@ public class InvoiceModel : PageModel public void OnGet() { + RestoreInvoiceDataFromTempData(); RestoreDisplayValuesFromTempData(); NormalizeInvoiceData(); // 如果有 GET 參數,設置顯示資訊 DisplayTransDateTime = InvoiceData.TransDateTime; DisplayTransAmount = InvoiceData.TransAmount; + + if (!Request.Query.Any()) + { + ModelState.Clear(); + } } public async Task OnGetDonateCodesAsync() @@ -280,6 +287,7 @@ public class InvoiceModel : PageModel SuccessMessage = "發票資訊送出成功!"; TempData[nameof(DisplayTransDateTime)] = DisplayTransDateTime; TempData[nameof(DisplayTransAmount)] = DisplayTransAmount; + TempData[InvoiceDataTempKey] = JsonSerializer.Serialize(InvoiceData); _logger.LogInformation("{ServiceName} - {ActionName} submitted successfully for OrderID: {OrderID}", ServiceName, actionName, InvoiceData.OrderID); return RedirectToPage(); @@ -337,4 +345,32 @@ public class InvoiceModel : PageModel DisplayTransAmount = amount; } } + + private void RestoreInvoiceDataFromTempData() + { + if (!TempData.TryGetValue(InvoiceDataTempKey, out var invoiceDataObj) || + invoiceDataObj is not string invoiceDataJson || + string.IsNullOrWhiteSpace(invoiceDataJson)) + { + return; + } + + try + { + var restoredData = JsonSerializer.Deserialize(invoiceDataJson, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }); + + if (restoredData != null) + { + InvoiceData = restoredData; + } + } + catch (JsonException ex) + { + _logger.LogWarning(ex, "{ServiceName} - {ActionName} failed to restore invoice data from temp data", + ServiceName, nameof(RestoreInvoiceDataFromTempData)); + } + } }