using BBWY.Client.APIServices;
using BBWY.Client.Helpers;
using BBWY.Client.Models;
using BBWY.Client.Views.Order;
using BBWY.Common.Models;
using BBWY.Controls;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Input;
using System.Windows;
using BBWY.Common.Extensions;
using System.Threading.Tasks;
using BBWY.Client.Views.PackTask;
using HandyControl.Tools.Extension;
using Newtonsoft.Json;
using BBWY.Client.Models.APIModel.Response.PackTask;
using BBWY.Client.Models.PackTask;
using WebSocketSharp;
using BBWY.Client.Models.APIModel;
using BBWY.Client.Views.SealBox;
using BBWY.Client.Models.SealBox;
using BBWY.Client.ViewModels.SealBox;
using BBWY.Client.Views.FallWare;
using BBWY.Client.Models.FallWare;

namespace BBWY.Client.ViewModels.PackTask
{
    /// <summary>
    /// 
    /// </summary>
    public partial class TaskListViewModel : BaseVM, IDenpendency//注入服务
    {



        #region 属性绑定




        private string sealBoxWaitConfigureCount;
        /// <summary>
        /// 封箱 待配置数
        /// </summary>
        public string SealBoxWaitConfigureCount { get => sealBoxWaitConfigureCount; set { Set(ref sealBoxWaitConfigureCount, value); } }

        private string sealBoxConfiguredCount;
        /// <summary>
        ///封箱 已配置数
        /// </summary>
        public string SealBoxConfiguredCount { get => sealBoxConfiguredCount; set { Set(ref sealBoxConfiguredCount, value); } }

        private SealBoxConfigureType sealBoxConfigureType;
        /// <summary>
        /// 封箱配置状态
        /// </summary>
        public SealBoxConfigureType SealBoxConfigureType { get => sealBoxConfigureType; set { Set(ref sealBoxConfigureType, value); } }

        //private SealBoxConfigureType fallWareConfigureType;
        ///// <summary>
        ///// 落仓配置状态
        ///// </summary>
        //public SealBoxConfigureType FallWareConfigureType { get => fallWareConfigureType; set { Set(ref fallWareConfigureType, value); } }


        private ObservableCollection<SealBoxWaitConfigureModel> sealBoxWaitConfigureList;
        /// <summary>
        /// 封箱待配置列表
        /// </summary>
        public ObservableCollection<SealBoxWaitConfigureModel> SealBoxWaitConfigureList { get => sealBoxWaitConfigureList; set { Set(ref sealBoxWaitConfigureList, value); } }

        private ObservableCollection<SealBoxConfiguredModel> sealBoxConfiguredList;
        /// <summary>
        /// 封箱已配置列表
        /// </summary>
        public ObservableCollection<SealBoxConfiguredModel> SealBoxConfiguredList { get => sealBoxConfiguredList; set { Set(ref sealBoxConfiguredList, value); } }



        private ObservableCollection<FallWareConfiguredModel> fallWareWaitConfigureList;
        /// <summary>
        /// 落仓待配置列表
        /// </summary>
        public ObservableCollection<FallWareConfiguredModel> FallWareWaitConfigureList { get => fallWareWaitConfigureList; set { Set(ref fallWareWaitConfigureList, value); } }

        private ObservableCollection<FallWareConfiguredModel> fallWareConfiguredList;
        /// <summary>
        /// 落仓已配置列表
        /// </summary>
        public ObservableCollection<FallWareConfiguredModel> FallWareConfiguredList { get => fallWareConfiguredList; set { Set(ref fallWareConfiguredList, value); } }

        /// <summary>
        /// 查询时间段
        /// </summary>
        private DateTime startTime;
        public DateTime StartTime { get => startTime; set { Set(ref startTime, value); } }

        private DateTime endTime;
        public DateTime EndTime { get => endTime; set { Set(ref endTime, value); } }

