using AntDesign; using AntDesign.TableModels; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Json; using System.Threading.Tasks; using wispro.sp.share; using wispro.sp.web.Services; namespace wispro.sp.web.Pages { public partial class StaffGrade { [Inject] public StaffGradeService _sfService { get; set; } [Inject] MessageService _message { get; set; } private List staffGrades; IEnumerable selectedRows; ITable table; int _pageIndex = 1; int _pageSize = 10; int _total = 0; bool _loading = false; wispro.sp.entity.StaffGrade EditingStaff = null; bool _visible = false; bool _isAdd = false; protected override async Task OnInitializedAsync() { _loading = true; List data = await _sfService.GetAll();// await Http.GetFromJsonAsync>($"http://localhost:39476/api/StaffGrade/GetAll"); _loading = false; staffGrades = data; _total = data.Count; } private void HandlePageChange(PaginationEventArgs args) { if (_pageIndex != args.Page) { _pageIndex = args.Page; } if (_pageSize != args.PageSize) { _pageSize = args.PageSize; } } Dictionary OnRow(RowData row) { Dictionary ret = new Dictionary(); ret.Add("id", row.Data.Id); ret.Add("onclick", ((Action)delegate { //_message.Info($"row {row.Data.Grade} was clicked"); })); return ret; } public void RemoveSelection(int id) { //var selected = selectedRows.Where(x => x.Id != id); //selectedRows = selected; } private void Delete(int id) { var rList = staffGrades.Where(x => x.Id == id).ToList(); if (rList.Count() > 0) { EditingStaff = rList[0]; _isAdd = false; _visible = true; } else { } _total = staffGrades.Count; } private void Edit(int id) { var rList = staffGrades.Where(x => x.Id == id).ToList(); if (rList.Count() > 0) { EditingStaff = rList[0]; _isAdd = false; _visible = true; } else { } _total = staffGrades.Count; } private void AddNew() { EditingStaff = new entity.StaffGrade(); _isAdd = true; _visible = true; } private async Task HandleOk(MouseEventArgs e) { ApiSaveResponse result = await _sfService.Save(EditingStaff); if (result.Success) { await _message.Success("数据已保存!"); } else { await _message.Error($"{result.ErrorMessage}"); } _visible = false; } private void HandleCancel(MouseEventArgs e) { _visible = false; } } }