终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

115 行
3.2 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. internal class RecipeDataWithCheck:ObservableObject
  88. {
  89. public RecipeData Recipe { get; set; }
  90. private bool _IsSelected;
  91. public bool IsSelected
  92. {
  93. get { return _IsSelected; }
  94. set { _IsSelected = value; OnPropertyChanged(); }
  95. }
  96. }
  97. }
  98. }