        /// <summary>
        /// 查询任务id
        /// </summary>
        private string searchTaskId;
        public string SearchTaskId
        {
            get => searchTaskId; set
            {
                Set(ref searchTaskId, value);
            }
        }

        /// <summary>
        /// 查询Sku
        /// </summary>
        private string searchSkuId;
        public string SearchSkuId { get => searchSkuId; set { Set(ref searchSkuId, value); } }

        public TaskState? taskState;
        /// <summary>
        /// 任务状态
        /// </summary>
        public TaskState? TaskState
        {
            get => taskState; private set
            {
                Set(ref taskState, value);
            }
        }

        private int pageIndex = 1;
        private int pageSize = 10;

        public int PageIndex { get => pageIndex; set { Set(ref pageIndex, value); } }

        public int PageSize { get => pageSize; set { Set(ref pageSize, value); } }
        private int orderCount;//总数量
        public int OrderCount { get => orderCount; set { Set(ref orderCount, value); } }


        /// <summary>
        /// 未到货数量
        /// </summary>
        public string NoArrivedCount { get => noArrivedCount; set { Set(ref noArrivedCount, value); } }
        private string noArrivedCount;
        private string someArrivedCount;
        /// <summary>
        /// 部分到货数量
        /// </summary>
        public string SomeArrivedCount { get => someArrivedCount; set { Set(ref someArrivedCount, value); } }

        private string arrivedCount;
        /// <summary>
        /// 已到货数量
        /// </summary>
        public string ArrivedCount { get => arrivedCount; set { Set(ref arrivedCount, value); } }

        private bool isLoading;
        public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }


        private string waitPackCount;
        /// <summary>
        /// 待打包任务数
        /// </summary>
        public string WaitPackCount { get => waitPackCount; set { Set(ref waitPackCount, value); } }
        private string waitSealBoxCount;
        /// <summary>
        /// 带封箱任务数
        /// </summary>
        public string WaitSealBoxCount { get => waitSealBoxCount; set { Set(ref waitSealBoxCount, value); } }



        private string waitFallWareCount;
        /// <summary>
        /// 待落仓任务数
        /// </summary>
        public string WaitFallWareCount { get => waitFallWareCount; set { Set(ref waitFallWareCount, value); } }

        private string waitOutbound;
        /// <summary>
        /// 待出库任务数
        /// </summary>
        public string WaitOutbound { get => waitOutbound; set { Set(ref waitOutbound, value); } }


        private string waitCompleted;
        /// <summary>
        /// 待完成任务数
        /// </summary>
        public string WaitCompleted { get => waitCompleted; set { Set(ref waitCompleted, value); } }



        private SealBoxService sealBoxService;
        private PackTaskService packTaskService;
        WorkProcessService workProcessService;
        public int? taskStatus { get; set; }
        private ObservableCollection<PackTaskModel> packTaskList;
        /// <summary>
        /// 动态数据表
        /// </summary>
        public ObservableCollection<PackTaskModel> PackTaskList { get => packTaskList; set { Set(ref packTaskList, value); } }


        #endregion



