终端一体化运控平台
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.
 
 
 

105 lines
3.6 KiB

  1. using BPA.Models;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.MorkF.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.MorkF.ViewModel
  13. {
  14. partial class LocalMenuViewModel:ObservableObject
  15. {
  16. public ObservableCollection<PotActions> PotActionStep { get; set; } = new ObservableCollection<PotActions>();
  17. public ObservableCollection<string> strPotActions { get; set; } = new ObservableCollection<string>();
  18. public RelayCommand<object> Delete { get; set; }
  19. public RelayCommand AddFryTime { get; set; }
  20. public RelayCommand Save { get; set; }
  21. private void Deleted(object o)
  22. {
  23. if (o == null) return;
  24. if(o is PotActions p)
  25. {
  26. PotActionStep.Remove(p);
  27. }
  28. for (int i = 0; i < PotActionStep.Count; i++)
  29. {
  30. PotActionStep[i].FryTime = i + 1;
  31. }
  32. }
  33. public LocalMenuViewModel()
  34. {
  35. if(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
  36. {
  37. PotActionStep.Clear();
  38. PotActionStep = new ObservableCollection<PotActions>(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions);
  39. }
  40. Delete = new RelayCommand<object>(Deleted);
  41. AddFryTime = new RelayCommand(() =>
  42. {
  43. List<SeasoningList> seasoningLists = new List<SeasoningList>();
  44. seasoningLists.Add(new SeasoningList { Loc = 0,Qty = 0});
  45. PotActionStep.Add(new BPA.Models.PotActions
  46. {
  47. FryTime = PotActionStep.Count +1,
  48. During =0,
  49. SeasoningLists = seasoningLists,
  50. });
  51. });
  52. Save = new RelayCommand(new Action(() =>
  53. {
  54. Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey = 11;
  55. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions = new List<PotActions>(PotActionStep);
  56. Json<LocalPotStep>.Save();
  57. ActionManage.GetInstance.Send("LocalMenuClose");
  58. }));
  59. foreach(var pot in Enum.GetNames(typeof(StirFryPotActionEnum)))
  60. {
  61. strPotActions.Add(pot);
  62. }
  63. ActionManage.GetInstance.Register(new Action(()=>
  64. {
  65. for (int i = 0; i < Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count; i++)
  66. {
  67. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[i].FryTime = i + 1;
  68. }
  69. }), "SortFryTime");
  70. ActionManage.GetInstance.Register(new Action<object>((o) =>
  71. {
  72. if (o == null) return ;
  73. if(o is int[] ints)
  74. {
  75. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[0]].FryTime = ints[1]+1;
  76. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[1]].FryTime = ints[0]+1;
  77. var res = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[0]];
  78. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Remove(res);
  79. Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Insert(ints[1],res);
  80. }
  81. }), "PotActionStep");
  82. }
  83. }
  84. }