Bladeren bron

fix送出後的顯示問題

master
Joanne.Chuang 2 weken geleden
bovenliggende
commit
be49892e4c
2 gewijzigde bestanden met toevoegingen van 36 en 23 verwijderingen
  1. +0
    -23
      Altob.NtuInvoiceGateway/Pages/Invoice.cshtml
  2. +36
    -0
      Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs

+ 0
- 23
Altob.NtuInvoiceGateway/Pages/Invoice.cshtml Bestand weergeven

@@ -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();
});


+ 36
- 0
Altob.NtuInvoiceGateway/Pages/Invoice.cshtml.cs Bestand weergeven

@@ -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<InvoiceModel> 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<IActionResult> 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<InvoiceRequest>(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));
}
}
}

Laden…
Annuleren
Opslaan