        public TaskListViewModel(PackTaskService packTaskService, GlobalContext globalContext, ProductService productService, ConsumableService consumableService, WorkProcessService workProcessService, IncreateServiceService increateServiceService, SealBoxService sealBoxService)
        {
            this.globalContext = globalContext;
            this.productService = productService;
            this.consumableService = consumableService;
            this.workProcessService = workProcessService;
            this.increateServiceService = increateServiceService;
            this.packTaskService = packTaskService;
            PackTaskList = new ObservableCollection<PackTaskModel>();//初始化数据

            SetTaskStateCommand = new RelayCommand<TaskState?>(SetTaskState);

            SetSealBoxConfigureTypeCommand = new RelayCommand<SealBoxConfigureType>(s =>
            {
                PageIndex = 1;
                SealBoxConfigureType = s;
                Task.Factory.StartNew(() => SearchTaskList());
            });

            CreateTaskCommand = new RelayCommand(CreateTask);
            SearchTaskCommand = new RelayCommand(() =>
            {
                PageIndex = 1;
                Task.Factory.StartNew(() => SearchTaskList());  //手动点击查询订单
            });
            TaskPageIndexChangedCommand = new RelayCommand<PageArgs>(p =>
            {
                LoadIndex(p.PageIndex);
            });

            OpenSkuDetailCommand = new RelayCommand<object>(OpenSkuDetail);
            DeletedTaskCommand = new RelayCommand<object>(DeletedTask);

            ConfiguredSealBoxCommand = new RelayCommand(ConfiguredSealBox);
            UpdateSealBoxConfiguredCommand = new RelayCommand<SealBoxConfiguredModel>(UpdateSealBoxConfigured);

            StartTime = DateTime.Now.Date;
            EndTime = DateTime.Now.Date;
            IsLoading = false;
            //加载数据
            SetTaskState(null);
            this.sealBoxService = sealBoxService;

            SealBoxConfigureType = SealBoxConfigureType.已配置;

            SetFallWareConfiguredCommand = new RelayCommand<object>(SetFallWareConfigured);
        }

        private void SetFallWareConfigured(object obj)
        {
            var fallware = obj as FallWareConfiguredModel;
            JDWareBoxModel model = new JDWareBoxModel
            {
                ShopName = globalContext.User.Shop.ShopName,
                WareName = fallware.WareName,
                SealBoxId = fallware.SealBoxId,
                ProductCount = fallware.SealBoxTotalCount,
                BoxCount = fallware.BoxCount.Value,
                PrewOrder = fallware.PrewOrder,
                ProductTitle = fallware.ProductTitle,
                PurchaseOrder = fallware.PurchaseOrder,
                WaybillNo = fallware.WaybillNo
            };
            if (fallware.WareType== WareType.京仓)
            {

                //SetJDWareBoxWindow window = new SetJDWareBoxWindow(model,sealBoxService,fallware.WareType.Value,ReflashTask);
                //window.Show();
                var w = new SetJDWareBoxWindow2(model, sealBoxService, fallware.WareType.Value, ReflashTask);
                w.ShowDialog();
            }
            if (fallware.WareType == WareType.云仓)
            {

                SetCloudWareBoxWindow window = new SetCloudWareBoxWindow(model, sealBoxService, fallware.WareType.Value, ReflashTask);
                window.Show();
            }
        }

        private void UpdateSealBoxConfigured(SealBoxConfiguredModel model)
        {
            var sealBoxId = model.SealBoxId;
            var taskIds = model.SealBoxConfigureTasks.Select(s => s.TaskId).ToArray();

            var updateSealBoxConfig = sealBoxService.GetUpdateSealBoxConfigured(sealBoxId, taskIds);
            if (updateSealBoxConfig == null)
            {
                MessageBox.Show("网络异常,获取不到带封箱数据");
                return;
            }
            if (!updateSealBoxConfig.Success || updateSealBoxConfig.Data == null)
            {
                MessageBox.Show(updateSealBoxConfig.Msg);
                return;
            }



            SealBoxConfigureWindow sealBoxConfigureWindow = new SealBoxConfigureWindow(updateSealBoxConfig.Data.UpdateSealBoxConfiguredTaskDatas, ReflashTask, sealBoxId);
            sealBoxConfigureWindow.Show();
        }

