feat: add withdrawal requests feature and update VAT loading mechanism
Build and Deploy / build (push) Successful in 1m25s
Build and Deploy / build (push) Successful in 1m25s
This commit is contained in:
@@ -192,6 +192,17 @@
|
||||
</MudCard>
|
||||
</MudLink>
|
||||
</MudItem>
|
||||
<MudItem xs="6" sm="6" md="3">
|
||||
<MudLink Href="@RouteConstants.Profile.WithdrawalRequests" Underline="Underline.None" Class="tile-link">
|
||||
<MudCard Elevation="1" Class="rounded-lg profile-tile">
|
||||
<MudCardContent Class="d-flex flex-column align-center pa-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.RequestPage" Size="Size.Large" Color="Color.Warning" />
|
||||
<MudText Typo="Typo.subtitle1" Class="mt-2">درخواست برداشت</MudText>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">ثبت و پیگیری برداشت</MudText>
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
</MudLink>
|
||||
</MudItem>
|
||||
<MudItem xs="6" sm="6" md="3">
|
||||
<MudLink Href="@RouteConstants.Club.Membership" Underline="Underline.None" Class="tile-link">
|
||||
<MudCard Elevation="1" Class="rounded-lg profile-tile">
|
||||
|
||||
@@ -17,14 +17,9 @@
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg" Style="background-color: var(--mud-palette-warning-lighten);">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Discount" Color="Color.Warning" Size="Size.Large" />
|
||||
<MudStack Spacing="0">
|
||||
<MudText Typo="Typo.subtitle2" Style="color: var(--mud-palette-warning-darken);">موجودی تخفیف باشگاه</MudText>
|
||||
<MudText Typo="Typo.h4" Style="color: var(--mud-palette-warning-darken);"><strong>@_balances.Discount</strong></MudText>
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.subtitle2" Class="mud-text-secondary">موجودی فروشگاه تخفیفی</MudText>
|
||||
<MudText Typo="Typo.h4" Color="Color.Warning">@_balances.Discount</MudText>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
@@ -35,61 +30,45 @@
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">درخواست برداشت از موجودی شبکه</MudText>
|
||||
<MudStack Spacing="2">
|
||||
<MudTextField @bind-Value="_withdrawPayoutId"
|
||||
Label="شناسه واریز (PayoutId)"
|
||||
Variant="Variant.Outlined"
|
||||
Type="MudBlazor.InputType.Number"
|
||||
Required="true" />
|
||||
<MudRadioGroup T="WithdrawalMethodClient" @bind-SelectedOption="_withdrawMethod" Row="true">
|
||||
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Cash" Label="برداشت نقدی (نیاز به شبا)" />
|
||||
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Diamond" Label="الماس/غیرنقدی" />
|
||||
</MudRadioGroup>
|
||||
<MudTextField @bind-Value="_withdrawIban"
|
||||
Label="شماره شبا"
|
||||
Variant="Variant.Outlined"
|
||||
Disabled="_withdrawMethod == WithdrawalMethodClient.Diamond"
|
||||
Placeholder="IRxxxxxxxxxxxx"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentText="IR" />
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">
|
||||
حداقل مبلغ برداشت: @FormatPrice(_minWithdrawalAmount)
|
||||
</MudText>
|
||||
<MudButton Disabled="_isSubmittingWithdrawal"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Outbound"
|
||||
OnClick="SubmitWithdrawal">
|
||||
@(_isSubmittingWithdrawal ? "در حال ثبت..." : "ثبت درخواست برداشت")
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
<!-- دکمه دسترسی سریع به درخواست برداشت -->
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Warning"
|
||||
Size="Size.Large"
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Filled.RequestPage"
|
||||
Href="@RouteConstants.Profile.WithdrawalRequests"
|
||||
Class="rounded-lg">
|
||||
درخواستهای برداشت
|
||||
</MudButton>
|
||||
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">تراکنشها و مسیرهای شارژ</MudText>
|
||||
|
||||
<MudStack Row="true" Spacing="2" Class="mb-3" AlignItems="AlignItems.End">
|
||||
<MudTextField @bind-Value="_filterReferenceId"
|
||||
Label="شناسه ارجاع"
|
||||
Variant="Variant.Outlined"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search" />
|
||||
<MudSelect T="string" @bind-Value="_filterType" Label="نوع تراکنش" Variant="Variant.Outlined">
|
||||
<MudSelectItem T="string" Value="@("all")">همه</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("in")">ورودی (شارژ)</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("out")">خروجی (برداشت/خرید)</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudSelect T="string" @bind-Value="_withdrawStatusFilter" Label="وضعیت برداشت" Variant="Variant.Outlined">
|
||||
<MudSelectItem T="string" Value="@("all")">همه</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("pending")">Pending</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("requested")">Requested</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("withdrawn")">Withdrawn</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("cancelled")">Cancelled</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudButton Variant="Variant.Outlined" OnClick="ApplyFilters" StartIcon="@Icons.Material.Filled.FilterList">اعمال فیلتر</MudButton>
|
||||
</MudStack>
|
||||
<MudGrid Spacing="2" Class="mb-3">
|
||||
<MudItem xs="6" md="4">
|
||||
<MudTextField @bind-Value="_filterReferenceId"
|
||||
Label="شناسه ارجاع"
|
||||
Variant="Variant.Outlined"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="6" md="4">
|
||||
<MudSelect T="string" @bind-Value="_filterType" Label="نوع تراکنش" Variant="Variant.Outlined" FullWidth="true">
|
||||
<MudSelectItem T="string" Value="@("all")">همه</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("in")">ورودی (شارژ)</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("out")">خروجی (برداشت/خرید)</MudSelectItem>
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="4" Class="d-flex align-end">
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
OnClick="ApplyFilters"
|
||||
StartIcon="@Icons.Material.Filled.FilterList"
|
||||
FullWidth="true">
|
||||
اعمال فیلتر
|
||||
</MudButton>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
|
||||
<MudTable Items="_txs" Dense="true">
|
||||
@@ -126,49 +105,5 @@
|
||||
</MudStack>
|
||||
</MudHidden>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">درخواستهای برداشت ثبتشده</MudText>
|
||||
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
|
||||
<MudTable Items="_withdrawals" Dense="true">
|
||||
<HeaderContent>
|
||||
<MudTh>هفته</MudTh>
|
||||
<MudTh>مبلغ</MudTh>
|
||||
<MudTh>وضعیت</MudTh>
|
||||
<MudTh>روش</MudTh>
|
||||
<MudTh>تاریخ</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>@context.WeekNumber</MudTd>
|
||||
<MudTd>@FormatPrice(context.Amount)</MudTd>
|
||||
<MudTd>
|
||||
<MudChip T="string" Color="@(ResolveStatusColor(context.Status))" Variant="Variant.Outlined" Size="Size.Small">
|
||||
@ResolveStatusText(context.Status)
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
<MudTd>@ResolveMethodText(context.Method)</MudTd>
|
||||
<MudTd>@context.Created</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</MudHidden>
|
||||
|
||||
<MudHidden Breakpoint="Breakpoint.MdAndUp">
|
||||
<MudStack Spacing="2">
|
||||
@foreach (var wd in _withdrawals)
|
||||
{
|
||||
<MudPaper Class="pa-3 rounded-lg" Outlined="true">
|
||||
<MudStack Spacing="1">
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
|
||||
<MudText>@wd.WeekNumber</MudText>
|
||||
<MudText Color="Color.Primary">@FormatPrice(wd.Amount)</MudText>
|
||||
</MudStack>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">وضعیت: @ResolveStatusText(wd.Status) | روش: @ResolveMethodText(wd.Method)</MudText>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">@wd.Created</MudText>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
}
|
||||
</MudStack>
|
||||
</MudHidden>
|
||||
</MudPaper>
|
||||
</MudStack>
|
||||
</MudContainer>
|
||||
|
||||
@@ -6,71 +6,20 @@ namespace FrontOffice.Main.Pages.Profile;
|
||||
|
||||
public partial class Wallet : ComponentBase
|
||||
{
|
||||
private long _minWithdrawalAmount = 1_000_000; // مقدار پیشفرض، از CMS خوانده میشود
|
||||
private (string Credit, string Discount, string Network) _balances = ("-", "-", "-");
|
||||
private List<WalletTransaction> _txs = new();
|
||||
private List<WalletWithdrawal> _withdrawals = new();
|
||||
private string? _filterReferenceId;
|
||||
private string _filterType = "all";
|
||||
private string _withdrawStatusFilter = "all";
|
||||
private bool _isSubmittingWithdrawal;
|
||||
private long _withdrawPayoutId;
|
||||
private WithdrawalMethodClient _withdrawMethod = WithdrawalMethodClient.Cash;
|
||||
private string? _withdrawIban;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var b = await WalletService.GetBalancesAsync();
|
||||
_balances = (FormatPrice(b.CreditBalance), FormatPrice(b.DiscountBalance), FormatPrice(b.NetworkBalance));
|
||||
_txs = await WalletService.GetTransactionsAsync();
|
||||
_withdrawals = await WalletService.GetWithdrawalsAsync();
|
||||
var settings = await WalletService.GetWithdrawalSettingsAsync();
|
||||
if (settings.MinWithdrawalAmount > 0)
|
||||
_minWithdrawalAmount = settings.MinWithdrawalAmount;
|
||||
}
|
||||
|
||||
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
|
||||
|
||||
private async Task SubmitWithdrawal()
|
||||
{
|
||||
var target = _withdrawals.FirstOrDefault(x => x.Id == _withdrawPayoutId);
|
||||
if (target is null)
|
||||
{
|
||||
_withdrawals = await WalletService.GetWithdrawalsAsync();
|
||||
target = _withdrawals.FirstOrDefault(x => x.Id == _withdrawPayoutId);
|
||||
}
|
||||
if (target != null && target.Amount < _minWithdrawalAmount)
|
||||
{
|
||||
Snackbar.Add($"مبلغ این واریز کمتر از حداقل برداشت ({_minWithdrawalAmount:N0} تومان) است.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (_withdrawPayoutId <= 0)
|
||||
{
|
||||
Snackbar.Add("شناسه واریز (PayoutId) الزامی است.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (_withdrawMethod == WithdrawalMethodClient.Cash && string.IsNullOrWhiteSpace(_withdrawIban))
|
||||
{
|
||||
Snackbar.Add("برای برداشت نقدی، شماره شبا لازم است.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_isSubmittingWithdrawal = true;
|
||||
await WalletService.RequestWithdrawalAsync(_withdrawPayoutId, _withdrawMethod, _withdrawIban);
|
||||
Snackbar.Add("درخواست برداشت ثبت شد.", Severity.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"خطا در ثبت برداشت: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSubmittingWithdrawal = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApplyFilters()
|
||||
{
|
||||
long? refId = null;
|
||||
@@ -85,39 +34,5 @@ public partial class Wallet : ComponentBase
|
||||
_ => null
|
||||
};
|
||||
_txs = await WalletService.GetTransactionsAsync(refId, isIncrease);
|
||||
int? status = _withdrawStatusFilter switch
|
||||
{
|
||||
"pending" => 1,
|
||||
"requested" => 2,
|
||||
"withdrawn" => 3,
|
||||
"cancelled" => 4,
|
||||
_ => null
|
||||
};
|
||||
_withdrawals = await WalletService.GetWithdrawalsAsync(status);
|
||||
}
|
||||
|
||||
private static string ResolveStatusText(int status) => status switch
|
||||
{
|
||||
0 => "ایجاد شده",
|
||||
1 => "پرداخت شده",
|
||||
2 => "درخواست برداشت",
|
||||
3 => "برداشت شده",
|
||||
4 => "لغو شده",
|
||||
_ => status.ToString()
|
||||
};
|
||||
|
||||
private static Color ResolveStatusColor(int status) => status switch
|
||||
{
|
||||
2 => Color.Warning,
|
||||
3 => Color.Success,
|
||||
4 => Color.Error,
|
||||
_ => Color.Info
|
||||
};
|
||||
|
||||
private static string ResolveMethodText(int? method) => method switch
|
||||
{
|
||||
0 => "نقدی",
|
||||
1 => "الماس",
|
||||
_ => "-"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
@attribute [Route(RouteConstants.Profile.WithdrawalRequests)]
|
||||
|
||||
<PageTitle>درخواستهای برداشت</PageTitle>
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.Large" Class="py-6">
|
||||
<MudStack Spacing="3">
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
|
||||
<MudText Typo="Typo.h5">درخواستهای برداشت</MudText>
|
||||
<MudButton Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ArrowBack" Href="@RouteConstants.Profile.Wallet">بازگشت به کیف پول</MudButton>
|
||||
</MudStack>
|
||||
|
||||
<!-- فرم درخواست برداشت جدید -->
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">ثبت درخواست برداشت جدید</MudText>
|
||||
<MudStack Spacing="2">
|
||||
<MudTextField @bind-Value="_withdrawPayoutId"
|
||||
Label="شناسه واریز (PayoutId)"
|
||||
Variant="Variant.Outlined"
|
||||
Type="MudBlazor.InputType.Number"
|
||||
Required="true" />
|
||||
<MudRadioGroup T="WithdrawalMethodClient" @bind-Value="_withdrawMethod" Row="true">
|
||||
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Cash" Color="Color.Primary">برداشت نقدی (نیاز به شبا)</MudRadio>
|
||||
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Diamond" Color="Color.Secondary">الماس/غیرنقدی</MudRadio>
|
||||
</MudRadioGroup>
|
||||
<MudTextField @bind-Value="_withdrawIban"
|
||||
Label="شماره شبا"
|
||||
Variant="Variant.Outlined"
|
||||
Disabled="_withdrawMethod == WithdrawalMethodClient.Diamond"
|
||||
Placeholder="IRxxxxxxxxxxxx"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentText="IR" />
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">
|
||||
حداقل مبلغ برداشت: @FormatPrice(_minWithdrawalAmount)
|
||||
</MudText>
|
||||
<MudButton Disabled="_isSubmittingWithdrawal"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Outbound"
|
||||
OnClick="SubmitWithdrawal">
|
||||
@(_isSubmittingWithdrawal ? "در حال ثبت..." : "ثبت درخواست برداشت")
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
<!-- فیلتر وضعیت -->
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.End">
|
||||
<MudSelect T="string" @bind-Value="_statusFilter" Label="فیلتر وضعیت" Variant="Variant.Outlined" Style="min-width: 180px;">
|
||||
<MudSelectItem T="string" Value="@("all")">همه</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("pending")">در انتظار</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("requested")">درخواست شده</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("withdrawn")">برداشت شده</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("cancelled")">لغو شده</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudButton Variant="Variant.Outlined" OnClick="ApplyFilter" StartIcon="@Icons.Material.Filled.FilterList">اعمال فیلتر</MudButton>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
<!-- لیست درخواستهای برداشت -->
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-3">لیست درخواستها</MudText>
|
||||
|
||||
@if (_isLoading)
|
||||
{
|
||||
<MudProgressLinear Color="Color.Primary" Indeterminate="true" />
|
||||
}
|
||||
else if (!_withdrawals.Any())
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
|
||||
هنوز درخواست برداشتی ثبت نشده است.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<!-- نمایش دسکتاپ -->
|
||||
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
|
||||
<MudTable Items="_withdrawals" Dense="true" Hover="true" Striped="true">
|
||||
<HeaderContent>
|
||||
<MudTh>هفته</MudTh>
|
||||
<MudTh>مبلغ</MudTh>
|
||||
<MudTh>وضعیت</MudTh>
|
||||
<MudTh>روش برداشت</MudTh>
|
||||
<MudTh>تاریخ ثبت</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="هفته">@context.WeekDisplayName</MudTd>
|
||||
<MudTd DataLabel="مبلغ">@FormatPrice(context.Amount)</MudTd>
|
||||
<MudTd DataLabel="وضعیت">
|
||||
<MudChip T="string" Color="@(ResolveStatusColor(context.Status))" Variant="Variant.Filled" Size="Size.Small">
|
||||
@ResolveStatusText(context.Status)
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="روش">@ResolveMethodText(context.Method)</MudTd>
|
||||
<MudTd DataLabel="تاریخ">@context.Created</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</MudHidden>
|
||||
|
||||
<!-- نمایش موبایل -->
|
||||
<MudHidden Breakpoint="Breakpoint.MdAndUp">
|
||||
<MudStack Spacing="2">
|
||||
@foreach (var wd in _withdrawals)
|
||||
{
|
||||
<MudPaper Class="pa-3 rounded-lg" Outlined="true">
|
||||
<MudStack Spacing="1">
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
|
||||
<MudText Typo="Typo.subtitle2">@wd.WeekDisplayName</MudText>
|
||||
<MudChip T="string" Color="@(ResolveStatusColor(wd.Status))" Variant="Variant.Filled" Size="Size.Small">
|
||||
@ResolveStatusText(wd.Status)
|
||||
</MudChip>
|
||||
</MudStack>
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
|
||||
<MudText Typo="Typo.h6" Color="Color.Primary">@FormatPrice(wd.Amount)</MudText>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">@ResolveMethodText(wd.Method)</MudText>
|
||||
</MudStack>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">@wd.Created</MudText>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
}
|
||||
</MudStack>
|
||||
</MudHidden>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudStack>
|
||||
</MudContainer>
|
||||
@@ -0,0 +1,123 @@
|
||||
using FrontOffice.Main.Utilities;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
namespace FrontOffice.Main.Pages.Profile;
|
||||
|
||||
public partial class WithdrawalRequests : ComponentBase
|
||||
{
|
||||
private long _minWithdrawalAmount = 1_000_000;
|
||||
private List<WalletWithdrawal> _withdrawals = new();
|
||||
private string _statusFilter = "all";
|
||||
private bool _isLoading = true;
|
||||
private bool _isSubmittingWithdrawal;
|
||||
private long _withdrawPayoutId;
|
||||
private WithdrawalMethodClient _withdrawMethod = WithdrawalMethodClient.Cash;
|
||||
private string? _withdrawIban;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isLoading = true;
|
||||
try
|
||||
{
|
||||
_withdrawals = await WalletService.GetWithdrawalsAsync();
|
||||
var settings = await WalletService.GetWithdrawalSettingsAsync();
|
||||
if (settings.MinWithdrawalAmount > 0)
|
||||
_minWithdrawalAmount = settings.MinWithdrawalAmount;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
|
||||
|
||||
private async Task SubmitWithdrawal()
|
||||
{
|
||||
if (_withdrawPayoutId <= 0)
|
||||
{
|
||||
Snackbar.Add("شناسه واریز (PayoutId) الزامی است.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (_withdrawMethod == WithdrawalMethodClient.Cash && string.IsNullOrWhiteSpace(_withdrawIban))
|
||||
{
|
||||
Snackbar.Add("برای برداشت نقدی، شماره شبا لازم است.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_isSubmittingWithdrawal = true;
|
||||
await WalletService.RequestWithdrawalAsync(_withdrawPayoutId, _withdrawMethod, _withdrawIban);
|
||||
Snackbar.Add("درخواست برداشت ثبت شد.", Severity.Success);
|
||||
|
||||
// بروزرسانی لیست
|
||||
await LoadData();
|
||||
|
||||
// ریست فرم
|
||||
_withdrawPayoutId = 0;
|
||||
_withdrawIban = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"خطا در ثبت برداشت: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSubmittingWithdrawal = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApplyFilter()
|
||||
{
|
||||
_isLoading = true;
|
||||
try
|
||||
{
|
||||
int? status = _statusFilter switch
|
||||
{
|
||||
"pending" => 1,
|
||||
"requested" => 2,
|
||||
"withdrawn" => 3,
|
||||
"cancelled" => 4,
|
||||
_ => null
|
||||
};
|
||||
_withdrawals = await WalletService.GetWithdrawalsAsync(status);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string ResolveStatusText(int status) => status switch
|
||||
{
|
||||
0 => "ایجاد شده",
|
||||
1 => "در انتظار پرداخت",
|
||||
2 => "درخواست برداشت",
|
||||
3 => "برداشت شده",
|
||||
4 => "لغو شده",
|
||||
_ => status.ToString()
|
||||
};
|
||||
|
||||
private static Color ResolveStatusColor(int status) => status switch
|
||||
{
|
||||
1 => Color.Info,
|
||||
2 => Color.Warning,
|
||||
3 => Color.Success,
|
||||
4 => Color.Error,
|
||||
_ => Color.Default
|
||||
};
|
||||
|
||||
private static string ResolveMethodText(int? method) => method switch
|
||||
{
|
||||
0 => "نقدی (شبا)",
|
||||
1 => "الماس",
|
||||
_ => "-"
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user