using HandyControl.Controls;
using HandyControl.Data;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using TouchSocket.Core;
using Newtonsoft.Json;
using WCS.Model.ApiModel.MXBackgroundThread;
using 智能仓储WCS管理系统.Api;

namespace 智能仓储WCS管理系统.ViewModel
{
    public class MXOutOrderViewModel : BindableBase
    {
        public MXOutOrderViewModel()
        {
        }


        #region Property
        private string matCode1;
        public string MatCode1
        {
            get { return matCode1; }
            set
            {
                SetProperty(ref matCode1, value);
            }
        }

        private string orderProdNumber;
        public string OrderProdNumber
        {
            get { return orderProdNumber; }
            set
            {
                SetProperty(ref orderProdNumber, value);
            }
        }

        private string orderWorkNumber;
        public string OrderWorkNumber
        {
            get { return orderWorkNumber; }
            set
            {
                SetProperty(ref orderWorkNumber, value);
            }
        }

        private string pickBillNumber;
        public string PickBillNumber
        {
            get { return pickBillNumber; }
            set
            {
                SetProperty(ref pickBillNumber, value);
            }
        }

        private string warehouseCode;
        public string WarehouseCode
        {
            get { return warehouseCode; }
            set
            {
                SetProperty(ref warehouseCode, value);
            }
        }



        private List<PickOrder> dataGridItemSource;
        public List<PickOrder> DataGridItemSource
        {
            get { return dataGridItemSource; }
            set
            {
                SetProperty(ref dataGridItemSource, value);
            }
        }




        #endregion

        #region Command
        public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearch); }
        public void BtnSearch()
        {
            Task.Run(() =>
            {
                var request = new PickOrderRequest()
                {
                    orderProdNumber = OrderProdNumber,
                    orderWorkNumber = OrderWorkNumber,
                    pickBillNumber = PickBillNumber
                };
                var requeststr = JsonConvert.SerializeObject(request);
                var result = ApiHelp.MXGetDataFromHttpLongWait<List<PickOrder>>(requeststr, LocalFile.Config.GetPickOrderUrl, "POST");
                if (result != null && result.code == 200 && result.data != null && result.data.Count() > 0)
                {
                    DataGridItemSource = result.data;
                }
                else if (result != null && result.code == 200 && (result.data == null || result.data.Count == 0))
                {
                    result.message = "输入的搜索条件未查询到发料单信息！";
                    Growl.Warning(result.message);
                    DataGridItemSource = result.data;
                }
                else
                {
                    Growl.Warning("调用MES接口超时：搜索失败！");
                }
            });
        }
        #endregion


    }
}