        private void ConfiguredSealBox()
        {
            var waitSealBoxRes = sealBoxService.GetSealBoxWaitConfigureList(null, null, null, null, null);//获取所有待封装列表
            if (waitSealBoxRes == null)
            {
                MessageBox.Show("网络异常,获取不到带封箱数据");
                return;
            }
            if (!waitSealBoxRes.Success || waitSealBoxRes.Data == null)
            {
                MessageBox.Show(waitSealBoxRes.Msg);
                return;
            }
            if (waitSealBoxRes.Data.TotalCount <= 0)
            {
                MessageBox.Show("已全部封箱!");
                return;
            }
            var taskIds = waitSealBoxRes.Data.SealBoxWaitConfigureModels.Select(w => w.TaskId).ToArray();


            var updateSealBoxConfig = sealBoxService.GetUpdateSealBoxConfigured(0, taskIds);
            if (updateSealBoxConfig == null)
            {
                MessageBox.Show("网络异常,获取不到带封箱数据");
                return;
            }
            if (!updateSealBoxConfig.Success || updateSealBoxConfig.Data == null)
            {
                MessageBox.Show(updateSealBoxConfig.Msg);
                return;
            }
            SealBoxConfigureWindow sealBoxConfigureWindow = new SealBoxConfigureWindow(updateSealBoxConfig.Data.UpdateSealBoxConfiguredTaskDatas, ReflashTask, 0);
            sealBoxConfigureWindow.Show();


        }

        private void DeletedTask(object obj)
        {
            var packTaskmodel = (PackTaskModel)obj;
            if (!packTaskmodel.OrderId.IsNullOrEmpty())
            {
                System.Windows.MessageBox.Show($"暂不支持删除采购组的任务,如要删除,请到采购列表取消订单:{packTaskmodel.OrderId}");
                return;
            }
            MessageBoxResult result = MessageBox.Show("确定取消任务?", "提示",
                                           MessageBoxButton.YesNo,
                                           MessageBoxImage.Warning);
            if (result != MessageBoxResult.Yes) return;
            packTaskService.DeletedTask(packTaskmodel.TaskId);
            Task.Factory.StartNew(() => SearchTaskList());
        }


        private void IsLoadCount()
        {
            var packTaskResult = packTaskService.GetTaskAllCount(globalContext.User.Shop.ShopId.ToString());
            if (packTaskResult != null && packTaskResult.Success && packTaskResult.Data != null)
            {
                App.Current.Dispatcher.Invoke(new Action(() =>
                {
                    ArrivedCount = packTaskResult.Data.ArrivedCount.ToString();
                    NoArrivedCount = packTaskResult.Data.NoArrivedCount.ToString();
                    SomeArrivedCount = packTaskResult.Data.SomeArrivedCount.ToString();
                    //WorryCount = packTaskResult.Data.WorryCount.ToString();
                    WaitOutbound = packTaskResult.Data.WaitOutbound?.ToString();
                    WaitPackCount = packTaskResult.Data.WaitPackCount?.ToString();
                    WaitSealBoxCount = packTaskResult.Data.WaitSealBox?.ToString();
                    WaitFallWareCount = packTaskResult.Data.WaitFallWareCount?.ToString();
                    WaitCompleted = packTaskResult.Data.WaitCompleted?.ToString();
                }));
            }
        }

        private void LoadIndex(int pageIndex)
        {
            PageIndex = pageIndex;//
            SearchTaskList();
        }




        #region 事件绑定
        /// <summary>
        /// 设置落仓配置信息(上传材料)
        /// </summary>
        public ICommand SetFallWareConfiguredCommand { get; set; }
        /// <summary>
        /// 修改封箱数据
        /// </summary>
        public ICommand UpdateSealBoxConfiguredCommand { get; set; }
        /// <summary>
        /// 配置封箱策略
        /// </summary>
        public ICommand ConfiguredSealBoxCommand { get; set; }
        /// <summary>
        /// 待配置 /已配置
        /// </summary>
        public ICommand SetSealBoxConfigureTypeCommand { get; set; }

        /// <summary>
        /// 筛选数据 
        /// </summary>
        public ICommand SetTaskStateCommand { get; set; }
        /// <summary>
        /// 搜索数据
        /// </summary>
        public ICommand SearchTaskCommand { get; set; }

        /// <summary>
        /// 创建任务
        /// </summary>
        public ICommand CreateTaskCommand { get; set; }

