using BPA.Helper;
using BPASmartClient.Model.大炒;
using BPASmartClient.MorkBF.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace BPASmartClient.MorkBF.ViewModel
{
//[INotifyPropertyChanged]
partial class FoodManagerViewModel : NotifyBase
{
///
/// 菜品步骤
///
public ObservableCollection FryPotProcesses { get; set; } = new ObservableCollection();
public ObservableCollection FryAction { get; set; } = new ObservableCollection();
public ObservableCollection Gear { get; set; } = new ObservableCollection() { 0, 1, 2, 3, 4, 5 };
public ObservableCollection PotPostion { get; set; } = new ObservableCollection() { 1, 2, 3, 4 };
//[ObservableProperty]
//private string _goodName;
public string GoodName { get { return _goodName; } set { _goodName = value; OnPropertyChanged(); } }
private string _goodName;
//[BPARelayCommand]
private void Add()
{
FryPotProcesses.Add(new FryPotProcess() { FryTime = FryPotProcesses.Count + 1 });
}
//[BPARelayCommand]
private void Save()
{
if (string.IsNullOrEmpty(GoodName)) return;
if (Global.GLoFryMessage != null)
{
var res = Json.Data.FryPotMessage.FirstOrDefault(p => p.GoodKey == Global.GLoFryMessage.GoodKey);
if (res != null)
{
res.GoodName = GoodName;
res.fryPotProcesses = FryPotProcesses.ToList();
}
}
else
{
if (Json.Data.FryPotMessage.FirstOrDefault(p => p.GoodName == _goodName) != null) return;
Json.Data.FryPotMessage.Add(new FryPotMessages
{
GoodName = GoodName,
GoodKey = new Guid().ToString(),
fryPotProcesses = FryPotProcesses.ToList()
});
}
Json.Save();
ActionManage.GetInstance.Send("更新菜单");
ActionManage.GetInstance.Send("FoodManagerViewClose");
}
//[BPARelayCommand]
private void Delete(object o)
{
if (o == null) return;
if (o is FryPotProcess value)
{
foreach (var item in FryPotProcesses)
{
if (item.FryTime > value.FryTime)
{
Application.Current?.Dispatcher.Invoke(new Action(() =>
{
item.FryTime -= 1;
}));
}
}
FryPotProcesses.Remove(value);
}
}
public FoodManagerViewModel()
{
foreach (var item in Enum.GetValues(typeof(FryAction)))
{
FryAction.Add((FryAction)item);
}
if (Global.GLoFryMessage != null)//编辑
{
GoodName = Global.GLoFryMessage.GoodName;
FryPotProcesses = new ObservableCollection(Global.GLoFryMessage.fryPotProcesses);
}
}
}
}