123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- 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<wispro.sp.entity.StaffGrade> staffGrades;
- IEnumerable<wispro.sp.entity.StaffGrade> selectedRows;
- [Inject] protected IAuthService _authService { get; set; }
- 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()
- {
- _authService.CanVisitResource();
- _loading = true;
- List<wispro.sp.entity.StaffGrade> data = await _sfService.GetAll();// await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"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<string, object> OnRow(RowData<wispro.sp.entity.StaffGrade> row)
- {
- Dictionary<string, object> ret = new Dictionary<string, object>();
- 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;
- }
- }
- }
|