终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

117 lines
3.3 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.JXJFoodBigStation.Model;
  4. using Microsoft.Toolkit.Mvvm.ComponentModel;
  5. using Microsoft.Toolkit.Mvvm.Input;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace BPASmartClient.JXJFoodBigStation.ViewModel
  13. {
  14. internal class SelectRecipesViewModel:ObservableObject
  15. {
  16. public SelectRecipesViewModel()
  17. {
  18. AllRecipes = new();
  19. foreach (var item in Json<LocalRecipe>.Data.SelectedRecipes)
  20. {
  21. SelectRecipes.Add(item);
  22. }
  23. if (Json<LocalRecipe>.Data.Recipes != null)
  24. {
  25. foreach (var item in Json<LocalRecipe>.Data.Recipes)
  26. {
  27. AllRecipes.Add(new RecipeDataWithCheck()
  28. {
  29. Recipe = item,
  30. IsSelected = SelectRecipes.Any(p => p.RecipeCode == item.RecipeCode)
  31. });
  32. }
  33. }
  34. ConfirmCommand = new(() =>
  35. {
  36. RefreshSelected();
  37. ActionManage.GetInstance.Send("CloseSelectRecipesView");
  38. });
  39. CancelCommand = new(() =>
  40. {
  41. ActionManage.GetInstance.Send("CloseSelectRecipesView");
  42. });
  43. AllSelectCommand = new(() =>
  44. {
  45. foreach (var item in AllRecipes)
  46. {
  47. item.IsSelected = true;
  48. }
  49. });
  50. AllCancelCommand = new(() =>
  51. {
  52. foreach (var item in AllRecipes)
  53. {
  54. item.IsSelected = false;
  55. }
  56. });
  57. }
  58. private void RefreshSelected()
  59. {
  60. SelectRecipes.Clear();
  61. foreach (var item in AllRecipes)
  62. {
  63. if (item.IsSelected==true)
  64. {
  65. SelectRecipes.Add(item.Recipe);
  66. }
  67. }
  68. }
  69. public ObservableCollection<RecipeDataWithCheck> AllRecipes {get; set; }
  70. public static ObservableCollection<RecipeData> SelectRecipes { get; set; } = new ObservableCollection<RecipeData>();
  71. /// <summary>
  72. /// 取消筛选,即关闭本窗口。
  73. /// </summary>
  74. public RelayCommand CancelCommand { get; set; }
  75. /// <summary>
  76. /// 全选。
  77. /// </summary>
  78. public RelayCommand AllSelectCommand { get; set; }
  79. /// <summary>
  80. /// 全部取消选择。
  81. /// </summary>
  82. public RelayCommand AllCancelCommand { get; set; }
  83. /// <summary>
  84. /// 确认选择。
  85. /// </summary>
  86. public RelayCommand ConfirmCommand { get; set; }
  87. /// <summary>
  88. /// 一个配方数据的包装类。
  89. /// </summary>
  90. internal class RecipeDataWithCheck:ObservableObject
  91. {
  92. public RecipeData Recipe { get; set; }
  93. private bool _IsSelected;
  94. public bool IsSelected
  95. {
  96. get { return _IsSelected; }
  97. set { _IsSelected = value; OnPropertyChanged(); }
  98. }
  99. }
  100. }
  101. }