using HandyControl.Controls; using MiniExcelLibs; using Ping9719.WpfEx.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Input; using System.Windows.Media; using SqlSugar; using HandyControl.Data; using System.Windows; using Newtonsoft.Json.Linq; using 智能仓储WCS管理系统.Views.Controls; using WCS.Model.ApiModel.User; using 智能仓储WCS管理系统.Api; using WCS.Model; using WCS.Model.ApiModel; namespace 智能仓储WCS管理系统.ViewModel { public class UserViewModel : BindableBase { private List dataList = new List(); /// /// 列表数据 /// public List DataList { get => dataList; set { SetProperty(ref dataList, value); } } #region 筛选 private string info1; public string Info1 { get => info1; set { SetProperty(ref info1, value); } } #endregion public ICommand UpdateListCommand { get => new DelegateCommand(UpdateList); } /// /// 更新信息 /// public void UpdateList() { var dia = Dialog.Show(new TextDialog()); try { var body = new GetUsersRequest() { UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, Info = Info1, }; var Result = ApiHelp.GetDataFromHttp>>(LocalFile.Config.ApiIpHost + "user/getUsers", body, "POST"); if (Result != null && Result.Data != null) { DataList = Result.Data; } } catch (Exception ex) { Growl.Error("加载数据失败:" + ex.Message); } finally { dia.Close(); } } public ICommand SeeCommand { get => new DelegateCommand(See); } public void See(UserModel obj) { UserEditView.Show(obj, CrudEnum.Read); } public ICommand AddCommand { get => new DelegateCommand(Add); } public void Add() { var isUp = UserEditView.Show(new UserModel(), CrudEnum.Create); if (isUp) { UpdateList(); Growl.Success("创建成功"); } } public ICommand UpdateCommand { get => new DelegateCommand(Update); } public void Update(UserModel obj) { var isUp = UserEditView.Show(obj, CrudEnum.Update); if (isUp) { UpdateList(); Growl.Success("更新成功"); } } public ICommand DelCommand { get => new DelegateCommand(Del); } public void Del(UserModel obj) { Growl.Ask($"是否删除用户[{obj.LoginName}]!", isConfirmed => { if (isConfirmed) { try { var body = new AddUserRequest() { UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, User = obj, AddOrUpdate = AddOrUpdate.Delete }; var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "user/addUser", body, "POST"); if (Result != null && Result.Code == 200) { UpdateList(); Growl.Success("删除成功"); } else { Growl.Error($"删除失败:{Result.Message.ToString()}"); } } catch (Exception ex) { Growl.Error($"删除失败:{ex.ToString()}"); return true; } } return true; }); } } }