using HandyControl.Controls;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using WCS.BLL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.Model.ApiModel.MatInventoryDetail;
using 智慧物流软件系统.Api;

namespace 智慧物流软件系统.ViewModels
{
    public class OutInventoryAddMatViewModel : BindableBase
    {
        #region Property
        private ObservableCollection<MatInventorySummaryModel> dataGridItemSource = new ObservableCollection<MatInventorySummaryModel>();
        public ObservableCollection<MatInventorySummaryModel> DataGridItemSource
        {
            get { return dataGridItemSource; }
            set
            {
                SetProperty(ref dataGridItemSource, value);
            }
        }

        private MatInventorySummaryModel selectedataGridItem;
        public MatInventorySummaryModel SelectedataGridItem
        {
            get { return selectedataGridItem; }
            set
            {
                SetProperty(ref selectedataGridItem, value);
            }
        }


        private string matCode;
        public string MatCode
        {
            get { return matCode; }
            set
            {
                SetProperty(ref matCode, value);
            }
        }

        private string matName;
        public string MatName
        {
            get { return matName; }
            set
            {
                SetProperty(ref matName, value);
            }
        }

        private int shelfTypeId;
        public int ShelfTypeId
        {
            get => shelfTypeId;
            set { SetProperty(ref shelfTypeId, value); }
        }

        #endregion

        #region Command
        /// <summary>
        /// 搜索
        /// </summary>
        public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearch); }
        public void BtnSearch()
        {
            #region 调用接口获取数据
            try
            {
                var body = new GetMatInventorySummaryRequest()
                {
                    MatName = MatName,
                    MatCode = MatCode,
                    ShelfTypeId = ShelfTypeId,
                };
                var Result = ApiHelp.GetDataFromHttp<ResponseCommon<List<MatInventorySummaryModel>>>(LocalFile.Config.ApiIpHost + "matInventoryDetail/getMatInventorySummary", body, "POST");
                if (Result != null && Result.Data != null)
                {
                    DataGridItemSource = new ObservableCollection<MatInventorySummaryModel>(Result.Data);
                }
            }
            catch (Exception ex)
            {
                Growl.Error("加载数据失败：" + ex.Message);
            }
            finally
            {
            }
            #endregion
        }
        #endregion
    }
}
