@page "/StaffList"
@inject HttpClient Http
@using AntDesign.TableModels
@inject MessageService _message
@using System.ComponentModel
@using wispro.sp.share;
@if (forecasts == null)
{
}
else
{
@serialNumber(_pageIndex, _pageSize, context.Name)
}
@using System.Text.Json;
@code {
private List forecasts;
IEnumerable selectedRows;
ITable table;
int _pageIndex = 1;
int _pageSize = 10;
int _total = 0;
bool _loading = false;
Staff EditingStaff = null;
bool _visible = false;
string[] _places = new string[] { "深圳", "苏州", "南通" };
protected override async Task OnInitializedAsync()
{
_loading = true;
StaffApiResponse data = await Http.GetFromJsonAsync($"http://localhost:39476/api/Staff/Query?pageIndex={_pageIndex}&pageSize={_pageSize}");
_loading = false;
forecasts = data.Results;
_total = data.TotalCount;
}
private void HandlePageChange(PaginationEventArgs args)
{
if (_pageIndex != args.Page)
{
_pageIndex = args.Page;
}
if (_pageSize != args.PageSize)
{
_pageSize = args.PageSize;
}
}
public async Task OnChange(QueryModel queryModel)
{
_loading = true;
StaffApiResponse data = await Http.GetFromJsonAsync("http://localhost:39476/api/Staff/Query?" + GetRandomuserParams(queryModel));
_loading = false;
forecasts = data.Results;
_total = data.TotalCount;
}
public int serialNumber(int pageIndex, int pageSize, string name)
{
int iIndex = 0;
foreach (Staff sf in forecasts)
{
iIndex++;
if (sf.Name == name)
{
break;
}
}
return (pageIndex - 1) * pageSize + iIndex;
}
Dictionary OnRow(RowData row)
{
Dictionary ret = new Dictionary();
ret.Add("id", row.RowIndex);
ret.Add("onclick", ((Action)delegate
{
_message.Info($"row {row.Data.Name} was clicked");
}));
return ret;
}
public void RemoveSelection(string name)
{
var selected = selectedRows.Where(x => x.Name != name);
selectedRows = selected;
}
private void Delete(string name)
{
var rList = forecasts.Where(x => x.Name == name).ToList();
if (rList.Count() > 0)
{
EditingStaff = rList[0];
_visible = true;
}
else
{
}
//_total = forecasts.Length;
}
string GetRandomuserParams(QueryModel queryModel)
{
List query = new List()
{
$"pageSize={queryModel.PageSize}",
$"pageIndex={queryModel.PageIndex}",
};
queryModel.SortModel.ForEach(x =>
{
query.Add($"sortField={x.FieldName.ToLower()}");
query.Add($"sortOrder={x.Sort}");
});
//queryModel.FilterModel.ForEach(filter =>
//{
// filter.SelectedValues.ForEach(value =>
// {
// query.Add($"{filter.FieldName.ToLower()}={value}");
// });
//});
return string.Join('&', query);
}
private void HandleOk(MouseEventArgs e)
{
Console.WriteLine(e);
_visible = false;
}
private void HandleCancel(MouseEventArgs e)
{
Console.WriteLine(e);
_visible = false;
}
}