|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
-
- global using CommunityToolkit.Mvvm.Input;
- using BPASmartClient.Helper;
- using BPASmartClient.Message;
-
- namespace BPASmartClient.MilkWithTea.ViewModel
- {
- partial class MainControlViewModel: ObservableObject
- {
-
- /// <summary>
- /// 本地奶茶列表
- /// </summary>
- public ObservableCollection<LocalRecipe> localTeaWithMilks { get; set; } = Json<JsonLocalRecipes>.Data.localRecipes;
-
- /// <summary>
- /// 奶茶对应的原料列表
- /// </summary>
- public ObservableCollection<LocalMaterail> materialRecipes { get; set; } = new ObservableCollection<LocalMaterail>();
-
- /// <summary>
- /// 订单状态列表
- /// </summary>
- public ObservableCollection<MorkOrder> orderStatusLists { get; set; } = new ObservableCollection<MorkOrder>();
-
- /// <summary>
- /// 等待取餐列表
- /// </summary>
- public ObservableCollection<MorkOrder> WaitTakeMeal { get; set; } = new ObservableCollection<MorkOrder>();
-
- /// <summary>
- /// 当前正在制作的奶茶
- /// </summary>
- [ObservableProperty]
- private string _currentGood = "茉莉花茶";
- /// <summary>
- /// 奶茶制作百分比
- /// </summary>
- [ObservableProperty]
- private string _makePercent = "0";
-
- [ObservableProperty]
- private LocalRecipe _selectedRecipe;
-
- /// <summary>
- /// 当前正在制作的奶茶
- /// </summary>
- public bool MakeEnable { get { return GLobal.makeEnable; } set { GLobal.makeEnable = value; OnPropertyChanged(); } }
-
- /// <summary>
- /// 本地奶茶制作
- /// </summary>
- [RelayCommand]
- private void MakeGood()
- {
- if(SelectedRecipe == null) return;
- foreach(var item in SelectedRecipe.localMaterails)
- {
- var res = Json<JsonLocalRecipes>.Data.localMaterails.FirstOrDefault(p => p.MaterialID == item.MaterialID);
- if ( res!= null)
- {
- item.MaterialPosition = res.MaterialPosition;
- }
- else
- {
- MessageLog.GetInstance.ShowEx($"配料:{item.MaterialName}不存在,下单失败");
- return;
- }
- }
- ActionManage.GetInstance.Send( "MakeGoods",SelectedRecipe);
- }
-
-
-
-
- public MainControlViewModel()
- {
- Init();
- MorkOrderPush morkOrderPush = new MorkOrderPush() { GoodsName = "珍珠奶茶", SortNum = 1 };
- MorkOrderPush morkOrderPush1 = new MorkOrderPush() { GoodsName = "茉莉花茶", SortNum = 2 };
- MorkOrderPush morkOrderPush2 = new MorkOrderPush() { GoodsName = "芝芝梅梅", SortNum = 3 };
-
- orderStatusLists.Add(new MorkOrder()
- {
- StartDate = "11:20",EndDate ="11:24",CompleteDate ="4",OrderStatus = ORDER_STATUS.COMPLETED_COOK,
- OrderPush = morkOrderPush
-
- });
- orderStatusLists.Add(new MorkOrder()
- {
-
- StartDate = "11:36",
- EndDate = "11:40",
- CompleteDate = "4",
- OrderStatus = ORDER_STATUS.COOKING,
- OrderPush = morkOrderPush1
-
- });
- orderStatusLists.Add(new MorkOrder()
- {
-
- StartDate = "10:33",
- EndDate = "10:28",
- CompleteDate = "5",
- OrderStatus = ORDER_STATUS.COMPLETED_TAKE,
- OrderPush = morkOrderPush2
-
- });
-
-
-
- }
-
-
-
- /// <summary>
- /// MQTT 大屏取餐通知委托
- /// </summary>
- public void Init()
- {
- //清除订单数据
- //ActionManage.GetInstance.Register(new Action(() =>
- //{
- // Application.Current.Dispatcher.Invoke(() =>
- // {
- // orderStatusLists.Clear();
- // WaitTakeMeal.Clear();
- // });
- //}), "ClearOrders");
-
- ActionManage.GetInstance.Register(new Action<object[]>((o) =>
- {
- if (o is object[] obj)
- {
- if (o.Length == 2)
- {
- if (o[0] is MorkOrderPush morkOrderpush && o[1] is IDevice device)
- {
- ObservableCollection<MorkOrder> observableCollection = new ObservableCollection<MorkOrder>();
- MorkOrder morkOrder = new MorkOrder()
- {
- OrderPush = morkOrderpush,
- OrderStatus = ORDER_STATUS.WAIT,
- StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- };
- observableCollection.Add(morkOrder);
- Application.Current?.Dispatcher.BeginInvoke((Action)delegate
- {
- int index = Array.FindIndex(Json<KeepDataBase>.Data.orderLists.ToArray(), p => p.DeviceId == device.DeviceId.ToString());
- if (index < 0)
- {
- Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
- {
- DeviceId = device.DeviceId.ToString(),
- IsAllSelect = true,
- morkOrderPushes = observableCollection,
-
- });
- }
- else
- {
- Json<KeepDataBase>.Data.orderLists.ElementAt(index).morkOrderPushes.Add(morkOrder);
- }
-
- orderStatusLists.Add(new MorkOrder()
- {
- OrderPush = morkOrderpush,
- OrderStatus = ORDER_STATUS.WAIT,
- StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- });
- });
-
- }
- }
- }
-
- }), "AddOrder");
-
- EventBus.EventBus.GetInstance().Subscribe<OrderStatusChangedEvent>(0, OrderStatusChangedHandle);
-
- ActionManage.GetInstance.Register(new Action<object[]>((o)=>
- {
- if (o is object[] obj)
- {
- if (o.Length == 2)
- {
- CurrentGood = o[0].ToString();
- MakePercent = o[1].ToString();
- }
- }
- }), "奶茶制作进度");
-
-
-
- }
-
- private void OrderStatusChangedHandle(IEvent @event, EventBus.EventBus.EventCallBackHandle callBack)
- {
- OrderStatusChangedEvent orderStatusChange = @event as OrderStatusChangedEvent;
- int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
- switch (orderStatusChange.Status)
- {
- case ORDER_STATUS.COOKING:
- if (index >= 0 && index < orderStatusLists.Count)
- orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
-
- break;
- case ORDER_STATUS.COMPLETED_COOK:
- if (index >= 0 && index < orderStatusLists.Count)
- {
- Application.Current.Dispatcher.BeginInvoke((Action)delegate
- {
- orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
- orderStatusLists.ElementAt(index).EndDate = DateTime.Now.ToString("HH:mm:ss");
- TimeSpan timeSpan = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).StartDate));
- orderStatusLists.ElementAt(index).CompleteDate = $"{timeSpan.TotalSeconds.ToString("0.00")} S";
-
- //压力测试时注释,正常使用需要取消注释
- if (!BPASmartClient.Business.InternetInfo.IsEnableTest)
- {
- WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index));
- orderStatusLists.RemoveAt(index);
- }
-
- });
- }
-
- break;
- case ORDER_STATUS.COMPLETED_TAKE:
- if (BPASmartClient.Business.InternetInfo.IsEnableTest && index >= 0 && index < orderStatusLists.Count)
- orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
-
- //压力测试时注释,正常使用需要取消注释
- var re = WaitTakeMeal.FirstOrDefault(p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
- if (re != null)
- {
- Application.Current.Dispatcher.BeginInvoke((Action)delegate
- {
- WaitTakeMeal.Remove(re);
- var removeObj = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.morkOrderPushes.FirstOrDefault(s => s.OrderPush.SuborderId == re.OrderPush.SuborderId) != null);
- if (removeObj != null) Json<KeepDataBase>.Data.orderLists.Remove(removeObj);
- });
- }
- break;
- default:
- break;
-
- }
- }
- }
- }
|