using CommunityToolkit.Mvvm.ComponentModel; using ivf_tl_Entity.GlobalEntitys; using ivf_tl_Operate.CustomUserControls; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ivf_tl_Operate.ViewModel { public partial class PhotoPageViewModel : ObservableObject { [ObservableProperty] private int pageIndex = 1; [ObservableProperty] private int pageSize = 16; [ObservableProperty] private int dataCount = -1; [ObservableProperty] private List picLayerList = new List(); [ObservableProperty] private int currentPicLayer = 0; public long EmbryoId { get; set; } = 0; public int HouseSn { get; set; } = 1; private Dictionary> AllPicViewList = new Dictionary>(); [ObservableProperty] private List currentPicViewList = new List(); [ObservableProperty] private ObservableCollection showPicViewList = new ObservableCollection(); public bool IsSourcePic { get; set; } = false; public bool PhotoToggle { get; set; } = false; public List PhotoButtonList { get; set; } = new List(); public int MaxFocal = 0; public int MinFocal = 0; public PhotoPageViewModel(int _HouseSn,long _EmbryoId,int MaxTotalLayer) { HouseSn = _HouseSn; EmbryoId = _EmbryoId; GetMaxAndMinFocal(MaxTotalLayer); SetCurrentPicViewList(); } private void GetMaxAndMinFocal(int MaxTotalLayer) { PicLayerList.Clear(); if (MaxTotalLayer <= 0) { MaxFocal = 0; MinFocal = 0; PicLayerList.Add(0); return; } MaxFocal = (MaxTotalLayer - 1) / 2; MinFocal = -MaxFocal; for (int i = MinFocal; i <= MaxFocal; i++) { PicLayerList.Add(i); } } public void SetCurrentPicViewList() { if (IsSourcePic) { CurrentPicViewList = AppData.Instance.HttpHelper.GetSourcePictureViewApi(AppData.Instance.TlSn, HouseSn, EmbryoId, CurrentPicLayer); return; } if(AllPicViewList.ContainsKey(CurrentPicLayer)) { CurrentPicViewList = AllPicViewList[CurrentPicLayer]; return; } CurrentPicViewList = AppData.Instance.HttpHelper.GetPictureViewApi(AppData.Instance.TlSn, HouseSn, EmbryoId, CurrentPicLayer); AllPicViewList.Add(CurrentPicLayer, CurrentPicViewList); } public void SetShowPicViewList() { ShowPicViewList.Clear(); Dictionary buttonTime = new Dictionary(); var selButton = PhotoButtonList.Where(x => x.IsSelected).ToList(); int k = 1; if (selButton.Any()) { foreach (var item in selButton) { if (PhotoToggle) { buttonTime.Add(item.PhotoBoxSetting.MinHour1, item.PhotoBoxSetting.MaxHour1); } else { buttonTime.Add(item.PhotoBoxSetting.MinHour, item.PhotoBoxSetting.MaxHour); } } foreach (var item in CurrentPicViewList) { foreach (var buttonTimeItem in buttonTime) { if(buttonTimeItem.Value == 0) { if (item.developTime >= buttonTimeItem.Key) { item.Num = k++; ShowPicViewList.Add(item); } } else { if (item.developTime >= buttonTimeItem.Key && item.developTime <= buttonTimeItem.Value) { item.Num = k++; ShowPicViewList.Add(item); } } } } } else { foreach (var item in CurrentPicViewList) { item.Num = k++; ShowPicViewList.Add(item); } } DataCount = -1; DataCount = ShowPicViewList.Count; } } }