207 lines
7.8 KiB
Plaintext
207 lines
7.8 KiB
Plaintext
@page "/Customer"
|
|
@using Front.Services
|
|
@using Shared.DTOs
|
|
@using Front.CUSComponent
|
|
@using Shared.DTOs.Serch
|
|
@inject HttpClientController hc;
|
|
<PageTitle>مشتری</PageTitle>
|
|
<Modal @ref="modal" />
|
|
|
|
<Preload LoadingText="در حال بارگذاری..." />
|
|
@* search *@
|
|
<div class="row">
|
|
<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">
|
|
<div class="col-md-1">
|
|
<input @bind-value="itemsearch.ID" placeholder="شناسه" style="text-align:center;" class="form-control" type="text" >
|
|
</div>
|
|
<div class="col-md-2">
|
|
<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>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<input @bind-value="itemsearch.EconomicCode" placeholder="کد اقتصادی / کدملی" style="text-align:center;" class="form-control" type="text">
|
|
</div>
|
|
<div class="col-md-2">
|
|
<input @bind-value="itemsearch.Phone" placeholder="تلفن" style="text-align:center;" class="form-control" type="text">
|
|
</div>
|
|
<div class="col-md-2">
|
|
<input @bind-value="itemsearch.ZipCode" placeholder="کد پستی" style="text-align:center;" class="form-control" type="text">
|
|
</div>
|
|
<div class="col-auto">
|
|
<button @onclick="() => LoadCus(1)" type="submit" class="btn btn-primary">جستجو</button>
|
|
</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">
|
|
<button type="submit" @onclick="()=>CustomerItem(0)" class="btn btn-primary">جدید</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@* alert *@
|
|
<div class="row">
|
|
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
|
|
<Icon Name="@alertIconName" class="me-2"></Icon>
|
|
@alertMessage
|
|
</Alert>
|
|
|
|
</div>
|
|
|
|
@* data *@
|
|
@if (request != null)
|
|
{
|
|
<LTable ModelinComponent="request?.list" OnMultipleOfThree="EventCallback.Factory.Create<int>(this,CustomerItem)" />
|
|
@* pagination *@
|
|
<p style="color:red">@request?.RowCount آیتم یافت شد</p>
|
|
<nav aria-label="Page navigation">
|
|
<ul class="pagination justify-content-center">
|
|
@for (int page = 1; page <= request?.PageCount; page++)
|
|
{
|
|
if (page == PageIndex)
|
|
{
|
|
<li class="page-item active">
|
|
<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>
|
|
}
|
|
}
|
|
|
|
|
|
</ul>
|
|
</nav>
|
|
}
|
|
|
|
@layout PanelLayout
|
|
@code {
|
|
|
|
[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!;
|
|
// alert
|
|
AlertColor alertColor = AlertColor.Primary;
|
|
IconName alertIconName = IconName.CheckCircleFill;
|
|
bool Hidealert = true;
|
|
string alertMessage = "";
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (PageIndex == null) PageIndex = 1;
|
|
await LoadCus(PageIndex.Value);
|
|
await base.OnParametersSetAsync();
|
|
}
|
|
}
|
|
@functions {
|
|
private void ShowSuccessAlert(string msg)
|
|
{
|
|
Hidealert = false;
|
|
alertColor = AlertColor.Success;
|
|
alertIconName = IconName.CheckCircleFill;
|
|
alertMessage = msg;
|
|
}
|
|
private void ShowDangerAlert(string msg)
|
|
{
|
|
Hidealert = false;
|
|
alertColor = AlertColor.Danger;
|
|
alertIconName = IconName.ExclamationTriangleFill;
|
|
alertMessage = msg;
|
|
}
|
|
public async Task LoadCus(int pi)
|
|
{
|
|
if (ItemSearchCustomertype > 0)
|
|
itemsearch.CustomerType = (CustomerType)ItemSearchCustomertype;
|
|
else
|
|
itemsearch.CustomerType = null;
|
|
|
|
itemsearch.PageSize = 10;
|
|
itemsearch.PageIndex = pi;
|
|
PreloadService.Show(SpinnerColor.Dark);
|
|
var rsp = await hc.Post<ItemSerchGetCustomer>("Customer/GetAll", itemsearch);
|
|
if (rsp.IsSuccessStatusCode)
|
|
{
|
|
request = await rsp.Content.ReadFromJsonAsync<PagingDto<RCustomer>>();
|
|
}
|
|
else if(rsp.StatusCode==System.Net.HttpStatusCode.Forbidden)
|
|
{
|
|
ShowDangerAlert("شما دسترسی به خواندن اطلاعات مشتری را نداربد");
|
|
}
|
|
else
|
|
{
|
|
ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
|
|
}
|
|
PreloadService.Hide();
|
|
}
|
|
public async Task CallBackCustomerItem(ActionInResultComponent result)
|
|
{
|
|
|
|
if (result.Action == ComponentAction.add)
|
|
{
|
|
if (result.Status==ComponentStatus.success)
|
|
ShowSuccessAlert("مشتری جدید با موفقیت اضافه شد");
|
|
|
|
}
|
|
else if (result.Action == ComponentAction.update)
|
|
{
|
|
if (result.Status == ComponentStatus.success)
|
|
ShowSuccessAlert("اطلاعات مشتری با موفقیت ویرایش شد");
|
|
}
|
|
else if (result.Action == ComponentAction.delete)
|
|
{
|
|
if (result.Status == ComponentStatus.success)
|
|
ShowSuccessAlert("مشتری با موفقیت حذف شد");
|
|
}
|
|
|
|
if (result.Status == ComponentStatus.success)
|
|
await LoadCus(1);
|
|
|
|
await modal.HideAsync();
|
|
}
|
|
public async Task CustomerItem(int ID)
|
|
{
|
|
|
|
var parameters = new Dictionary<string, object>();
|
|
|
|
if(ID == 0) parameters.Add("Cus", new RCustomer(){ID=0});
|
|
else parameters.Add("Cus", request.list.Where(w=>w.ID==ID).First().Clone());
|
|
|
|
parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<ActionInResultComponent>(this, CallBackCustomerItem));
|
|
await modal.ShowAsync<CustomerItem>(title: ID == 0 ? "مشتری جدید" : "ویرایش اطلاعات", parameters: parameters);
|
|
|
|
|
|
}
|
|
} |