DetailViewModel.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using ivf_tl_Entity.Entity.balance;
  4. using CommunityToolkit.Mvvm.ComponentModel;
  5. using ivf_tl_Entity.Entity.Result;
  6. using ivf_tl_Service.HttpProvider;
  7. using ivf_tl_Entity.Entity;
  8. using ivf_tl_Manage.Converts;
  9. using System.Diagnostics;
  10. using System;
  11. using ivf_tl_Entity.Enums;
  12. using System.Collections.ObjectModel;
  13. namespace ivf_tl_Manage.ViewModels
  14. {
  15. public partial class DetailViewModel : BaseViewModel
  16. {
  17. public DetailProvider detailProvider = null;
  18. public BaseViewModel ParentViewModel = null;
  19. [ObservableProperty]
  20. private House currentHouse = null;
  21. [ObservableProperty]
  22. private Dish currentDish;
  23. [ObservableProperty]
  24. private Embryo currentEmbryo = null;
  25. [ObservableProperty]
  26. private double videoAllTime = 1;
  27. [ObservableProperty]
  28. private double videoCurrentTime = 0;
  29. [ObservableProperty]
  30. private int currentFocal = 0;
  31. [ObservableProperty]
  32. private Dictionary<double, string> fpsItemList = new Dictionary<double, string>();
  33. [ObservableProperty]
  34. private KeyValuePair<double, string> selectedFps = new KeyValuePair<double, string>(1, "1.0x");
  35. [ObservableProperty]
  36. private bool isDishRecord = false;
  37. [ObservableProperty]
  38. private bool isHistory = false;
  39. [ObservableProperty]
  40. private bool isCurrentDish = true;
  41. [ObservableProperty]
  42. private bool isUpdata = false;
  43. [ObservableProperty]
  44. private ObservableCollection<MeasurementEntity> measurementList = new ObservableCollection<MeasurementEntity>();
  45. public List<DishPicAndVideo> DishPicAndVideoList { get; set; } = new List<DishPicAndVideo>();
  46. public DishPicAndVideo CurrentWellDishPicAndVideo { get; set; } = null;
  47. public LayerPicAndVideo CurrentWellLayerPicAndVideo { get; set; } = null;
  48. public DetailPic CurrentPic { get; set; } = null;
  49. public List<ButtonEntity> QuickButtons { get; set; } = new List<ButtonEntity>();
  50. private bool _IsInit = false;
  51. public int MaxTotalLayer = -1;
  52. public DetailViewModel(BaseViewModel baseViewModel, TLInfo tLInfo, Dish dish, House house, bool dishrecord)
  53. {
  54. AppData.Instance.CurrentTlInfo = tLInfo;
  55. MeasurementList.Clear();
  56. MeasurementList.Add(new MeasurementEntity { Num = 1 });
  57. MeasurementList.Add(new MeasurementEntity { Num = 2 });
  58. MeasurementList.Add(new MeasurementEntity { Num = 3 });
  59. FpsItemList.Clear();
  60. FpsItemList.Add(2, "2.0x");
  61. FpsItemList.Add(1.5, "1.5x");
  62. FpsItemList.Add(1.25, "1.25x");
  63. FpsItemList.Add(1, "1.0x");
  64. FpsItemList.Add(0.5, "0.5x");
  65. FpsItemList.Add(0.25, "0.25x");
  66. if (detailProvider == null) detailProvider = AppData.Instance.GetDetailProvider();
  67. base.ViewModelName = nameof(DetailViewModel);
  68. this.ParentViewModel = baseViewModel;
  69. IsDishRecord = dishrecord;
  70. this.CurrentHouse = house;
  71. this.CurrentDish = dish;
  72. if (CurrentDish.embryoList == null) CurrentDish.embryoList = new List<Embryo>();
  73. IsUpdata = true;
  74. base.NavName = $"{KeyToStringConvert.GetLanguageStringByKey("0163")}{CurrentHouse.houseSn}";
  75. NavList.Clear();
  76. if (IsDishRecord == true)
  77. {
  78. NavList.Add(baseViewModel);
  79. NavList.Add(this);
  80. return;
  81. }
  82. NavList.Add(AppData.Instance.MainWindowViewModel.devManageViewModel);
  83. NavList.Add(AppData.Instance.MainWindowViewModel.patientManageViewModel);
  84. NavList.Add(this);
  85. }
  86. public void Init()
  87. {
  88. Stopwatch stopwatch = Stopwatch.StartNew();
  89. TimeLog($"{CurrentHouse.houseSn}号舱室详情界面数据初始化开始,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}", LogEnum.TakeTime);
  90. var time1 = stopwatch.Elapsed;
  91. VideoAllTime = 1;
  92. VideoCurrentTime = 0;
  93. CurrentFocal = 0;
  94. if (_IsInit) return;
  95. _IsInit = true;
  96. SelectedFps = new KeyValuePair<double, string>(1, "1.0x");
  97. CurrentEmbryo = null;
  98. DishPicAndVideoList.Clear();
  99. CurrentWellDishPicAndVideo = null;
  100. CurrentWellLayerPicAndVideo = null;
  101. CurrentPic = null;
  102. QuickButtons.Clear();
  103. if (CurrentDish.embryoList != null && CurrentDish.embryoList.Any())
  104. DishPicAndVideoList = detailProvider.GetRecordDetailApi(CurrentDish.tlSn, CurrentDish.houseSn, CurrentDish.id, CurrentDish.embryoList.Select(x => x.wellSn).ToList());
  105. var time2 = stopwatch.Elapsed;
  106. TimeLog($"获取图片视频:{DateTime.Now},耗时:{(time2 - time1).TotalMilliseconds}毫秒", LogEnum.TakeTime);
  107. QuickButtons = detailProvider.GetQuickButtonsApi();
  108. time1 = stopwatch.Elapsed;
  109. DebugLog($"{CurrentHouse.houseSn}号舱室详情界面数据初始化完成,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")},[读取快捷按钮耗时:{(time1 - time2).TotalMilliseconds}毫秒]总耗时:{stopwatch.Elapsed.TotalMilliseconds}毫秒", LogEnum.TakeTime);
  110. stopwatch.Stop();
  111. }
  112. public void Back()
  113. {
  114. if (ParentViewModel != null)
  115. AppData.Instance.MainWindowViewModel.CurrentViewModle = ParentViewModel;
  116. else
  117. AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.devManageViewModel;
  118. }
  119. public void MarkEmbryo()
  120. {
  121. //MarkUseViewModel markUseViewModel = null;
  122. //if (!IsDishRecord) markUseViewModel = new MarkUseViewModel(this, $"{KeyToStringConvert.GetLanguageStringByKey("0163")}{CurrentHouse.houseSn}");
  123. //else markUseViewModel = new MarkUseViewModel(this, ParentViewModel, $"{KeyToStringConvert.GetLanguageStringByKey("0163")}{CurrentHouse.houseSn}");
  124. //markUseViewModel.Init();
  125. //AppData.Instance.MainWindowViewModel.CurrentViewModle = markUseViewModel;
  126. MarkUseViewModel markUseViewModel = new MarkUseViewModel(this, IsDishRecord, IsCurrentDish);
  127. markUseViewModel.Init();
  128. AppData.Instance.MainWindowViewModel.CurrentViewModle = markUseViewModel;
  129. }
  130. public bool MarkEmbryo(int embryoState)
  131. {
  132. return detailProvider.MarkEmbryoDestinationApi(CurrentEmbryo.id, embryoState);
  133. }
  134. public bool EndDish()
  135. {
  136. if (detailProvider.EndCultureRecordApi(CurrentDish.id))
  137. {
  138. AppData.Instance.MainWindowViewModel.patientManageViewModel.EndDish(CurrentDish.houseSn);
  139. return true;
  140. }
  141. return false;
  142. }
  143. public void GetPicDetail()
  144. {
  145. }
  146. }
  147. }