PhotoPageViewModel.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using ivf_tl_Entity.GlobalEntitys;
  3. using ivf_tl_Operate.CustomUserControls;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ivf_tl_Operate.ViewModel
  11. {
  12. public partial class PhotoPageViewModel : ObservableObject
  13. {
  14. [ObservableProperty]
  15. private int pageIndex = 1;
  16. [ObservableProperty]
  17. private int pageSize = 16;
  18. [ObservableProperty]
  19. private int dataCount = -1;
  20. [ObservableProperty]
  21. private List<int> picLayerList = new List<int>();
  22. [ObservableProperty]
  23. private int currentPicLayer = 0;
  24. public long EmbryoId { get; set; } = 0;
  25. public int HouseSn { get; set; } = 1;
  26. private Dictionary<int, List<PictureView>> AllPicViewList = new Dictionary<int, List<PictureView>>();
  27. [ObservableProperty]
  28. private List<PictureView> currentPicViewList = new List<PictureView>();
  29. [ObservableProperty]
  30. private ObservableCollection<PictureView> showPicViewList = new ObservableCollection<PictureView>();
  31. public bool IsSourcePic { get; set; } = false;
  32. public bool PhotoToggle { get; set; } = false;
  33. public List<PhotoButton> PhotoButtonList { get; set; } = new List<PhotoButton>();
  34. public int MaxFocal = 0;
  35. public int MinFocal = 0;
  36. public PhotoPageViewModel(int _HouseSn,long _EmbryoId,int MaxTotalLayer)
  37. {
  38. HouseSn = _HouseSn;
  39. EmbryoId = _EmbryoId;
  40. GetMaxAndMinFocal(MaxTotalLayer);
  41. SetCurrentPicViewList();
  42. }
  43. private void GetMaxAndMinFocal(int MaxTotalLayer)
  44. {
  45. PicLayerList.Clear();
  46. if (MaxTotalLayer <= 0)
  47. {
  48. MaxFocal = 0;
  49. MinFocal = 0;
  50. PicLayerList.Add(0);
  51. return;
  52. }
  53. MaxFocal = (MaxTotalLayer - 1) / 2;
  54. MinFocal = -MaxFocal;
  55. for (int i = MinFocal; i <= MaxFocal; i++)
  56. {
  57. PicLayerList.Add(i);
  58. }
  59. }
  60. public void SetCurrentPicViewList()
  61. {
  62. if (IsSourcePic)
  63. {
  64. CurrentPicViewList = AppData.Instance.HttpHelper.GetSourcePictureViewApi(AppData.Instance.TlSn, HouseSn, EmbryoId, CurrentPicLayer);
  65. return;
  66. }
  67. if(AllPicViewList.ContainsKey(CurrentPicLayer))
  68. {
  69. CurrentPicViewList = AllPicViewList[CurrentPicLayer];
  70. return;
  71. }
  72. CurrentPicViewList = AppData.Instance.HttpHelper.GetPictureViewApi(AppData.Instance.TlSn, HouseSn, EmbryoId, CurrentPicLayer);
  73. AllPicViewList.Add(CurrentPicLayer, CurrentPicViewList);
  74. }
  75. public void SetShowPicViewList()
  76. {
  77. ShowPicViewList.Clear();
  78. Dictionary<int, int> buttonTime = new Dictionary<int, int>();
  79. var selButton = PhotoButtonList.Where(x => x.IsSelected).ToList();
  80. int k = 1;
  81. if (selButton.Any())
  82. {
  83. foreach (var item in selButton)
  84. {
  85. if (PhotoToggle)
  86. {
  87. buttonTime.Add(item.PhotoBoxSetting.MinHour1, item.PhotoBoxSetting.MaxHour1);
  88. }
  89. else
  90. {
  91. buttonTime.Add(item.PhotoBoxSetting.MinHour, item.PhotoBoxSetting.MaxHour);
  92. }
  93. }
  94. foreach (var item in CurrentPicViewList)
  95. {
  96. foreach (var buttonTimeItem in buttonTime)
  97. {
  98. if(buttonTimeItem.Value == 0)
  99. {
  100. if (item.developTime >= buttonTimeItem.Key)
  101. {
  102. item.Num = k++;
  103. ShowPicViewList.Add(item);
  104. }
  105. }
  106. else
  107. {
  108. if (item.developTime >= buttonTimeItem.Key && item.developTime <= buttonTimeItem.Value)
  109. {
  110. item.Num = k++;
  111. ShowPicViewList.Add(item);
  112. }
  113. }
  114. }
  115. }
  116. }
  117. else
  118. {
  119. foreach (var item in CurrentPicViewList)
  120. {
  121. item.Num = k++;
  122. ShowPicViewList.Add(item);
  123. }
  124. }
  125. DataCount = -1;
  126. DataCount = ShowPicViewList.Count;
  127. }
  128. }
  129. }