        /// <summary>
        /// 页面改变事件
        /// </summary>
        public ICommand TaskPageIndexChangedCommand { get; set; }

        /// <summary>
        /// 打开图片链接
        /// </summary>
        public ICommand OpenSkuDetailCommand { get; set; }


        /// <summary>
        /// 删除任务
        /// </summary>
        public ICommand DeletedTaskCommand { get; set; }

        public void SetTaskState(TaskState? taskState)
        {
            PageIndex = 1;
            TaskState = taskState;
            SearchTaskList();

        }

        private ConsumableService consumableService;
        private IncreateServiceService increateServiceService;


        public void ReflashTask()//刷新界面
        {
            SearchTaskList();
        }

        private List<TaskState> waitSealBoxTaskStates = new List<TaskState> {
              Models.TaskState.待落仓, Models.TaskState.待封箱
        };//配置封箱的任务状态范围
        /// <summary>
        /// 搜索任务列表
        /// </summary>
        public void SearchTaskList()
        {
            long? taskId = null;
            try
            {
                if (SearchTaskId != null && !string.IsNullOrEmpty(SearchTaskId.Trim()))
                    taskId= Convert.ToInt64(SearchTaskId);
            }
            catch
            {
                System.Windows.MessageBox.Show("任务id必须为数字");
                return;

            }

            IsLoading = true;

            if (TaskState == null || !waitSealBoxTaskStates.Contains(TaskState.Value))
                Task.Factory.StartNew(() =>
                {

                    try
                    {
                        PackTaskList = new ObservableCollection<PackTaskModel>();//初始化数据
                        var datas = packTaskService.GetTaskList(SearchSkuId, SearchTaskId, StartTime, EndTime, (this.TaskState),
                            PageIndex, PageSize);
                        if (datas != null && datas.Data != null && datas.Success)
                        {
                            var dataModel = datas.Data;
                            OrderCount = dataModel.TotalCount;
                            foreach (var item in dataModel.Items)
                            {

                                var data = new PackTaskModel()
                                {
                                    Brand = item.Brand,
                                    SkuId = item.SkuId,
                                    AcceptName = item.UserName,
                                    Availability = (Availability)item.Availability,
                                    BasicPack = (BasicPack)item.BasicPack,
                                    DepartmentName = item.DepartmentName,
                                    CertificatePosition = (CertificatePosition)item.CertificatePosition,
                                    GoodsNumber = item.GoodsNumber,
                                    Increment1 = item.Increment1,
                                    ItemList = new List<SkuMessage>() { new SkuMessage
                            {    BrandName = item.BrandName,
                                 GoodsNo = item.ProductItemNum, Logo= item.Logo,
                                 ShopName = item.ShopName, SkuName = item.SkuName,
                                  Id = item.SkuId

                            } },
                                    MarkMessage = item.MarkMessage,
                                    PackType = (PackType)item.PackType,

                                    PositionType = item.PositionType,
                                    SkuCount = item.SkuCount,
                                    SkuTitle = item.SkuGoodsTitle,
                                    TaskId = item.TaskId,

                                    EndTime = item.CreateTime,
                                    BrandName = item.BrandName,
                                    OrderId = item.OrderId,
                                    TaskState = item.TaskState,

                                    // IsWorry = (Worry)item.IsWorry,
                                };
                                if (item.BarCodeDTO != null && item.BarCodeDTO.Id > 0)
                                {
                                    data.BarCodeModel = item.BarCodeDTO;
                                }
                                if (item.Cers != null)
                                {
                                    data.CertificateModel = item.Cers;
                                }
                                if (item.FeesItemResponse != null)
                                {
                                    data.FeesItemResponse = item.FeesItemResponse;
                                    data.FeesMoney = item.FeesItemResponse.SingleFees;
                                    data.IsShowFees = data.FeesMoney > 0 ? true : false;
                                    data.FeesItemResponse.DiscountSingleFees = item.FeesItemResponse.SingleFees * item.FeesItemResponse.disCount;
                                    data.FeesItemResponse.DiscountAllFees = item.FeesItemResponse.AllFees * item.FeesItemResponse.disCount;

                                }
                                else
                                {
                                    data.IsShowFees = false;
                                }
                                if (item.PackUserName != null && item.PackUserName.Count() > 0)
                                {
                                    data.PackUser = string.Join("\r\n", item.PackUserName);
                                }

                                data.ReflashTask = ReflashTask;

                                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                {
                                    PackTaskList.Add(data);
                                }));

                            }



                        }
                        else
                        {
                            MessageBox.Show("查不到数据");
                        }
                        IsLoadCount();

                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(ex.Message);

                    }
                    IsLoading = false;
                });

            if (TaskState != null && waitSealBoxTaskStates.Contains(TaskState.Value))//封箱操作
            {
                if (TaskState == Models.TaskState.待封箱)
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            if (SealBoxConfigureType == SealBoxConfigureType.待配置)
                            {
                                SealBoxWaitConfigureList = new ObservableCollection<SealBoxWaitConfigureModel>();
                                ApiResponse<SealBoxWaitConfigureResponse> sealBoxWaitRes = sealBoxService.GetSealBoxWaitConfigureList(SearchSkuId, SearchTaskId, PageSize, PageIndex);

                                if (sealBoxWaitRes == null)
                                {
                                    System.Windows.MessageBox.Show("网络异常"); IsLoading = false; return;
                                }

                                if (!sealBoxWaitRes.Success || sealBoxWaitRes.Data == null)
                                {
                                    System.Windows.MessageBox.Show(sealBoxWaitRes.Msg); IsLoading = false; return;
                                }
                                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                {
                                    OrderCount = sealBoxWaitRes.Data.TotalCount;
                                }));

                                foreach (var item in sealBoxWaitRes.Data.SealBoxWaitConfigureModels)
                                {
                                    App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                    {
                                        SealBoxWaitConfigureList.Add(item);
                                    }));
                                }

                            }

                            if (SealBoxConfigureType == SealBoxConfigureType.已配置)
                            {
                                SealBoxConfiguredList = new ObservableCollection<SealBoxConfiguredModel>();
                                var sealBoxRes = sealBoxService.GetSealBoxConfiguredList(PositionState.待封箱, SearchSkuId, SearchTaskId, globalContext.User.Shop.ShopId.ToString(), PageSize, PageIndex);
                                if (sealBoxRes == null)
                                {
                                    System.Windows.MessageBox.Show("网络异常"); IsLoading = false; return;
                                }

                                if (!sealBoxRes.Success || sealBoxRes.Data == null)
                                {
                                    System.Windows.MessageBox.Show(sealBoxRes.Msg); IsLoading = false; return;
                                }
                                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                {
                                    OrderCount = sealBoxRes.Data.TotalCount;
                                }));

                                foreach (var item in sealBoxRes.Data.SealBoxConfiguredModels)
                                {
                                    App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                    {
                                        SealBoxConfiguredList.Add(item);
                                    }));
                                }
                            }
                            IsLoadSealBoxCount();
                            IsLoadCount();
                        }
                        catch (Exception ex)
                        {

                            System.Windows.MessageBox.Show(ex.Message);
                        }

                        IsLoading = false;
                    });
                if (TaskState == Models.TaskState.待落仓)
                    Task.Factory.StartNew(() =>
                    {

                        try
                        {
                            if (SealBoxConfigureType == SealBoxConfigureType.待配置)
                            {
                                FallWareWaitConfigureList = new ObservableCollection<FallWareConfiguredModel>();
                                var fallWareRes = sealBoxService.SearchFallWareConfiguredList(PositionState.待落仓, taskId, SearchSkuId, PageIndex, PageSize);

                                if (fallWareRes == null)
                                {
                                    System.Windows.MessageBox.Show("网络异常"); IsLoading = false; return;
                                }

                                if (!fallWareRes.Success || fallWareRes.Data == null)
                                {
                                    System.Windows.MessageBox.Show(fallWareRes.Msg); IsLoading = false; return;
                                }
                                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                {
                                    OrderCount = fallWareRes.Data.TotalCount;
                                }));

                                foreach (var item in fallWareRes.Data.FallWareConfiguredModels)
                                {
                                    App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                    {
                                        FallWareWaitConfigureList.Add(item);
                                    }));
                                }
                            }
                            if (SealBoxConfigureType == SealBoxConfigureType.已配置)
                            {
                                FallWareConfiguredList = new ObservableCollection<FallWareConfiguredModel>();
                                var fallWareRes = sealBoxService.SearchFallWareConfiguredList(PositionState.已配置待落仓, taskId, SearchSkuId, PageIndex, PageSize);

                                if (fallWareRes == null)
                                {
                                    System.Windows.MessageBox.Show("网络异常"); IsLoading = false; return;
                                }

                                if (!fallWareRes.Success || fallWareRes.Data == null)
                                {
                                    System.Windows.MessageBox.Show(fallWareRes.Msg); IsLoading = false; return;
                                }
                                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                {
                                    OrderCount = fallWareRes.Data.TotalCount;
                                }));

                                foreach (var item in fallWareRes.Data.FallWareConfiguredModels)
                                {
                                    App.Current.Dispatcher.BeginInvoke(new Action(() =>
                                    {
                                        FallWareConfiguredList.Add(item);
                                    }));
                                }
                            }

                            IsLoadFallWareCount();
                            IsLoadCount();

                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);

                        }
                        IsLoading = false;

                    });
            }



        }

        GlobalContext globalContext;
        ProductService productService;
        private void IsLoadFallWareCount()
        {
            var res = sealBoxService.GetFallWareConfigureCounts(globalContext.User.Shop.ShopId.ToString());
            if (res != null && res.Success && res.Data != null)
            {
                SealBoxWaitConfigureCount = res.Data.FallWareWaitConfigureCount.ToString();
                SealBoxConfiguredCount = res.Data.FallWareConfiguredCount.ToString();
            }
        }

        private void IsLoadSealBoxCount()
        {
            var res = sealBoxService.GetSealBoxPackStateCount();
            if (res != null && res.Success && res.Data != null)
            {
                SealBoxWaitConfigureCount = res.Data.SealBoxWaitConfigureCount.ToString();
                SealBoxConfiguredCount = res.Data.SealBoxConfiguredCount.ToString();
            }

        }

        /// <summary>
        /// 展示发布任务页面
        /// </summary>
        public void CreateTask()
        {



            PublishTaskWindow publish = new PublishTaskWindow(ReflashTask);
            publish.Show();
        }






        /// <summary>
        /// 弹出条形码可视化界面
        /// </summary>
        public void ShowBarCodeWindow()
        {

        }


        /// <summary>
        /// 弹出合格证 可视化页面
        /// </summary>
        public void ShowCertificateWindow()
        {
        }
        /// <summary>
        /// 筛选任务状态数据(根据TaskList数据)
        /// </summary>
        public void SelectTaskStatus() { }
        #endregion
        private void OpenSkuDetail(object param)
        {
            var paramList = (object[])param;
            // var orderId = paramList[0].ToString();


            var skuId = paramList.Last().ToString();


            var url = $"https://item.jd.com/{skuId}.html";
            try
            {
                System.Diagnostics.Process.Start("explorer.exe", url);
            }
            catch (Exception ex)
            {
                Clipboard.SetText(url);
                MessageBox.Show($"{ex.Message}\r\n调用浏览器失败,网页链接已复制到剪切板,请手动打开浏览器访问", "提示");
            }

        }









    }
}