From 44a7421bb297e3087a8b8d7cf103bad7a186a021 Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Thu, 13 Apr 2023 00:28:22 +0800 Subject: [PATCH] 1 --- .../BatchPurchase/ProductSkuWithScheme.cs | 3 + BBWY.Client/Models/MappingProfile.cs | 1 + BBWY.Client/Models/Product/Purchaser.cs | 24 ++++- .../BatchPurchaseAddProductSkuViewModel.cs | 94 ++++++++++++---- .../BatchPurchaseAddProductSku.xaml | 101 +++++++++++++++++- .../BatchPurchase/BatchPurchaseBusiness.cs | 2 +- 6 files changed, 199 insertions(+), 26 deletions(-) diff --git a/BBWY.Client/Models/BatchPurchase/ProductSkuWithScheme.cs b/BBWY.Client/Models/BatchPurchase/ProductSkuWithScheme.cs index e4836ff8..e19f5d0c 100644 --- a/BBWY.Client/Models/BatchPurchase/ProductSkuWithScheme.cs +++ b/BBWY.Client/Models/BatchPurchase/ProductSkuWithScheme.cs @@ -7,6 +7,7 @@ namespace BBWY.Client.Models public class ProductSkuWithScheme : NotifyObject { private int quantity; + private bool isSelected; public string Id { get; set; } public string SkuId { get; set; } @@ -41,6 +42,8 @@ namespace BBWY.Client.Models public IList PurchaseSchemeProductSkuList { get; set; } + public bool IsSelected { get => isSelected; set { Set(ref isSelected, value); } } + public ProductSkuWithScheme() { PurchaseSchemeProductSkuList = new ObservableCollection(); diff --git a/BBWY.Client/Models/MappingProfile.cs b/BBWY.Client/Models/MappingProfile.cs index 8ff89753..6c871dd9 100644 --- a/BBWY.Client/Models/MappingProfile.cs +++ b/BBWY.Client/Models/MappingProfile.cs @@ -31,6 +31,7 @@ namespace BBWY.Client.Models CreateMap(); CreateMap(); CreateMap(); + CreateMap(); } } } diff --git a/BBWY.Client/Models/Product/Purchaser.cs b/BBWY.Client/Models/Product/Purchaser.cs index 21ab7466..5f766231 100644 --- a/BBWY.Client/Models/Product/Purchaser.cs +++ b/BBWY.Client/Models/Product/Purchaser.cs @@ -1,4 +1,8 @@ -namespace BBWY.Client.Models +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace BBWY.Client.Models { /// /// 采购商 @@ -22,4 +26,22 @@ public Platform Platform { get; set; } } + + public class PurchaserComparer : IEqualityComparer + { + public bool Equals([AllowNull] Purchaser x, [AllowNull] Purchaser y) + { + if (Object.ReferenceEquals(x, y)) return true; + + if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null)) + return false; + + return x?.Id == y?.Id; + } + + public int GetHashCode([DisallowNull] Purchaser obj) + { + return base.GetHashCode(); + } + } } diff --git a/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseAddProductSkuViewModel.cs b/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseAddProductSkuViewModel.cs index c9cfc18e..f22baec9 100644 --- a/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseAddProductSkuViewModel.cs +++ b/BBWY.Client/ViewModels/BatchPurchase/BatchPurchaseAddProductSkuViewModel.cs @@ -1,18 +1,20 @@ using BBWY.Client.APIServices; using BBWY.Client.Models; using GalaSoft.MvvmLight.Command; -using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Text; +using System.Threading.Tasks; +using System.Windows; using System.Windows.Input; +using BBWY.Common.Extensions; namespace BBWY.Client.ViewModels { public class BatchPurchaseAddProductSkuViewModel : BaseVM { private BatchPurchaseService batchPurchaseService; + private bool isLoading; private string sku; private string spu; private Purchaser selectedPurchaser; @@ -21,8 +23,12 @@ namespace BBWY.Client.ViewModels private KVModel selectedPurchasePlatform; private KVModel defaultPurchasePlatform; + private bool allSelected; + public ICommand SearchCommand { get; set; } public ICommand FilterCommand { get; set; } + public ICommand SaveCommand { get; set; } + public string Sku { get => sku; set { Set(ref sku, value); } } public string Spu { get => spu; set { Set(ref spu, value); } } @@ -31,24 +37,26 @@ namespace BBWY.Client.ViewModels public IList PurchasePlatformList { get; set; } public Purchaser SelectedPurchaser { - get => selectedPurchaser; set - { - if (Set(ref selectedPurchaser, value)) - OnFilterChanged(); - } + get => selectedPurchaser; set { Set(ref selectedPurchaser, value); } } public KVModel SelectedPurchasePlatform { - get => selectedPurchasePlatform; set - { - if (Set(ref selectedPurchasePlatform, value)) - OnFilterChanged(); - } + get => selectedPurchasePlatform; set { Set(ref selectedPurchasePlatform, value); } } public IList SourceList { get; set; } public IList FilterList { get; set; } + public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } + + public bool AllSelected + { + get => allSelected; set + { + if (Set(ref allSelected, value)) + OnAllSelectedChanged(); + } + } public BatchPurchaseAddProductSkuViewModel(BatchPurchaseService batchPurchaseService) { @@ -66,17 +74,63 @@ namespace BBWY.Client.ViewModels SourceList = new List(); FilterList = new List(); - SelectedPurchaser = PurchaserList[0]; - SelectedPurchasePlatform = PurchasePlatformList[0]; SearchCommand = new RelayCommand(Search); FilterCommand = new RelayCommand(Filter); + SaveCommand = new RelayCommand(Save); + SelectedPurchaser = PurchaserList[0]; + SelectedPurchasePlatform = PurchasePlatformList[0]; + } + + private void Search() + { + IsLoading = true; + Task.Factory.StartNew(() => batchPurchaseService.GetProductSkuAndSchemeList(Sku, Spu)).ContinueWith(t => + { + IsLoading = false; + var response = t.Result; + if (!response.Success) + { + App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "提示")); + return; + } + SourceList.Clear(); + + App.Current.Dispatcher.Invoke(() => + { + PurchaserList.Clear(); + FilterList.Clear(); + + PurchaserList.Add(defaultPurchaser); + SelectedPurchaser = PurchaserList[0]; + SelectedPurchasePlatform = PurchasePlatformList[0]; + }); + + if (response.Data == null || response.Data.Count() == 0) + return; + var list = response.Data.Map>(); + + #region 提取采购商 + var purchaserList = list.Where(item => !string.IsNullOrEmpty(item.PurchaserId)) + .Select(item => new Purchaser() { Id = item.PurchaserId, Name = item.PurchaseName, Platform = item.PurchasePlatform.Value }) + .Distinct(new PurchaserComparer()); + #endregion + + App.Current.Dispatcher.Invoke(() => + { + foreach (var purchaser in purchaserList) + PurchaserList.Add(purchaser); + foreach (var item in list) + SourceList.Add(item); + Filter(); + }); + }); } - private void OnFilterChanged() + private void Filter() { + FilterList.Clear(); if (SourceList.Count() == 0) return; - FilterList.Clear(); var resultList = new List(); resultList.AddRange(SourceList); @@ -111,14 +165,14 @@ namespace BBWY.Client.ViewModels } } - private void Search() + private void Save() { } - private void Filter() - { - + private void OnAllSelectedChanged() + { + } } } diff --git a/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml b/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml index a1083ff4..abfc732f 100644 --- a/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml +++ b/BBWY.Client/Views/BatchPurchase/BatchPurchaseAddProductSku.xaml @@ -38,24 +38,117 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs b/BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs index 959b519e..484027d5 100644 --- a/BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs +++ b/BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs @@ -23,7 +23,7 @@ namespace BBWY.Server.Business /// public IList GetProductSkuAndSchemeList(SearchProductSkuAndSchemeRequest request) { - if (string.IsNullOrEmpty(request.Spu) || string.IsNullOrEmpty(request.Sku)) + if (string.IsNullOrEmpty(request.Spu) && string.IsNullOrEmpty(request.Sku)) throw new BusinessException("至少具备一个Sku或Spu条件"); var productSkuList = productBusiness.GetProductSkuList(new SearchProductSkuRequest()