|
@ -3,6 +3,7 @@ using BBWYB.Client.Models; |
|
|
using BBWYB.Client.Views.Order; |
|
|
using BBWYB.Client.Views.Order; |
|
|
using BBWYB.Client.Views.Purchase; |
|
|
using BBWYB.Client.Views.Purchase; |
|
|
using BBWYB.Common.Extensions; |
|
|
using BBWYB.Common.Extensions; |
|
|
|
|
|
using BBWYB.Common.Models; |
|
|
using CommunityToolkit.Mvvm.Input; |
|
|
using CommunityToolkit.Mvvm.Input; |
|
|
using CommunityToolkit.Mvvm.Messaging; |
|
|
using CommunityToolkit.Mvvm.Messaging; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
@ -21,22 +22,31 @@ namespace BBWYB.Client.ViewModels |
|
|
private Order order; |
|
|
private Order order; |
|
|
private bool freeChoice; |
|
|
private bool freeChoice; |
|
|
private bool isResponse = true; |
|
|
private bool isResponse = true; |
|
|
|
|
|
private bool isLoading; |
|
|
|
|
|
|
|
|
public IList<PurchaseSchemeSkuGroup> SkuGroup { get; set; } |
|
|
public IList<PurchaseSchemeSkuGroup> SkuGroup { get; set; } |
|
|
|
|
|
|
|
|
public ICommand ConfirmCommand { get; set; } |
|
|
public ICommand ConfirmCommand { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public ICommand RefreshCommand { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool FreeChoice { get => freeChoice; set { SetProperty(ref freeChoice, value); } } |
|
|
public bool FreeChoice { get => freeChoice; set { SetProperty(ref freeChoice, value); } } |
|
|
|
|
|
|
|
|
|
|
|
public bool IsLoading { get => isLoading; set { SetProperty(ref isLoading, value); } } |
|
|
|
|
|
|
|
|
public ChoosePurchaseSchemeViewModel(PurchaseService purchaseService, GlobalContext globalContext) |
|
|
public ChoosePurchaseSchemeViewModel(PurchaseService purchaseService, GlobalContext globalContext) |
|
|
{ |
|
|
{ |
|
|
this.purchaseService = purchaseService; |
|
|
this.purchaseService = purchaseService; |
|
|
this.globalContext = globalContext; |
|
|
this.globalContext = globalContext; |
|
|
this.SkuGroup = new ObservableCollection<PurchaseSchemeSkuGroup>(); |
|
|
this.SkuGroup = new ObservableCollection<PurchaseSchemeSkuGroup>(); |
|
|
ConfirmCommand = new RelayCommand(Confirm); |
|
|
ConfirmCommand = new RelayCommand(Confirm); |
|
|
|
|
|
RefreshCommand = new RelayCommand(Refresh); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected override void Load() |
|
|
protected override void Load() |
|
|
{ |
|
|
{ |
|
|
|
|
|
IsLoading = true; |
|
|
Task.Factory.StartNew(() => LoadScheme()); |
|
|
Task.Factory.StartNew(() => LoadScheme()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -49,6 +59,12 @@ namespace BBWYB.Client.ViewModels |
|
|
{ |
|
|
{ |
|
|
var skuIdList = order.ItemList.Select(osku => osku.SkuId).ToList(); |
|
|
var skuIdList = order.ItemList.Select(osku => osku.SkuId).ToList(); |
|
|
var response = purchaseService.GetPurchaseSchemeList(skuIdList, shopId: globalContext.User.Shop.ShopId); |
|
|
var response = purchaseService.GetPurchaseSchemeList(skuIdList, shopId: globalContext.User.Shop.ShopId); |
|
|
|
|
|
LoadScheme(response); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void LoadScheme(ApiResponse<IList<PurchaseSchemeResponse>> response) |
|
|
|
|
|
{ |
|
|
|
|
|
IsLoading = false; |
|
|
if (!response.Success) |
|
|
if (!response.Success) |
|
|
{ |
|
|
{ |
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "提示")); |
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "提示")); |
|
@ -114,5 +130,26 @@ namespace BBWYB.Client.ViewModels |
|
|
} |
|
|
} |
|
|
isResponse = true; |
|
|
isResponse = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override void Refresh() |
|
|
|
|
|
{ |
|
|
|
|
|
if (SkuGroup.Count() == 0) |
|
|
|
|
|
return; |
|
|
|
|
|
IsLoading = true; |
|
|
|
|
|
var schemeIdList = new List<long>(); |
|
|
|
|
|
foreach (var group in SkuGroup) |
|
|
|
|
|
{ |
|
|
|
|
|
schemeIdList.AddRange(group.SchemeList.Select(s => s.Id)); |
|
|
|
|
|
group.SchemeList.Clear(); |
|
|
|
|
|
} |
|
|
|
|
|
SkuGroup.Clear(); |
|
|
|
|
|
|
|
|
|
|
|
Task.Factory.StartNew(() => purchaseService.RefreshPurchaseScheme(schemeIdList)).ContinueWith(t => |
|
|
|
|
|
{ |
|
|
|
|
|
var response = t.Result; |
|
|
|
|
|
LoadScheme(response); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|