Files
Atomx/Atomx.Admin/Atomx.Admin.Client/Pages/Settings/StateProvinceList.razor

213 lines
7.3 KiB
Plaintext

@page "/stateprovince/list/{countryId:long}"
@page "/{locale}/stateprovince/list/{countryId:long}"
@inject ILogger<StateProvinceList> Logger
@attribute [Authorize]
<PageContainer Title="州省管理">
<Breadcrumb>
<Breadcrumb>
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
<BreadcrumbItem Href="/settings">系统配置</BreadcrumbItem>
<BreadcrumbItem>州省管理</BreadcrumbItem>
</Breadcrumb>
</Breadcrumb>
<ChildContent>
<Spin Spinning="pageLoading">
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="(16, 16)">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="display:flex">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<br />
<Card Title="州、省列表" Class="hideborder">
<Extra>
<div class="extraContent">
<Button Type="ButtonType.Primary" HtmlType="submit" OnClick="HandleAddNew">新增州省</Button>
</div>
</Extra>
<ChildContent>
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true">
<Selection CheckStrictly />
<PropertyColumn Property="c => c.Name" Title="名称" />
<PropertyColumn Property="c => c.Initial" Title="首字母" />
<PropertyColumn Property="c => c.Abbreviation" Title="缩写" />
<PropertyColumn Property="c => c.Enabled" Title="状态">
@if (context.Enabled)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c => c.DisplayOrder" Title="排序" />
<ActionColumn Title="操作" Align="ColumnAlign.Right">
<Space>
<SpaceItem>
<a @onclick="(e) => HandleEdit(context)">编辑</a>
</SpaceItem>
@*<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>*@
</Space>
</ActionColumn>
</Table>
<br />
<Row Justify="RowJustify.End">
@if (PagingList.Count > 0)
{
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
}
</Row>
</ChildContent>
</Card>
</Spin>
</ChildContent>
</PageContainer>
@code {
[Parameter]
public string Locale { get; set; } = string.Empty;
[Parameter]
public long CountryId { get; set; }
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
bool pageLoading = false;
bool searchExpand = false;
Form<StateProvinceSearch> searchForm = new();
StateProvinceSearch search = new();
PagingList<StateProvince> PagingList = new() { Size = 20 };
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
loadQueryString();
await LoadListAsync();
await base.OnParametersSetAsync();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
search.CountryId = CountryId;
}
async Task LoadListAsync()
{
try
{
pageLoading = true;
var url = "/api/stateprovince/search";
var apiResult = await HttpService.GetPagingList<StateProvince>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
else if (apiResult.Code == 403)
{
ModalService.Error(new ConfirmOptions() { Title = "权限不足", Content = apiResult.Message });
}
StateHasChanged();
}
finally
{
pageLoading = false;
}
}
void OnSearchReset()
{
search = new();
searchForm?.Reset();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?page={page}");
}
else
{
Navigation.NavigateTo($"/stateprovince/list/{CountryId}");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/stateprovince/list/{CountryId}?{queryString}");
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void HandleAddNew()
{
Navigation.NavigateTo($"/stateprovince/{CountryId}/create");
}
void HandleEdit(StateProvince model)
{
Navigation.NavigateTo($"/stateprovince/{CountryId}/edit/{model.Id}");
}
}