using BPA.Models; using BPASmartClient.Helper; using BPASmartClient.MorkF.Model; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.MorkF.ViewModel { partial class LocalMenuViewModel:ObservableObject { public ObservableCollection PotActionStep { get; set; } = new ObservableCollection(); public ObservableCollection strPotActions { get; set; } = new ObservableCollection(); public RelayCommand Delete { get; set; } public RelayCommand AddFryTime { get; set; } public RelayCommand Save { get; set; } private void Deleted(object o) { if (o == null) return; if(o is PotActions p) { PotActionStep.Remove(p); } for (int i = 0; i < PotActionStep.Count; i++) { PotActionStep[i].FryTime = i + 1; } } public LocalMenuViewModel() { if(Json.Data.LocalstirFryGoods.StirPotActions.Count > 0) { PotActionStep.Clear(); PotActionStep = new ObservableCollection(Json.Data.LocalstirFryGoods.StirPotActions); } Delete = new RelayCommand(Deleted); AddFryTime = new RelayCommand(() => { List seasoningLists = new List(); seasoningLists.Add(new SeasoningList { Loc = 0,Qty = 0}); PotActionStep.Add(new BPA.Models.PotActions { FryTime = PotActionStep.Count +1, During =0, SeasoningLists = seasoningLists, }); }); Save = new RelayCommand(new Action(() => { Json.Data.LocalstirFryGoods.GoodsKey = 11; Json.Data.LocalstirFryGoods.StirPotActions = new List(PotActionStep); Json.Save(); ActionManage.GetInstance.Send("LocalMenuClose"); })); foreach(var pot in Enum.GetNames(typeof(StirFryPotActionEnum))) { strPotActions.Add(pot); } ActionManage.GetInstance.Register(new Action(()=> { for (int i = 0; i < Json.Data.LocalstirFryGoods.StirPotActions.Count; i++) { Json.Data.LocalstirFryGoods.StirPotActions[i].FryTime = i + 1; } }), "SortFryTime"); ActionManage.GetInstance.Register(new Action((o) => { if (o == null) return ; if(o is int[] ints) { Json.Data.LocalstirFryGoods.StirPotActions[ints[0]].FryTime = ints[1]+1; Json.Data.LocalstirFryGoods.StirPotActions[ints[1]].FryTime = ints[0]+1; var res = Json.Data.LocalstirFryGoods.StirPotActions[ints[0]]; Json.Data.LocalstirFryGoods.StirPotActions.Remove(res); Json.Data.LocalstirFryGoods.StirPotActions.Insert(ints[1],res); } }), "PotActionStep"); } } }