Files
moadiran/TaxPayerFull/Pages/UserPanel/Customer.razor

210 lines
8.0 KiB
Plaintext
Raw Normal View History

2024-04-22 23:32:39 +03:30
@page "/Customer"
2024-05-05 18:15:37 +03:30
@using Front.Services
2024-05-04 23:13:26 +03:30
@using Shared.DTOs
2024-05-05 18:15:37 +03:30
@using Front.CUSComponent
@using Shared.DTOs.Serch
@inject HttpClientController hc;
2024-05-04 23:13:26 +03:30
<PageTitle>مشتری</PageTitle>
2024-06-27 22:50:34 +03:30
<Modal Size="ModalSize.ExtraLarge" @ref="modal" />
2024-05-05 21:35:15 +03:30
<Preload LoadingText="در حال بارگذاری..." />
2024-05-04 23:13:26 +03:30
@* search *@
<div class="row">
2024-05-31 00:24:45 +03:30
<h4 class="fw-bold py-3 mb-4">
<span class="text-muted fw-light">سرویس ها /</span> مشتری
</h4>
2024-05-04 23:13:26 +03:30
<div class="col-md-12">
<div class="card mb-2">
<div class="row">
<div class="col-md-12">
<ul class="list-group fa-padding" style="border: 2px solid #0d6efd">
<li class="list-group-item" data-toggle="modal" data-target="#issue">
<div class="row g-3">
2024-05-06 17:22:02 +03:30
<div class="col-md-1">
2024-05-07 13:55:11 +03:30
<input @bind-value="itemsearch.ID" placeholder="شناسه" style="text-align:center;" class="form-control" type="text" >
2024-05-04 23:13:26 +03:30
</div>
2024-05-06 17:22:02 +03:30
<div class="col-md-2">
2024-05-07 13:55:11 +03:30
<select @bind="ItemSearchCustomertype" class="form-control" aria-label="Default select example">
<option value="0" style="color: #b5b5b5" selected>نوع مشتری...</option>
<option value="1">حقیقی</option>
<option value="2">حقوقی</option>
<option value="3">مشارکت مدنی</option>
<option value="4">اتباع غیر ایرانی</option>
</select>
2024-05-06 17:22:02 +03:30
</div>
<div class="col-md-2">
2024-05-07 13:55:11 +03:30
<input @bind-value="itemsearch.EconomicCode" placeholder="کد اقتصادی / کدملی" style="text-align:center;" class="form-control" type="text">
2024-05-06 17:22:02 +03:30
</div>
<div class="col-md-2">
2024-05-07 13:55:11 +03:30
<input @bind-value="itemsearch.Phone" placeholder="تلفن" style="text-align:center;" class="form-control" type="text">
2024-05-06 17:22:02 +03:30
</div>
<div class="col-md-2">
2024-05-07 13:55:11 +03:30
<input @bind-value="itemsearch.ZipCode" placeholder="کد پستی" style="text-align:center;" class="form-control" type="text">
2024-05-04 23:13:26 +03:30
</div>
<div class="col-auto">
2024-05-07 13:55:11 +03:30
<button @onclick="() => LoadCus(1)" type="submit" class="btn btn-primary">جستجو</button>
2024-05-04 23:13:26 +03:30
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
@* action *@
<div class="row">
<div class="col-md-12">
<div class="mb-2">
<div class="row">
<div class="col-md-12">
<div class="col-auto">
2024-05-08 17:25:02 +03:30
<button type="submit" @onclick="()=>CustomerItem(0)" class="btn btn-primary">جدید</button>
2024-05-04 23:13:26 +03:30
</div>
</div>
</div>
</div>
</div>
</div>
2024-05-05 18:15:37 +03:30
@* alert *@
2024-05-04 23:13:26 +03:30
<div class="row">
2024-05-05 18:15:37 +03:30
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
<Icon Name="@alertIconName" class="me-2"></Icon>
@alertMessage
</Alert>
2024-05-04 23:13:26 +03:30
</div>
2024-05-05 18:15:37 +03:30
@* data *@
@if (request != null)
{
2024-05-08 17:25:02 +03:30
<LTable ModelinComponent="request?.list" OnMultipleOfThree="EventCallback.Factory.Create<int>(this,CustomerItem)" />
2024-05-05 18:15:37 +03:30
@* pagination *@
2024-05-07 13:55:11 +03:30
<p style="color:red">@request?.RowCount آیتم یافت شد</p>
2024-05-05 18:15:37 +03:30
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
@for (int page = 1; page <= request?.PageCount; page++)
{
if (page == PageIndex)
{
2024-05-05 21:35:15 +03:30
<li class="page-item active">
2024-05-05 18:15:37 +03:30
<a class="page-link" href="@hc._nav.GetUriWithQueryParameter("PageIndex",page)">@(page)</a>
</li>
}
else
{
<li class="page-item">
<a class="page-link" href="@hc._nav.GetUriWithQueryParameter("PageIndex",page)">@(page)</a>
</li>
}
}
2024-05-05 21:35:15 +03:30
2024-05-05 18:15:37 +03:30
</ul>
</nav>
}
2024-04-22 23:32:39 +03:30
@layout PanelLayout
@code {
2024-05-05 21:35:15 +03:30
2024-05-07 13:55:11 +03:30
[Inject] protected PreloadService PreloadService { get; set; } = default!;
public int? ItemSearchCustomertype { get; set; }
ItemSerchGetCustomer itemsearch = new ItemSerchGetCustomer();
[Parameter, SupplyParameterFromQuery]
public int? PageIndex { get; set; }
public Shared.DTOs.PagingDto<RCustomer>? request { get; set; }
private Modal modal = default!;
2024-05-05 18:15:37 +03:30
// alert
AlertColor alertColor = AlertColor.Primary;
IconName alertIconName = IconName.CheckCircleFill;
bool Hidealert = true;
string alertMessage = "";
2024-05-04 23:13:26 +03:30
2024-05-05 18:15:37 +03:30
protected override async Task OnParametersSetAsync()
2024-05-04 23:13:26 +03:30
{
2024-05-05 18:15:37 +03:30
if (PageIndex == null) PageIndex = 1;
await LoadCus(PageIndex.Value);
await base.OnParametersSetAsync();
2024-05-07 13:55:11 +03:30
}
2024-05-05 18:15:37 +03:30
}
@functions {
private void ShowSuccessAlert(string msg)
{
Hidealert = false;
alertColor = AlertColor.Success;
alertIconName = IconName.CheckCircleFill;
alertMessage = msg;
2024-05-04 23:13:26 +03:30
}
2024-05-05 18:15:37 +03:30
private void ShowDangerAlert(string msg)
2024-05-04 23:13:26 +03:30
{
2024-05-05 18:15:37 +03:30
Hidealert = false;
alertColor = AlertColor.Danger;
alertIconName = IconName.ExclamationTriangleFill;
alertMessage = msg;
}
public async Task LoadCus(int pi)
{
2024-05-07 13:55:11 +03:30
if (ItemSearchCustomertype > 0)
itemsearch.CustomerType = (CustomerType)ItemSearchCustomertype;
else
itemsearch.CustomerType = null;
itemsearch.PageSize = 10;
itemsearch.PageIndex = pi;
2024-05-05 21:35:15 +03:30
PreloadService.Show(SpinnerColor.Dark);
2024-05-07 13:55:11 +03:30
var rsp = await hc.Post<ItemSerchGetCustomer>("Customer/GetAll", itemsearch);
2024-05-05 18:15:37 +03:30
if (rsp.IsSuccessStatusCode)
2024-05-04 23:13:26 +03:30
{
2024-05-05 18:15:37 +03:30
request = await rsp.Content.ReadFromJsonAsync<PagingDto<RCustomer>>();
}
else if(rsp.StatusCode==System.Net.HttpStatusCode.Forbidden)
{
ShowDangerAlert("شما دسترسی به خواندن اطلاعات مشتری را نداربد");
}
else
{
ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
2024-05-05 21:35:15 +03:30
PreloadService.Hide();
2024-05-04 23:13:26 +03:30
}
2024-05-07 13:55:11 +03:30
public async Task CallBackCustomerItem(ActionInResultComponent result)
{
if (result.Action == ComponentAction.add)
{
if (result.Status==ComponentStatus.success)
2024-05-08 17:25:02 +03:30
ShowSuccessAlert("مشتری جدید با موفقیت اضافه شد");
2024-05-07 13:55:11 +03:30
}
2024-05-08 17:25:02 +03:30
else if (result.Action == ComponentAction.update)
2024-05-07 13:55:11 +03:30
{
if (result.Status == ComponentStatus.success)
ShowSuccessAlert("اطلاعات مشتری با موفقیت ویرایش شد");
}
else if (result.Action == ComponentAction.delete)
{
if (result.Status == ComponentStatus.success)
2024-05-08 17:25:02 +03:30
ShowSuccessAlert("مشتری با موفقیت حذف شد");
2024-05-07 13:55:11 +03:30
}
if (result.Status == ComponentStatus.success)
2024-05-08 17:25:02 +03:30
await LoadCus(1);
2024-05-07 13:55:11 +03:30
await modal.HideAsync();
}
2024-05-08 17:25:02 +03:30
public async Task CustomerItem(int ID)
2024-05-07 13:55:11 +03:30
{
2024-05-08 17:25:02 +03:30
2024-05-07 13:55:11 +03:30
var parameters = new Dictionary<string, object>();
2024-05-08 17:25:02 +03:30
if(ID == 0) parameters.Add("Cus", new RCustomer(){ID=0});
else parameters.Add("Cus", request.list.Where(w=>w.ID==ID).First().Clone());
2024-05-07 13:55:11 +03:30
parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<ActionInResultComponent>(this, CallBackCustomerItem));
2024-05-09 19:56:53 +03:30
await modal.ShowAsync<CustomerItem>(title: ID == 0 ? "مشتری جدید" : "ویرایش اطلاعات", parameters: parameters);
2024-05-08 17:25:02 +03:30
2024-05-07 13:55:11 +03:30
}
2024-05-05 18:15:37 +03:30
}