13 changed files with 684 additions and 4 deletions
@ -0,0 +1,46 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace BBWY.Client.Models |
|||
{ |
|||
public class ExportOrderSkuResponse |
|||
{ |
|||
public string OrderId { get; set; } |
|||
|
|||
public DateTime? StartTime { get; set; } |
|||
|
|||
public long ShopId { get; set; } |
|||
|
|||
public string ShopName { get; set; } |
|||
|
|||
public string Spu { get; set; } |
|||
|
|||
public string Sku { get; set; } |
|||
|
|||
public StorageType? StorageType { get; set; } |
|||
|
|||
public decimal? PurchaseSkuAmount { get; set; } |
|||
|
|||
public decimal? PurchaseFreight { get; set; } |
|||
|
|||
public decimal? PurchaseAmount { get { return PurchaseSkuAmount + PurchaseFreight; } } |
|||
|
|||
public decimal? SkuPrice { get; set; } |
|||
|
|||
public int? ItemTotal { get; set; } |
|||
|
|||
public string SpuName { get; set; } |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"{StartTime},{ShopName},{OrderId},{Spu},{Sku},{StorageType},{PurchaseAmount},{SkuPrice},{ItemTotal},{SpuName}"; |
|||
} |
|||
} |
|||
|
|||
public class ExportOrderSkuListResponse |
|||
{ |
|||
public long Count { get; set; } |
|||
|
|||
public IList<ExportOrderSkuResponse> ItemList { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,223 @@ |
|||
using BBWY.Client.APIServices; |
|||
using BBWY.Client.Models; |
|||
using BBWY.Common.Models; |
|||
using BBWY.Controls; |
|||
using GalaSoft.MvvmLight.Command; |
|||
using Microsoft.Win32; |
|||
using Newtonsoft.Json; |
|||
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; |
|||
|
|||
namespace BBWY.Client.ViewModels |
|||
{ |
|||
public class ExportOrderSkuViewModel : BaseVM, IDenpendency |
|||
{ |
|||
private DateTime startDate; |
|||
private DateTime endDate; |
|||
|
|||
private GlobalContext globalContext; |
|||
private KVModel selectedPlatform; |
|||
private int pageIndex; |
|||
private int pageSize; |
|||
private long totalCount; |
|||
private bool isLoading; |
|||
private bool isShowAll_Shop; |
|||
private bool isShowAll_Department; |
|||
|
|||
private OrderService orderService; |
|||
|
|||
public IList<Department> DepartmentList { get; set; } |
|||
|
|||
public IList<Shop> ShopList { get; set; } |
|||
|
|||
public IList<KVModel> PlatformList { get; set; } |
|||
|
|||
public IList<ExportOrderSkuResponse> ExportSkuList { get; set; } |
|||
|
|||
public DateTime StartDate { get => startDate; set { Set(ref startDate, value); } } |
|||
public DateTime EndDate { get => endDate; set { Set(ref endDate, value); } } |
|||
|
|||
public KVModel SelectedPlatform { get => selectedPlatform; set { Set(ref selectedPlatform, value); } } |
|||
|
|||
public ICommand SearchCommand { get; set; } |
|||
|
|||
public ICommand ExportCommand { get; set; } |
|||
|
|||
public ICommand OrderPageIndexChangedCommand { get; set; } |
|||
|
|||
public int PageIndex { get => pageIndex; set { Set(ref pageIndex, value); } } |
|||
public int PageSize { get => pageSize; set { Set(ref pageSize, value); } } |
|||
|
|||
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } |
|||
|
|||
public long TotalCount { get => totalCount; set { Set(ref totalCount, value); } } |
|||
|
|||
public bool IsShowAll_Shop { get => isShowAll_Shop; set { Set(ref isShowAll_Shop, value); } } |
|||
|
|||
public bool IsShowAll_Department { get => isShowAll_Department; set { Set(ref isShowAll_Department, value); } } |
|||
|
|||
public ExportOrderSkuViewModel(GlobalContext globalContext, OrderService orderService) |
|||
{ |
|||
this.orderService = orderService; |
|||
|
|||
DepartmentList = new ObservableCollection<Department>(); |
|||
ShopList = new ObservableCollection<Shop>(); |
|||
PlatformList = new ObservableCollection<KVModel>(); |
|||
ExportSkuList = new ObservableCollection<ExportOrderSkuResponse>(); |
|||
SearchCommand = new RelayCommand(Search); |
|||
ExportCommand = new RelayCommand(Export); |
|||
OrderPageIndexChangedCommand = new RelayCommand<PageArgs>(p => |
|||
{ |
|||
//this.PageIndex = p.PageIndex;
|
|||
Task.Factory.StartNew(() => SearchCore(p.PageIndex)); |
|||
}); |
|||
|
|||
var platformEnumValues = Enum.GetValues(typeof(Platform)); |
|||
foreach (var ev in platformEnumValues) |
|||
{ |
|||
var p = (Platform)ev; |
|||
PlatformList.Add(new KVModel() |
|||
{ |
|||
Key = p.ToString(), |
|||
Value = ((int)p).ToString() |
|||
}); |
|||
} |
|||
IsShowAll_Department = IsShowAll_Shop = true; |
|||
this.globalContext = globalContext; |
|||
LoadDepartment(); |
|||
StartDate = DateTime.Now.Date; |
|||
EndDate = DateTime.Now.Date; |
|||
PageIndex = 1; |
|||
PageSize = 20; |
|||
} |
|||
|
|||
private void LoadDepartment() |
|||
{ |
|||
var dlist = JsonConvert.DeserializeObject<IList<Department>>(JsonConvert.SerializeObject(globalContext.User.DepartmentList)); |
|||
foreach (var d in dlist) |
|||
{ |
|||
d.IsSelected = false; |
|||
DepartmentList.Add(d); |
|||
d.OnIsSelectedChanged = OnDeparmentSelectionChanged; |
|||
} |
|||
ShopList.Clear(); |
|||
} |
|||
|
|||
private void OnDeparmentSelectionChanged() |
|||
{ |
|||
ShopList.Clear(); |
|||
foreach (var d in DepartmentList) |
|||
{ |
|||
if (!d.IsSelected) |
|||
continue; |
|||
foreach (var s in d.ShopList) |
|||
{ |
|||
s.OnIsSelectedChanged = OnShopSelectionChanged; |
|||
s.IsSelected = false; |
|||
ShopList.Add(s); |
|||
} |
|||
} |
|||
IsShowAll_Department = !DepartmentList.Any(d => d.IsSelected); |
|||
} |
|||
|
|||
private void OnShopSelectionChanged() |
|||
{ |
|||
IsShowAll_Shop = !ShopList.Any(s => s.IsSelected); |
|||
} |
|||
|
|||
private void Search() |
|||
{ |
|||
PageIndex = 1; |
|||
Task.Factory.StartNew(() => SearchCore(PageIndex)); |
|||
} |
|||
|
|||
private void SearchCore(int pageIndex) |
|||
{ |
|||
IsLoading = true; |
|||
int? purchasePlatform = null; |
|||
if (SelectedPlatform != null) |
|||
purchasePlatform = int.Parse(SelectedPlatform.Value); |
|||
List<long> shopIds = new List<long>(); |
|||
if (ShopList.Count() > 0) |
|||
{ |
|||
if (ShopList.Any(s => s.IsSelected)) |
|||
shopIds.AddRange(ShopList.Where(s => s.IsSelected).Select(s => s.ShopId)); |
|||
else |
|||
shopIds.AddRange(ShopList.Select(s => s.ShopId)); |
|||
} |
|||
var response = orderService.QueryOrderSkuList(StartDate, |
|||
EndDate, |
|||
purchasePlatform, |
|||
shopIds, |
|||
pageIndex, |
|||
PageSize); |
|||
IsLoading = false; |
|||
TotalCount = 0; |
|||
if (!response.Success) |
|||
{ |
|||
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "提示")); |
|||
return; |
|||
} |
|||
TotalCount = response.Data.Count; |
|||
App.Current.Dispatcher.Invoke(() => |
|||
{ |
|||
ExportSkuList.Clear(); |
|||
foreach (var item in response.Data.ItemList) |
|||
ExportSkuList.Add(item); |
|||
}); |
|||
|
|||
} |
|||
|
|||
private void Export() |
|||
{ |
|||
var sfd = new SaveFileDialog() { Filter = "csv files(*.csv)|*.csv" }; |
|||
if (sfd.ShowDialog() != true) |
|||
return; |
|||
|
|||
var ssaveFileName = sfd.FileName; |
|||
|
|||
int? purchasePlatform = null; |
|||
if (SelectedPlatform != null) |
|||
purchasePlatform = int.Parse(SelectedPlatform.Value); |
|||
IsLoading = true; |
|||
Task.Factory.StartNew(() => orderService.ExportOrderSkuList(StartDate, |
|||
EndDate, |
|||
purchasePlatform, |
|||
ShopList.Where(s => s.IsSelected).Select(s => s.ShopId).ToList())).ContinueWith(t => |
|||
{ |
|||
var response = t.Result; |
|||
|
|||
if (!response.Success) |
|||
{ |
|||
IsLoading = false; |
|||
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "提示")); |
|||
return; |
|||
} |
|||
|
|||
try |
|||
{ |
|||
var list = response.Data.Select(x => x.ToString()).ToList(); |
|||
list.Insert(0, "开始时间,店铺名称,订单Id,SPU,SKU,仓储类型,采购成本(货款+运费),单价,数量,商品标题"); |
|||
System.IO.File.WriteAllLines(ssaveFileName, list, Encoding.UTF8); |
|||
App.Current.Dispatcher.Invoke(() => MessageBox.Show("导出完成", "导出")); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "导出")); |
|||
return; |
|||
} |
|||
finally |
|||
{ |
|||
IsLoading = false; |
|||
} |
|||
}); |
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,166 @@ |
|||
<Page x:Class="BBWY.Client.Views.Order.ExportOrderSkuView" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:c="clr-namespace:BBWY.Controls;assembly=BBWY.Controls" |
|||
xmlns:hc="https://handyorg.github.io/handycontrol" |
|||
xmlns:sys="clr-namespace:System;assembly=mscorlib" |
|||
xmlns:cmodel="clr-namespace:BBWY.Client.Models" |
|||
xmlns:local="clr-namespace:BBWY.Client.Views.Order" |
|||
xmlns:b="http://schemas.microsoft.com/xaml/behaviors" |
|||
mc:Ignorable="d" |
|||
d:DesignHeight="769" d:DesignWidth="1024" |
|||
DataContext="{Binding ExportOrderSkuVM,Source={StaticResource Locator}}" |
|||
Title="ExportOrderSkuView" |
|||
xmlns:converter="clr-namespace:HandyControl.Tools.Converter;assembly=HandyControl" |
|||
xmlns:interactivity="clr-namespace:HandyControl.Interactivity;assembly=HandyControl" |
|||
xmlns:ex="clr-namespace:HandyControl.Tools.Extension;assembly=HandyControl" |
|||
xmlns:langs="clr-namespace:HandyControl.Properties.Langs;assembly=HandyControl"> |
|||
<Page.Resources> |
|||
|
|||
</Page.Resources> |
|||
<Grid> |
|||
<c:RoundWaitProgress Play="{Binding IsLoading}" Panel.ZIndex="999"/> |
|||
<Grid Margin="5,0"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="40"/> |
|||
<RowDefinition Height="5"/> |
|||
<RowDefinition /> |
|||
<RowDefinition Height="5"/> |
|||
<RowDefinition Height="30"/> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<Grid Background="{StaticResource Border.Background}"> |
|||
<Grid.Resources> |
|||
<ResourceDictionary> |
|||
<ResourceDictionary.MergedDictionaries> |
|||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/> |
|||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/> |
|||
</ResourceDictionary.MergedDictionaries> |
|||
</ResourceDictionary> |
|||
</Grid.Resources> |
|||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5,0"> |
|||
<Grid> |
|||
<hc:CheckComboBox IsTextSearchEnabled="True" ItemsSource="{Binding DepartmentList}" |
|||
ShowClearButton="True" |
|||
MinWidth="150" |
|||
Height="30"> |
|||
<hc:CheckComboBox.ItemTemplate> |
|||
<DataTemplate> |
|||
<StackPanel Orientation="Horizontal" Margin="5,2.5"> |
|||
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/> |
|||
</StackPanel> |
|||
</DataTemplate> |
|||
</hc:CheckComboBox.ItemTemplate> |
|||
<hc:CheckComboBox.ItemContainerStyle> |
|||
<Style TargetType="{x:Type hc:CheckComboBoxItem}" BasedOn="{StaticResource NoBgListBoxItemStyle}"> |
|||
<Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/> |
|||
</Style> |
|||
</hc:CheckComboBox.ItemContainerStyle> |
|||
</hc:CheckComboBox> |
|||
<TextBlock Text="全部" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0" |
|||
Visibility="{Binding IsShowAll_Department,ConverterParameter=true:Visible:Collapsed,Converter={StaticResource objConverter}}"/> |
|||
</Grid> |
|||
|
|||
<Grid> |
|||
<hc:CheckComboBox IsTextSearchEnabled="True" ItemsSource="{Binding ShopList}" |
|||
ShowClearButton="True" |
|||
MinWidth="150" |
|||
Margin="5,0,0,0"> |
|||
<hc:CheckComboBox.ItemTemplate> |
|||
<DataTemplate> |
|||
<StackPanel Orientation="Horizontal" Margin="5,2.5"> |
|||
<CheckBox Content="{Binding ShopName}" IsChecked="{Binding IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/> |
|||
</StackPanel> |
|||
</DataTemplate> |
|||
</hc:CheckComboBox.ItemTemplate> |
|||
<hc:CheckComboBox.ItemContainerStyle> |
|||
<Style TargetType="{x:Type hc:CheckComboBoxItem}" BasedOn="{StaticResource NoBgListBoxItemStyle}"> |
|||
<Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/> |
|||
</Style> |
|||
</hc:CheckComboBox.ItemContainerStyle> |
|||
</hc:CheckComboBox> |
|||
<TextBlock Text="全部" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0" |
|||
Visibility="{Binding IsShowAll_Shop,ConverterParameter=true:Visible:Collapsed,Converter={StaticResource objConverter}}"/> |
|||
</Grid> |
|||
|
|||
<!--<hc:CheckComboBox IsTextSearchEnabled="True" ItemsSource="{Binding PlatformList}" |
|||
ShowClearButton="True" |
|||
MinWidth="150" |
|||
Margin="5,0,0,0" |
|||
SelectionMode="Single" |
|||
SelectedItem="{Binding SelectedPlatform,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" |
|||
DisplayMemberPath="Key"> |
|||
</hc:CheckComboBox>--> |
|||
|
|||
<DatePicker Height="30" Margin="5,0,0,0" SelectedDate="{Binding StartDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/> |
|||
<DatePicker Height="30" Margin="5,0,0,0" SelectedDate="{Binding EndDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/> |
|||
|
|||
<c:BButton Content="查询" Margin="5,0,0,0" Width="80" Command="{Binding SearchCommand}"/> |
|||
<c:BButton Content="导出" Width="80" Margin="5,0,0,0" Command="{Binding ExportCommand}" Background="#02A7F0"/> |
|||
</StackPanel> |
|||
</Grid> |
|||
|
|||
<DataGrid Grid.Row="2" |
|||
ItemsSource="{Binding ExportSkuList}" |
|||
BorderThickness="1,1,0,0" |
|||
BorderBrush="{StaticResource Border.Brush}" |
|||
VirtualizingPanel.IsVirtualizing="True"> |
|||
<DataGrid.Columns> |
|||
<DataGridTextColumn Binding="{Binding StartTime,StringFormat=yyyy-MM-dd HH:mm:ss}" Header="订单日期" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="140"/> |
|||
<DataGridTextColumn Binding="{Binding ShopName}" Header="店铺名称" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="150"/> |
|||
<DataGridTextColumn Binding="{Binding OrderId}" Header="订单号" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="110"/> |
|||
<DataGridTextColumn Binding="{Binding Spu}" Header="SPU" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="120"/> |
|||
<DataGridTextColumn Binding="{Binding Sku}" Header="SKU" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="120"/> |
|||
<DataGridTextColumn Binding="{Binding StorageType}" Header="仓储类型" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="80"/> |
|||
<DataGridTextColumn Binding="{Binding PurchaseAmount,Mode=OneWay}" Header="采购成本" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="80"/> |
|||
<DataGridTextColumn Binding="{Binding SkuPrice}" Header="单价" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="80"/> |
|||
<DataGridTextColumn Binding="{Binding ItemTotal}" Header="数量" |
|||
ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="50"/> |
|||
<DataGridTextColumn Binding="{Binding SpuName}" Header="商品标题" ElementStyle="{StaticResource middleTextBlock}" |
|||
HeaderStyle="{StaticResource ColumnHeaderStyle_Center}" |
|||
Width="*"/> |
|||
</DataGrid.Columns> |
|||
</DataGrid> |
|||
|
|||
<c:PageControl PageIndex="{Binding PageIndex}" |
|||
PageSize="{Binding PageSize}" |
|||
RecordCount="{Binding TotalCount}" |
|||
Grid.Row="4" |
|||
HorizontalAlignment="Left"> |
|||
<b:Interaction.Triggers> |
|||
<b:EventTrigger EventName="OnPageIndexChanged"> |
|||
<b:InvokeCommandAction Command="{Binding OrderPageIndexChangedCommand}" PassEventArgsToCommand="True"/> |
|||
</b:EventTrigger> |
|||
</b:Interaction.Triggers> |
|||
</c:PageControl> |
|||
</Grid> |
|||
</Grid> |
|||
</Page> |
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Windows; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Data; |
|||
using System.Windows.Documents; |
|||
using System.Windows.Input; |
|||
using System.Windows.Media; |
|||
using System.Windows.Media.Imaging; |
|||
using System.Windows.Navigation; |
|||
using System.Windows.Shapes; |
|||
|
|||
namespace BBWY.Client.Views.Order |
|||
{ |
|||
/// <summary>
|
|||
/// ExportOrderSkuView.xaml 的交互逻辑
|
|||
/// </summary>
|
|||
public partial class ExportOrderSkuView : Page |
|||
{ |
|||
public ExportOrderSkuView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace BBWY.Server.Model.Dto |
|||
{ |
|||
public class QueryOrderSkuRequest : ExportOrderSkuRequest |
|||
{ |
|||
public int PageIndex { get; set; } |
|||
|
|||
public int PageSize { get; set; } |
|||
} |
|||
|
|||
public class ExportOrderSkuRequest |
|||
{ |
|||
public List<long> ShopIds { get; set; } |
|||
|
|||
public Enums.Platform? PurchasePlatform { get; set; } |
|||
|
|||
public DateTime StartTime { get; set; } |
|||
|
|||
public DateTime EndTime { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace BBWY.Server.Model.Dto |
|||
{ |
|||
public class ExportOrderSkuResponse |
|||
{ |
|||
public string OrderId { get; set; } |
|||
|
|||
public DateTime? StartTime { get; set; } |
|||
|
|||
public long ShopId { get; set; } |
|||
|
|||
public string ShopName { get; set; } |
|||
|
|||
public string Spu { get; set; } |
|||
|
|||
public string Sku { get; set; } |
|||
|
|||
public Enums.StorageType? StorageType { get; set; } |
|||
|
|||
public decimal? PurchaseSkuAmount { get; set; } |
|||
|
|||
public decimal? PurchaseFreight { get; set; } |
|||
|
|||
public decimal? SkuPrice { get; set; } |
|||
|
|||
public int? ItemTotal { get; set; } |
|||
|
|||
public string SpuName { get; set; } |
|||
} |
|||
|
|||
public class ExportOrderSkuListResponse |
|||
{ |
|||
public long Count { get; set; } |
|||
|
|||
public IList<ExportOrderSkuResponse> ItemList { get; set; } |
|||
} |
|||
} |
Loading…
Reference in new issue