This commit is contained in:
MeysamMoghaddam
2025-10-13 18:38:02 +03:30
parent d68f0189f4
commit 15d9f7f96a
2 changed files with 78 additions and 57 deletions

View File

@@ -13,7 +13,7 @@
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3">
<MudIcon Icon="@Icons.Material.Filled.ShoppingCart" Size="Size.Large" Color="Color.Primary" />
<div>
<MudText Typo="Typo.h4" >تکمیل خرید</MudText>
<MudText Typo="Typo.h4">تکمیل خرید</MudText>
<MudText Typo="Typo.body2" Class="mud-text-secondary">مرحله نهایی خرید پکیج</MudText>
</div>
</MudStack>
@@ -86,16 +86,24 @@
Elevation="@(_selectedAddress?.Id == address.Id ? 4 : 0)"
Class="pa-3 rounded-xl cursor-pointer"
Style="@(_selectedAddress?.Id == address.Id ? "border: 2px solid var(--mud-palette-primary);" : "")"
OnClick="() => SelectAddress(address)">
@onclick="() => SetAddressAsDefault(address.Id)">
<MudStack Spacing="1">
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
<MudRadio T="long" Value="address.Id" Checked="@(_selectedAddress?.Id == address.Id)" />
<MudText Typo="Typo.subtitle2">@address.Title</MudText>
<MudCheckBox @bind-Value="address.IsDefault"
Disabled="true"
Color="Color.Primary" />
<MudText Typo="Typo.subtitle2">@(address.Title)</MudText>
@if (address.IsDefault)
{
<MudChip T="string" Color="Color.Success" Variant="Variant.Filled" Size="Size.Small">پیش‌فرض</MudChip>
}
@if (!address.IsDefault)
{
@if (_isSettingDefaultAddress && _settingDefaultAddressId == address.Id)
{
<MudProgressCircular Size="Size.Small" Color="Color.Primary" Indeterminate="true" />
}
else
{
<MudButton Variant="Variant.Text"
Color="Color.Primary"
@@ -104,9 +112,13 @@
تنظیم به عنوان پیش‌فرض
</MudButton>
}
}
</MudStack>
<MudStack Row="true">
<MudText Typo="Typo.body2" Class="mud-text-secondary">@(address.Address)</MudText>
<MudSpacer />
<MudText Typo="Typo.caption" Class="mud-text-secondary">کد پستی: @(address.PostalCode)</MudText>
</MudStack>
<MudText Typo="Typo.body2" Class="mud-text-secondary">@address.Address</MudText>
<MudText Typo="Typo.caption" Class="mud-text-secondary">کد پستی: @address.PostalCode</MudText>
</MudStack>
</MudPaper>
}
@@ -140,23 +152,22 @@
<MudPaper Elevation="4" Class="pa-6">
<MudText Typo="Typo.h5" Class="mb-4">کد تخفیف</MudText>
<MudStack Spacing="3">
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.Stretch">
<MudTextField @bind-Value="_discountCode"
Label="کد تخفیف"
Variant="Variant.Outlined"
Class="flex-grow-1"
Placeholder="کد تخفیف خود را وارد کنید" />
<MudButton Variant="Variant.Filled"
Color="Color.Secondary"
OnClick="ApplyDiscountCode"
Disabled="_isApplyingDiscount">
اعمال
</MudButton>
</MudStack>
@if (!string.IsNullOrWhiteSpace(_discountMessage))
{
<MudText Typo="Typo.caption" Color="@(_discountApplied ? Color.Success : Color.Error)" Class="mt-2">
@_discountMessage
@(_discountMessage)
</MudText>
}
</MudStack>
@@ -170,23 +181,23 @@
<MudStack Spacing="3">
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.body1">پکیج @(_selectedPackage.Title)</MudText>
<MudText Typo="Typo.body1">@_selectedPackage.Price.ToThousands().ToCurrencyUnitIRT()</MudText>
<MudText Typo="Typo.body1">@(_selectedPackage.Title)</MudText>
<MudText Typo="Typo.body1">@(_selectedPackage.Price.ToThousands().ToCurrencyUnitIRT())</MudText>
</MudStack>
@if (_discountApplied && _discountAmount > 0)
{
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.body2" Color="Color.Success">تخفیف (@_discountCode)</MudText>
<MudText Typo="Typo.body2" Color="Color.Success">-@_discountAmount.ToThousands().ToCurrencyUnitIRT()</MudText>
<MudText Typo="Typo.body2" Color="Color.Success">تخفیف (@(_discountCode))</MudText>
<MudText Typo="Typo.body2" Color="Color.Success">-@(_discountAmount.ToThousands().ToCurrencyUnitIRT())</MudText>
</MudStack>
}
<MudDivider />
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.h6" >مجموع</MudText>
<MudText Typo="Typo.h6" Color="Color.Primary">@_finalPrice.ToThousands().ToCurrencyUnitIRT()</MudText>
<MudText Typo="Typo.h6">مجموع</MudText>
<MudText Typo="Typo.h6" Color="Color.Primary">@(_finalPrice.ToThousands().ToCurrencyUnitIRT())</MudText>
</MudStack>
<MudButton Variant="Variant.Filled"

View File

@@ -33,6 +33,10 @@ public partial class Checkout
private long _discountAmount;
private long _finalPrice;
// Address management
private bool _isSettingDefaultAddress;
private long? _settingDefaultAddressId;
private bool CanProceedToPayment => _selectedPackage != null && _selectedAddress != null;
protected override async Task OnInitializedAsync()
@@ -96,14 +100,13 @@ public partial class Checkout
}
}
private void SelectAddress(GetAllUserAddressByFilterResponseModel address)
{
_selectedAddress = address;
StateHasChanged();
}
private async Task SetAddressAsDefault(long addressId)
{
if (_isSettingDefaultAddress) return;
_isSettingDefaultAddress = true;
_settingDefaultAddressId = addressId;
try
{
await UserAddressContract.SetAddressAsDefaultAsync(new() { Id = addressId });
@@ -114,6 +117,12 @@ public partial class Checkout
{
Snackbar.Add($"خطا در تغییر آدرس پیش‌فرض: {ex.Message}", Severity.Error);
}
finally
{
_isSettingDefaultAddress = false;
_settingDefaultAddressId = null;
await InvokeAsync(StateHasChanged);
}
}
private async Task ApplyDiscountCode()
@@ -163,6 +172,9 @@ public partial class Checkout
private async Task ProcessPayment()
{
Snackbar.Add("درگاه پرداخت متصل نیست! لطفا در زمان دیگری مجددا تلاش فرمایید!", Severity.Warning);
return;
if (!CanProceedToPayment || _selectedPackage == null || _selectedAddress == null)
{
Snackbar.Add("لطفاً پکیج و آدرس را انتخاب کنید.", Severity.Warning);
@@ -186,9 +198,7 @@ public partial class Checkout
var paymentResponse = await TransactionContract.PaymentRequestAsync(paymentRequest);
if (string.IsNullOrEmpty(paymentResponse.PaymentGWUrl))
{
throw new Exception("آدرس درگاه پرداخت دریافت نشد.");
}
Snackbar.Add("آدرس درگاه پرداخت دریافت نشد.", Severity.Error);
// Step 2: Create user order
var orderRequest = new CreateNewUserOrderRequest