using HandyControl.Controls; using Ping9719.WpfEx.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Input; using SqlSugar; using 智慧物流软件系统.Views.Controls; using 智慧物流软件系统.Api; using WCS.Model; using WCS.Model.ApiModel; using WCS.Model.ApiModel.MatBaseInfo; using System.Collections.ObjectModel; using WCS.Model.ApiModel.Stocktaking; using System.Security.AccessControl; using WCS.Model.ApiModel.AGV; namespace 智慧物流软件系统.ViewModel { public class AGVTaskViewModel : BindableBase { public AGVTaskViewModel() { //初始化下拉列表框 TaskStatus.Add("全部"); var statuses = Enum.GetValues(typeof(TaskStatusEnum)) .Cast() .ToList(); foreach (var status in statuses) { TaskStatus.Add(status.ToString()); } } #region Property private ObservableCollection dataGridItemSource; public ObservableCollection DataGridItemSource { get { return dataGridItemSource; } set { SetProperty(ref dataGridItemSource, value); } } public AGVTaskModel selectedataGridItem; public AGVTaskModel SelectedataGridItem { get { return selectedataGridItem; } set { SetProperty(ref selectedataGridItem, value); } } /// /// 货架编码 /// private string shelfCode; public string ShelfCode { get { return shelfCode; } set { SetProperty(ref shelfCode, value); } } /// /// 任务创建人 /// private string createUser; public string CreateUser { get { return createUser; } set { SetProperty(ref createUser, value); } } /// /// 起点 /// private string startLocationCode; public string StartLocationCode { get { return startLocationCode; } set { SetProperty(ref startLocationCode, value); } } /// /// 终点 /// private string endLocationCode; public string EndLocationCode { get { return endLocationCode; } set { SetProperty(ref endLocationCode, value); } } /// /// 结束位置 /// private List stocktakingStatuses = new List(); public List TaskStatus { get { return stocktakingStatuses; } set { SetProperty(ref stocktakingStatuses, value); } } private string selectedTaskStatus; public string SelectedTaskStatus { get { return selectedTaskStatus; } set { SetProperty(ref selectedTaskStatus, value); } } #endregion #region Command public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); } public void BtnReset() { ShelfCode = string.Empty; CreateUser = string.Empty; StartLocationCode = string.Empty; EndLocationCode = string.Empty; SelectedTaskStatus = TaskStatus.Where(t => t.Contains("正在执行")).First(); } public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearchReset); } public void BtnSearchReset() { BtnSearch(true); } public void BtnSearch(bool IsPageReset = true) { if (CurrentPage == 0 || IsPageReset) { CurrentPage = 1; return; } var isSelected = Enum.TryParse(SelectedTaskStatus, out TaskStatusEnum status); #region 调用接口获取数据 var dia = Dialog.Show(new TextDialog()); try { var body = new GetAGVTasksRequest() { ShelfCode = ShelfCode, StartLocationCode = StartLocationCode, EndLocationCode = EndLocationCode, CreateUser = CreateUser, TaskStatus = isSelected ? status : null, UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, PageNumber = CurrentPage, PageSize = PageSize, }; var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "AgvTask/getAGVTasks", body, "POST"); if (Result != null && Result.Data != null && Result.Data.Lists != null) { DataGridItemSource = new ObservableCollection(Result.Data.Lists); MaxPage = Result.Data.MaxPage; TotalCount = Result.Data.TotalCount; } } catch (Exception ex) { Growl.Error("加载数据失败:" + ex.Message); } finally { dia.Close(); } #endregion } /// /// 物料删除操作 /// public ICommand BtnCommitCommand { get => new DelegateCommand(BtnCommit); } public async void BtnCommit() { Growl.Ask($"是否提交所有勾选的数据?", isConfirmed => { if (isConfirmed) { //查询勾选的第一个数据 var needDeleteIds = DataGridItemSource?.Where(t => t.IsSelected == true) .Select(t => t.Id) .ToList(); if (needDeleteIds == null) { Growl.Warning("请选择需要提交的数据!"); } else { var body = new DeleteInfosRequest() { UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, needDeleteIds = needDeleteIds, }; var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "PDAStocktaking/commitStocktakingInfos", body, "POST"); if (Result != null && Result.Code == 200) { CurrentPage = 1; Growl.Success("提交成功!" + Result?.Message); } else { Growl.Error($"{Result?.Message?.ToString()}"); } } } return true; }); } /// /// 物料修改操作 /// public ICommand BtnEditCommand { get => new DelegateCommand(BtnEdit); } public async void BtnEdit() { ////查询勾选的第一个数据 //var matDetailStocktakingInfo = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault(); //if (matDetailStocktakingInfo == null) //{ // Growl.Warning("请选择需要修改的数据!"); // return; //} //else //{ // var updateView = new MatDetailStocktakingInfoUpdateView("修改盘点数据", matDetailStocktakingInfo); // updateView.ShowDialog(); // if (updateView.DialogResult == true) // { // matDetailStocktakingInfo = updateView.matDetailStocktakingInfo; // var body = new UpdateStocktakingInfoRequest() // { // MatDetailStocktakingInfoId = matDetailStocktakingInfo.Id, // StocktakingQty = matDetailStocktakingInfo.StocktakingQty, // UserName = LocalStatic.CurrentUser, // DeviceType = LocalFile.Config.DeviceType, // }; // var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "PDAStocktaking/updateStocktakingInfos", body, "POST"); // if (Result != null && Result.Code == 200) // { // CurrentPage = 1; // Growl.Success("修改成功!"); // } // else // { // Growl.Error($"{Result?.Message?.ToString()}"); // } // } //} } /// /// 物料删除操作 /// public ICommand BtnDeleteCommand { get => new DelegateCommand(BtnDelete); } public async void BtnDelete() { Growl.Ask($"是否删除所有勾选得数据]!", isConfirmed => { if (isConfirmed) { //查询勾选的第一个数据 var needDeleteIds = DataGridItemSource?.Where(t => t.IsSelected == true) .Select(t => t.Id) .ToList(); if (needDeleteIds == null) { Growl.Warning("请选择需要修改的数据!"); } else { var body = new DeleteInfosRequest() { UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, needDeleteIds = needDeleteIds, }; var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "PDAStocktaking/deleteStocktakingInfos", body, "POST"); if (Result != null && Result.Code == 200) { CurrentPage = 1; Growl.Success("删除成功!" + Result?.Message); } else { Growl.Error($"{Result?.Message?.ToString()}"); } } } return true; }); } #endregion #region PageOperation 分页操作 private int currentPage; public int CurrentPage { get { return currentPage; } set { SetProperty(ref currentPage, value); BtnSearch(false); } } private int maxPage; public int MaxPage { get { return maxPage; } set { SetProperty(ref maxPage, value); } } //总数量 private int totalCount; public int TotalCount { get { return totalCount; } set { SetProperty(ref totalCount, value); } } private int pageSize = 10; public int PageSize { get => pageSize; set { SetProperty(ref pageSize, value); BtnSearch(true); } } public ICommand BtnFirstPageCommand { get => new DelegateCommand(BtnFirstPage); } public void BtnFirstPage() { CurrentPage = 1; } public ICommand BtnPrePageCommand { get => new DelegateCommand(BtnPrePage); } public void BtnPrePage() { if (CurrentPage > 1) { CurrentPage--; } } public ICommand BtnNextPageCommand { get => new DelegateCommand(BtnNextPage); } public void BtnNextPage() { if (CurrentPage < MaxPage) { CurrentPage++; } } public ICommand BtnLastPageCommand { get => new DelegateCommand(BtnLastPage); } public void BtnLastPage() { if (CurrentPage != MaxPage) { CurrentPage = MaxPage; } } #endregion } }