AutoCompleteStaff.razor.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using wispro.sp.entity;
  8. using wispro.sp.web.Services;
  9. namespace wispro.sp.web.Components
  10. {
  11. public partial class AutoCompleteStaff
  12. {
  13. private Staff _SelectedItem;
  14. private string SelectValueName;
  15. List<Staff> _ShowStaffLists;
  16. [Parameter]
  17. public int? StaffId { get; set; }
  18. [Parameter]
  19. public EventCallback<int?> StaffIdChanged { get; set; }
  20. [Parameter]
  21. public List<Staff> StaffLists { get; set; }
  22. [Inject] IUserService _UserService { get; set; }
  23. protected override void OnInitialized()
  24. {
  25. _ShowStaffLists = StaffLists;
  26. base.OnInitialized();
  27. }
  28. Func<object, object, bool> CompareWith = (a, b) =>
  29. {
  30. if (a is Staff o1 && b is Staff o2)
  31. {
  32. return o1.Name == o2.Name ;
  33. }
  34. else
  35. {
  36. return false;
  37. }
  38. };
  39. void OnSelectionChange(AutoCompleteOption item)
  40. {
  41. _SelectedItem = (Staff)item.Value;
  42. StaffId = _SelectedItem.Id;
  43. }
  44. void OnInput(ChangeEventArgs e)
  45. {
  46. var v = e.Value.ToString();
  47. _ShowStaffLists = StaffLists.Where<Staff>(s => s.Name.Contains(v)).ToList();
  48. }
  49. }
  50. }