155 lines
5.4 KiB
Plaintext
155 lines
5.4 KiB
Plaintext
@page "/admin/companies"
|
|
@attribute [Authorize]
|
|
@inject IApiClient ApiClient
|
|
@inject IJSRuntime JS
|
|
|
|
<PageTitle>고객사 관리</PageTitle>
|
|
|
|
<section class="admin-page-hero">
|
|
<div>
|
|
<div class="admin-eyebrow">Settings</div>
|
|
<h1 class="admin-page-title">고객사 관리</h1>
|
|
<p class="admin-page-subtitle">등록된 고객사를 관리하고 새로운 고객사를 추가합니다.</p>
|
|
</div>
|
|
<button type="button" class="site-button primary" @onclick='() => NavTo("/taxbaik/admin/companies/create")'>새 고객사 등록</button>
|
|
</section>
|
|
|
|
<div class="admin-surface mb-4 mt-4">
|
|
<div class="admin-summary-bar">
|
|
<span>@($"전체 고객사 {totalCompanies}개")</span>
|
|
<span>페이지 @currentPage / @totalPages</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="admin-surface">
|
|
@if (isLoading)
|
|
{
|
|
<Skeleton Count="6" CssClass="taxbaik-skeleton-grid" />
|
|
}
|
|
else
|
|
{
|
|
<div class="admin-table-wrap">
|
|
<table class="admin-table">
|
|
<thead>
|
|
<tr>
|
|
<th>회사코드</th>
|
|
<th>회사명</th>
|
|
<th>담당자</th>
|
|
<th>전화</th>
|
|
<th>이메일</th>
|
|
<th>활성</th>
|
|
<th>등록일</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var item in companies)
|
|
{
|
|
<tr>
|
|
<td>@item.CompanyCode</td>
|
|
<td>@item.CompanyName</td>
|
|
<td>@(item.ContactPerson ?? "—")</td>
|
|
<td>@(item.Phone ?? "—")</td>
|
|
<td>@(item.Email ?? "—")</td>
|
|
<td>@(item.IsActive ? "활성" : "비활성")</td>
|
|
<td>@item.CreatedAt.ToString("yyyy-MM-dd")</td>
|
|
<td><a class="site-button secondary" href="@($"/taxbaik/admin/companies/{item.Id}/edit")">수정</a></td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<div class="admin-pagination">
|
|
<button type="button" class="site-button secondary" disabled="@(currentPage <= 1 || isLoading)" @onclick="PreviousPage">이전</button>
|
|
<button type="button" class="site-button secondary" disabled="@(currentPage >= totalPages || isLoading)" @onclick="NextPage">다음</button>
|
|
</div>
|
|
|
|
@code {
|
|
private List<CompanyDto> companies = [];
|
|
private bool isLoading = true;
|
|
private int currentPage = 1;
|
|
private int totalPages = 1;
|
|
private int totalCompanies = 0;
|
|
private const int PageSize = 20;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadData();
|
|
}
|
|
|
|
private async Task LoadData()
|
|
{
|
|
try
|
|
{
|
|
isLoading = true;
|
|
var response = await ApiClient.GetAsync<dynamic>($"company?page={currentPage}&pageSize={PageSize}");
|
|
|
|
IDictionary<string, object>? dict = response as IDictionary<string, object>;
|
|
if (dict != null)
|
|
{
|
|
totalCompanies = (int)(dynamic)dict["total"];
|
|
totalPages = (totalCompanies + PageSize - 1) / PageSize;
|
|
|
|
if (dict["data"] is System.Collections.IEnumerable dataList)
|
|
{
|
|
companies = new List<CompanyDto>();
|
|
foreach (var item in dataList)
|
|
{
|
|
if (item is IDictionary<string, object> companyDict)
|
|
{
|
|
companies.Add(new CompanyDto
|
|
{
|
|
Id = (int)(dynamic)companyDict["id"],
|
|
CompanyCode = (string)companyDict["companyCode"],
|
|
CompanyName = (string)companyDict["companyName"],
|
|
ContactPerson = (string?)companyDict["contactPerson"],
|
|
Phone = (string?)companyDict["phone"],
|
|
Email = (string?)companyDict["email"],
|
|
IsActive = (bool)(dynamic)companyDict["isActive"],
|
|
CreatedAt = DateTime.Parse(companyDict["createdAt"].ToString()!)
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await JS.InvokeVoidAsync("alert", $"고객사 로드 실패: {ex.Message}");
|
|
}
|
|
finally
|
|
{
|
|
isLoading = false;
|
|
}
|
|
}
|
|
|
|
private async Task NextPage()
|
|
{
|
|
currentPage++;
|
|
await LoadData();
|
|
}
|
|
|
|
private async Task PreviousPage()
|
|
{
|
|
currentPage = Math.Max(1, currentPage - 1);
|
|
await LoadData();
|
|
}
|
|
|
|
private class CompanyDto
|
|
{
|
|
public int Id { get; set; }
|
|
public string CompanyCode { get; set; } = "";
|
|
public string CompanyName { get; set; } = "";
|
|
public string? ContactPerson { get; set; }
|
|
public string? Phone { get; set; }
|
|
public string? Email { get; set; }
|
|
public bool IsActive { get; set; }
|
|
public DateTime CreatedAt { get; set; }
|
|
}
|
|
|
|
private string NavTo(string url) => url;
|
|
}
|