ProductDescriptionViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Prism.Commands;
  2. using Prism.Events;
  3. using Prism.Ioc;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using TeamAAS_VP.Events;
  12. using TeamAAS_VP.Core;
  13. using TeamAAS_VP.Models;
  14. namespace TeamAAS_VP.ViewModels.Product
  15. {
  16. public class ProductDescriptionViewModel : BindableBase
  17. {
  18. IRegionManager _regionManager;
  19. IEventAggregator _eventAggregator;
  20. IContainerProvider _container;
  21. IDialogService _dialogService;
  22. ProductsViewModel productsViewModel;
  23. #region 属性
  24. private ProductModel _SelectProduct;
  25. /// <summary>
  26. /// 选中的产品
  27. /// </summary>
  28. public ProductModel SelectProduct
  29. {
  30. get { return _SelectProduct; }
  31. set { SetProperty(ref _SelectProduct, value); }
  32. }
  33. #endregion
  34. #region 命令
  35. private DelegateCommand _NextCommand;
  36. public DelegateCommand NextCommand =>
  37. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  38. private DelegateCommand _BackCommand;
  39. public DelegateCommand BackCommand =>
  40. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  41. private DelegateCommand _LoadedCommand;
  42. public DelegateCommand LoadedCommand =>
  43. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  44. #endregion
  45. #region 事件
  46. #endregion
  47. public ProductDescriptionViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService)
  48. {
  49. _regionManager = regionManager;
  50. _eventAggregator = ea;
  51. _container = container;
  52. _dialogService = dialogService;
  53. //订阅权限登录事件
  54. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  55. productsViewModel = _container.Resolve<ProductsViewModel>();
  56. SelectProduct = productsViewModel.SelectProduct;
  57. }
  58. #region 方法
  59. /// <summary>
  60. /// 下一步
  61. /// </summary>
  62. void ExecuteNextCommand()
  63. {
  64. _regionManager.RequestNavigate("ProductRegionContext", "ProductProcessManage");
  65. }
  66. void ExecuteBackCommand()
  67. {
  68. _regionManager.RequestNavigate("ProductRegionContext", "ProductHome");
  69. }
  70. void ExecuteLoadedCommand()
  71. {
  72. if (_container.Resolve<Management>().CurrentUser.userPart == Enums.UserPart.Operator)
  73. {
  74. IsAllowEdit = false;
  75. }
  76. else
  77. {
  78. IsAllowEdit = true;
  79. }
  80. productsViewModel = _container.Resolve<ProductsViewModel>();
  81. SelectProduct = productsViewModel.SelectProduct;
  82. }
  83. #endregion
  84. private bool _IsAllowEdit = false;
  85. public bool IsAllowEdit
  86. {
  87. get { return _IsAllowEdit; }
  88. set { SetProperty(ref _IsAllowEdit, value); }
  89. }
  90. private void LoginChange(Models.User user)
  91. {
  92. if (user.userPart == Enums.UserPart.Operator)
  93. {
  94. IsAllowEdit = false;
  95. }
  96. else
  97. {
  98. IsAllowEdit = true;
  99. }
  100. }
  101. }
  102. }