订单售后费用明细:重置后不再自动带日期

- 点“重置”或提交空日期时,不再回填近 7 天默认区间,日期框保持为空并做不限日期查询
- 首次进入页面仍保留近 7 天默认区间;导出文件名在无日期时显示“不限日期”
- 补充过滤归一化与页面渲染用例
This commit is contained in:
renshen 2026-10-06 18:12:16 +08:00
parent eda10bd740
commit 83e5108ce6
3 changed files with 65 additions and 3 deletions

View File

@ -68,10 +68,16 @@ class OrderDataPageData
{
$input ??= request()->query();
$shopNames = $this->shopNames($input['shop_name'] ?? $input['shop_names'] ?? null);
$from = $this->date($input['from'] ?? null);
$to = $this->date($input['to'] ?? null);
// 首次进入页面时给一个近 7 天的默认区间;点了“重置”或提交了空日期后,
// 明确不加日期条件(页面上的日期框保持为空),由用户自己决定下一步再看什么。
$cleared = ! empty($input['reset']) || array_key_exists('from', $input) || array_key_exists('to', $input);
return [
'from' => $this->date($input['from'] ?? null) ?: now()->subDays(6)->toDateString(),
'to' => $this->date($input['to'] ?? null) ?: now()->toDateString(),
'from' => $from !== '' ? $from : ($cleared ? '' : now()->subDays(6)->toDateString()),
'to' => $to !== '' ? $to : ($cleared ? '' : now()->toDateString()),
'order_no' => $this->text($input['order_no'] ?? null),
// shop_name 保留单值形态,兼容只认单值的调用方;多选统一用 shop_names。
'shop_name' => $shopNames[0] ?? '',

View File

@ -124,6 +124,9 @@
]);
$rows = $orderData['orderDataRows'];
$filters = $orderData['orderDataFilters'];
$exportRangeLabel = ($filters['from'] ?? '') === '' && ($filters['to'] ?? '') === ''
? '不限日期'
: (($filters['from'] ?: '不限') . '_' . ($filters['to'] ?: '不限'));
$status = data_get($orderData, 'orderDataStatus.X-Caiwu-Data-Status');
$orderDataError = $orderData['orderDataError'];
$afterSalesWorkOrders = $orderData['afterSalesWorkOrders'] ?? [
@ -396,6 +399,7 @@
'section' => $section['slug'],
'page' => $page['slug'],
'tab' => $activeTab['slug'] ?? null,
'reset' => 1,
]) }}" class="upstream-data-button">
<span class="material-icons-outlined" aria-hidden="true">refresh</span>
<span>重置</span>
@ -405,7 +409,7 @@
id="order-data-after-sales-export-button"
data-export-contract="order-data.after-sales.current-page-export"
data-export-table="order-data-after-sales-table"
data-export-filename="订单售后费用明细_{{ $filters['from'] ?? '开始' }}_{{ $filters['to'] ?? '结束' }}_第{{ $rows?->currentPage() ?? 1 }}页.csv"
data-export-filename="订单售后费用明细_{{ $exportRangeLabel }}_第{{ $rows?->currentPage() ?? 1 }}页.csv"
@class(['upstream-data-button', 'is-disabled' => !$rows || $rows->isEmpty()])
@if (!$rows || $rows->isEmpty()) disabled="disabled" aria-disabled="true" @endif
aria-label="导出当前页"

View File

@ -97,6 +97,58 @@ class OrderDataPagesUpstreamTest extends FeatureTestCase
->assertSeeText('ORDER-MULTI-1');
}
public function test_after_sales_filter_normalization_keeps_defaults_and_clears_on_reset(): void
{
$data = app(\Modules\EcommerceFinance\View\OrderDataPageData::class);
// 首次进入(没有任何参数)仍给近 7 天的默认区间。
$default = $data->afterSalesFilters([]);
$this->assertSame(now()->subDays(6)->toDateString(), $default['from']);
$this->assertSame(now()->toDateString(), $default['to']);
// 点“重置”后不再带日期条件,页面上日期框保持为空。
$cleared = $data->afterSalesFilters(['reset' => 1]);
$this->assertSame('', $cleared['from']);
$this->assertSame('', $cleared['to']);
$blank = $data->afterSalesFilters(['from' => '', 'to' => '']);
$this->assertSame('', $blank['from']);
$this->assertSame('', $blank['to']);
$explicit = $data->afterSalesFilters(['from' => '2026-08-01', 'to' => '2026-08-31']);
$this->assertSame('2026-08-01', $explicit['from']);
$this->assertSame('2026-08-31', $explicit['to']);
}
public function test_after_sales_reset_renders_empty_date_inputs(): void
{
$this->allowOrderDataPages();
$mirror = Mockery::mock(OrderDataMirrorRepository::class);
$mirror->shouldReceive('ready')->zeroOrMoreTimes()->andReturnTrue();
$mirror->shouldReceive('shopNames')->zeroOrMoreTimes()->andReturn([]);
$mirror->shouldReceive('afterSales')->once()
->with(
Mockery::on(static fn (array $filters): bool => $filters['from'] === '' && $filters['to'] === ''),
1,
25,
)
->andReturn(['rows' => []]);
$this->app->instance(OrderDataMirrorRepository::class, $mirror);
$factory = Mockery::mock(UpstreamQueryCacheFactory::class);
$factory->shouldNotReceive('forSource');
$this->app->instance(UpstreamQueryCacheFactory::class, $factory);
$this->loginAs()->get(route('business.pages.show', [
'section' => 'order-data',
'page' => 'raw-data',
'tab' => 'after-sales-expenses',
'reset' => 1,
]))
->assertOk()
->assertSee('name="from" type="date" value=""', false)
->assertSee('name="to" type="date" value=""', false);
}
public function test_order_data_pages_render_cached_upstream_rows_and_filters(): void
{
$this->allowOrderDataPages();