统计页面 修改店铺选择,增加店铺搜索Combobox

This commit is contained in:
chfei committed 2026-08-07 11:25:19 +08:00
1 parent b6b72e6bc3
commit f12a7f14ea
16 files changed
+1801 -41

No files matched your search

@@ -15,8 +15,8 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Models
/// <summary>结束时间</summary>
public DateTime EndDate { get; set; }
/// <summary>店铺 shop_id(B.shop_id),空/Null 表示全部店铺</summary>
public string ShopKey { get; set; }
/// <summary>选中的店铺 app_key 列表;空/Null 表示全部店铺</summary>
public List<string> ShopKeys { get; set; }
}
/// <summary>
@@ -2,10 +2,12 @@
x:Class="_29WxOrderWpf.Ctrls.Statistics.RevenueStatisticsSearchBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:_29WxOrderWpf.Ctrls.Commons"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:_29WxOrderWpf.Ctrls.Statistics.ViewModels"
d:DataContext="{d:DesignInstance Type=vm:ShopRevenueStatisticsViewModel,IsDesignTimeCreatable=True}"
d:DataContext="{d:DesignInstance Type=vm:ShopRevenueStatisticsViewModel,
IsDesignTimeCreatable=True}"
mc:Ignorable="d">
<UserControl.Resources>
<!-- 日期只允许从日历选择,禁止手工输入 -->
@@ -42,21 +44,23 @@
FontSize="14"
Foreground="#666666"
Text="时间" />
<ComboBox IsEnabled="False"
<ComboBox
Width="110"
Height="32"
VerticalContentAlignment="Center"
DisplayMemberPath="Text"
IsReadOnly="True"
BorderThickness="1"
ItemsSource="{Binding TimeRangeOptions}"
SelectedItem="{Binding SelectedTimeRange, Mode=TwoWay}"
Style="{StaticResource BaseComboBoxStyle}" />
Style="{StaticResource RoundedComboBox}" />
<TextBlock
Margin="14,0,6,0"
VerticalAlignment="Center"
FontSize="14"
Foreground="#666666"
Text="日期" />
<DatePicker
<DatePicker BorderBrush="{StaticResource pageColorBrush}"
Height="32"
VerticalContentAlignment="Center"
SelectedDate="{Binding StartDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
@@ -66,7 +70,7 @@
FontSize="14"
Foreground="#666666"
Text="~" />
<DatePicker
<DatePicker BorderBrush="{StaticResource pageColorBrush}"
Height="32"
VerticalContentAlignment="Center"
SelectedDate="{Binding EndDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
@@ -76,14 +80,21 @@
FontSize="14"
Foreground="#666666"
Text="店铺" />
<ComboBox IsEnabled="False"
<c:ShopFilterComboBox
Width="130"
Height="32"
DisplayMemberPath="ShopName"
IsGrouped="True"
ItemsSource="{Binding ShopOptions}"
SelectedItems="{Binding SelectedShops}" />
<!--<ComboBox IsEnabled="False"
Width="130"
Height="32"
VerticalContentAlignment="Center"
DisplayMemberPath="ShopName"
ItemsSource="{Binding ShopOptions}"
SelectedItem="{Binding SelectedShop, Mode=TwoWay}"
Style="{StaticResource BaseComboBoxStyle}" />
Style="{StaticResource BaseComboBoxStyle}" />-->
<Button
Height="32"
Margin="18,0,0,0"
@@ -431,8 +431,8 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
}
}
// 3. 按天从缓存拼装完整范围,再按所选店铺过滤(ShopKey 为空 = 全部店铺)
return FilterByShop(GetCachedRows(startDay, endDay), query.ShopKey);
// 3. 按天从缓存拼装完整范围,再按所选店铺过滤(ShopKeys 为空 = 全部店铺)
return FilterByShop(GetCachedRows(startDay, endDay), query.ShopKeys);
}
/// <summary>
@@ -477,21 +477,24 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
return result;
}
/// <summary>按所选店铺过滤明细:ShopKey 为空返回全部;否则按店铺名(ShopName)精确匹配。</summary>
private static List<ShopRevenueStatisticsRow> FilterByShop(List<ShopRevenueStatisticsRow> rows, string shopKey)
/// <summary>按所选店铺过滤明细:ShopKeys 为空/Null 返回全部;否则按店铺名(ShopName)精确匹配。</summary>
private static List<ShopRevenueStatisticsRow> FilterByShop(List<ShopRevenueStatisticsRow> rows, List<string> shopKeys)
{
if (rows == null)
return new List<ShopRevenueStatisticsRow>();
if (string.IsNullOrEmpty(shopKey))
if (shopKeys == null || shopKeys.Count == 0)
return new List<ShopRevenueStatisticsRow>(rows);
var shop = GetShopOptions().FirstOrDefault(a => a.AppKey == shopKey);
if (shop == null || string.IsNullOrEmpty(shop.ShopName))
var shops = GetShopOptions()
.Where(a => shopKeys.Contains(a.AppKey))
.Where(a => !string.IsNullOrEmpty(a.ShopName))
.ToList();
if (shops.Count == 0)
return new List<ShopRevenueStatisticsRow>();
return rows
.Where(r => string.Equals(r.ShopName, shop.ShopName, StringComparison.OrdinalIgnoreCase))
.Where(r => shops.Any(s => string.Equals(r.ShopName, s.ShopName, StringComparison.OrdinalIgnoreCase)))
.ToList();
}
@@ -20,7 +20,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
public class PeriodRevenueStatisticsViewModel : PropertyNotifyObject
{
/// <summary>每页行数</summary>
private const int PageSize = 20;
private const int PageSize = 50;
private readonly IShopRevenueStatisticsService _service;
private readonly PeriodStatisticType _periodType;
@@ -29,7 +29,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
private readonly DelegateCommand _nextPageCommand;
private readonly DelegateCommand _lastPageCommand;
private ShopOption _selectedShop;
private ObservableCollection<ShopOption> _selectedShops;
private ShopRevenueSummary _summary;
private ObservableCollection<ShopPeriodStatisticsItem> _statistics;
private List<ShopPeriodStatisticsItem> _allItems = new List<ShopPeriodStatisticsItem>();
@@ -192,17 +192,17 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
set { this.SetValue(x => x.EndDate, value); }
}
/// <summary>店铺选项(含“全部店铺”)</summary>
/// <summary>店铺选项(“全部店铺”由多选控件“全部商铺”表示)</summary>
public ObservableCollection<ShopOption> ShopOptions { get; }
/// <summary>选中的店铺</summary>
public ShopOption SelectedShop
/// <summary>选中的店铺(多选,绑定 ShopFilterComboBox.SelectedItems)</summary>
public ObservableCollection<ShopOption> SelectedShops
{
get { return _selectedShop; }
get { return _selectedShops; }
set
{
_selectedShop = value;
OnPropertyChanged(nameof(SelectedShop));
_selectedShops = value;
OnPropertyChanged(nameof(SelectedShops));
}
}
@@ -378,12 +378,11 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
{
try
{
// 店铺选项
ShopOptions.Add(new ShopOption { AppKey = string.Empty, ShopName = "全部店铺" });
// 店铺选项(全部店铺由多选控件“全部商铺”表示,不再额外加入“全部店铺”项)
var shops = await _service.GetShopOptionsAsync();
foreach (var shop in shops)
ShopOptions.Add(shop);
SelectedShop = ShopOptions.FirstOrDefault();
SelectedShops = new ObservableCollection<ShopOption>(ShopOptions);
// 默认时间范围
SelectedTimeRange = TimeRangeOptions.FirstOrDefault(t => t.Value == GetDefaultTimeRangeValue(_periodType));
@@ -477,6 +476,23 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
}
}
/// <summary>根据选中店铺生成查询店铺 key 列表:未选/全选/选中“全部店铺”时返回空列表(表示全部店铺)</summary>
private List<string> BuildSelectedShopKeys()
{
var selected = SelectedShops;
if (selected == null || selected.Count == 0)
return new List<string>();
var keys = selected.Select(s => s == null ? string.Empty : s.AppKey).ToList();
if (keys.Any(string.IsNullOrEmpty))
return new List<string>();
if (selected.Count >= ShopOptions.Count)
return new List<string>();
return keys;
}
/// <summary>执行查询,刷新周期统计表格并回到第一页</summary>
private async Task LoadAsync()
{
@@ -494,7 +510,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
{
StartDate = StartDate,
EndDate = EndDate,
ShopKey = SelectedShop == null ? string.Empty : SelectedShop.AppKey,
ShopKeys = BuildSelectedShopKeys(),
};
var table = await _service.GetPeriodStatisticsAsync(query, _periodType);
@@ -518,7 +534,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
/// <summary>重置查询条件并重新加载</summary>
private async void Reset()
{
SelectedShop = ShopOptions.FirstOrDefault();
SelectedShops = new ObservableCollection<ShopOption>(ShopOptions);
SelectedTimeRange = TimeRangeOptions.FirstOrDefault(t => t.Value == GetDefaultTimeRangeValue(_periodType));
ApplyTimeRange();
await LoadAsync();
@@ -25,7 +25,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
private ObservableCollection<RevenueTrendPoint> _trendData;
private ObservableCollection<ShopSalesProportionItem> _shopProportionData;
private ObservableCollection<ShopStatisticsItem> _shopStatistics;
private ShopOption _selectedShop;
private ObservableCollection<ShopOption> _selectedShops;
private string _selectedPlatform;
public ShopRevenueStatisticsViewModel()
@@ -92,17 +92,17 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
set { this.SetValue(x => x.EndDate, value); }
}
/// <summary>店铺选项(含“全部店铺”)</summary>
/// <summary>店铺选项(“全部店铺”由多选控件“全部商铺”表示)</summary>
public ObservableCollection<ShopOption> ShopOptions { get; }
/// <summary>选中的店铺</summary>
public ShopOption SelectedShop
public ObservableCollection<ShopOption> SelectedShops
{
get { return _selectedShop; }
get { return _selectedShops; }
set
{
_selectedShop = value;
OnPropertyChanged(nameof(SelectedShop));
_selectedShops = value;
OnPropertyChanged(nameof(SelectedShops));
}
}
@@ -179,12 +179,11 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
{
try
{
// 店铺选项
ShopOptions.Add(new ShopOption { AppKey = string.Empty, ShopName = "全部店铺" });
// 店铺选项(全部店铺由多选控件“全部商铺”表示,不再额外加入“全部店铺”项)
var shops = await _service.GetShopOptionsAsync();
foreach (var shop in shops)
ShopOptions.Add(shop);
SelectedShop = ShopOptions.FirstOrDefault();
SelectedShops = new ObservableCollection<ShopOption>(ShopOptions);
// 默认时间范围:本月
SelectedTimeRange = TimeRangeOptions.FirstOrDefault(t => t.Value == "month");
@@ -233,6 +232,23 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
}
}
/// <summary>根据选中店铺生成查询店铺 key 列表:未选/全选/选中“全部店铺”时返回空列表(表示全部店铺)</summary>
private List<string> BuildSelectedShopKeys()
{
var selected = SelectedShops;
if (selected == null || selected.Count == 0)
return new List<string>();
var keys = selected.Select(s => s == null ? string.Empty : s.AppKey).ToList();
if (keys.Any(string.IsNullOrEmpty))
return new List<string>();
if (selected.Count >= ShopOptions.Count)
return new List<string>();
return keys;
}
/// <summary>执行查询,刷新页面所有统计数据</summary>
private async Task LoadAsync()
{
@@ -250,7 +266,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
{
StartDate = StartDate,
EndDate = EndDate,
ShopKey = SelectedShop == null ? string.Empty : SelectedShop.AppKey,
ShopKeys = BuildSelectedShopKeys(),
};
Summary = await _service.GetSummaryAsync(query);
@@ -277,7 +293,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
/// <summary>重置查询条件并重新加载</summary>
private async void Reset()
{
SelectedShop = ShopOptions.FirstOrDefault();
SelectedShops = new ObservableCollection<ShopOption>(ShopOptions);
SelectedTimeRange = TimeRangeOptions.FirstOrDefault(t => t.Value == "month");
ApplyTimeRange();
await LoadAsync();