Skip to content

Commit

Permalink
refactor(filament-order):重构订单发货页面
Browse files Browse the repository at this point in the history
- 更新了订单发货页面的布局和功能- 添加了卖家备注功能
- 优化了订单信息的显示- 改进了发货表单的交互
  • Loading branch information
liushoukun committed Oct 23, 2024
1 parent 9a92066 commit f3fe909
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<x-filament-panels::page>
@if ($this->hasInfolist())
{{ $this->infolist }}
@endif

@foreach($forms as $form)
<x-filament-panels::form
:wire:key="$this->getId() . '.forms.'.$form"
:wire:submit="$form.'Submit'"
>
{{ $this->{$form} }}

<x-filament-panels::form.actions
:actions="$this->getCachedFormActions()"
:full-width="$this->hasFullWidthFormActions()"
/>
</x-filament-panels::form>


@endforeach

<x-filament-panels::form
:wire:key="$this->getId() . '.forms.dummy'"
wire:submit="dummy"
>
{{ $this->form }}

<x-filament-panels::form.actions
:actions="$this->getCachedFormActions()"
:full-width="$this->hasFullWidthFormActions()"
/>
</x-filament-panels::form>


</x-filament-panels::page>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function getModelLabel() : string
public static function infolist(Infolist $infoList) : Infolist
{
$infoList->schema([
Section::make(fn(Model $record) => $record->id)
Section::make(static fn(Model $record) => $record->id)
->schema([
TextEntry::make('order_status')
->badge()
Expand Down Expand Up @@ -462,8 +462,12 @@ public static function table(Table $table) : Table
Tables\Actions\ViewAction::make(),
Tables\Actions\Action::make('shipping')
->url( fn($record)=>static::getUrl('shipping',['record'=>$record->id]))
->visible(fn($record)=>$record->shipping_status !== ShippingStatusEnum::SHIPPED)
,

OrderCluster\Resources\OrderResource\Actions\SellerRemarksAction::make('seller_remarks'),
OrderCluster\Resources\OrderResource\Actions\SellerRemarksAction::make('seller_message'),

])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace RedJasmine\FilamentOrder\Clusters\Order\Resources\OrderResource\Actions;

use Filament\Forms;

use Filament\Tables\Actions\Action;

class SellerRemarksAction extends Action
{

protected function setUp() : void
{
parent::setUp();

$this->label('卖家备注');
$this->color('primary');
$this->modalWidth('lg');
$this->modalHeading('卖家备注');
$this->fillForm(fn($record) : array => [

'remarks' => $record->info->{$this->name}
]);
$this->form([
Forms\Components\Textarea::make('remarks')
]);

$this->action(function ($data, $record) {


dd($this->name, $data, $record);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Filament\Actions\Action;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Infolists\Infolist;
use Filament\Notifications\Notification;
use Filament\Pages\Concerns\InteractsWithFormActions;
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
Expand All @@ -13,38 +14,67 @@
use RedJasmine\FilamentCore\Helpers\ResourcePageHelper;
use RedJasmine\FilamentOrder\Clusters\Order\Resources\OrderResource;
use RedJasmine\Order\Application\UserCases\Commands\Shipping\OrderDummyShippingCommand;
use RedJasmine\Order\Application\UserCases\Commands\Shipping\OrderLogisticsShippingCommand;
use RedJasmine\Support\Exceptions\AbstractException;
use Throwable;

/**
* @property Form $form
* @property Form $dummy
* @property Form $logistics
*/
class Shipping extends Page
{


protected static string $resource = OrderResource::class;


use InteractsWithRecord, ResourcePageHelper {
InteractsWithRecord::resolveRecord insteadof ResourcePageHelper;
}

public ?array $data = [];

protected function getViewData(): array
{
return [
'forms'=>$this->getForms()
];
}

use InteractsWithFormActions;
public function infolist(Infolist $infolist): Infolist
{
return static::getResource()::infolist($infolist);
}

protected function makeInfolist(): Infolist
{
return parent::makeInfolist()
->record($this->getRecord())
->columns($this->hasInlineLabels() ? 1 : 2)
->inlineLabel($this->hasInlineLabels());
}
protected function hasInfolist(): bool
{
return (bool) count($this->getInfolist('infolist')->getComponents());
}


public function mount(int|string $record) : void
{

$this->record = $this->resolveRecord($record);


$this->form->fill([
$this->dummy->fill([
'order_products' => $this->record->products->pluck('id')->toArray(),
'is_finished' => true,
]);


$this->logistics->fill([
'is_split'=>false,

]);
}

protected function getFormActions() : array
Expand All @@ -56,65 +86,41 @@ protected function getFormActions() : array
}


public function save()
{
//$data = $this->form->getState();
dd($this->form->getState());


}


public function dummy()
{
$data = $this->form->getState();
$data['id'] = $this->record->id;
$command = OrderDummyShippingCommand::from($data);


try {
app(static::getResource()::getCommandService())->dummyShipping($command);
}catch (AbstractException $abstractException){
Notification::make()->danger()
->title($abstractException->getMessage())
->send();
return;
}
Notification::make()->success()
->title('OK')
->send();

$this->redirect(static::getResource()::getUrl('index'));

}

protected function getSaveFormAction() : Action
{
return Action::make('dummy')
return Action::make('save')
->label('发货')
->submit('dummy');
->submit('save');
}


protected static string $view = 'red-jasmine-filament-order::resources.order-resource.pages.shipping';

public function getHeading() : string
{
return 'getHeading';
return $this->getRecord()->id;
}

public static function getNavigationLabel() : string
{
return '大号';
}


public function getTitle() : string|Htmlable
{
return '这个啥z';
return $this->getRecord()->id;
}


public function form(Form $form) : Form
protected function getForms() : array
{
return [
'dummy',
'logistics',
];
}

public function dummy(Form $form) : Form
{
$record = $this->record;
return $form->schema([
Expand All @@ -128,17 +134,78 @@ public function form(Form $form) : Form
->boolean()

])
->statePath('data')
->statePath('data.dummy')
->columns(1);
}

public function dummySubmit()
{
$data = $this->dummy->getState();
$data['id'] = $this->record->id;
$command = OrderDummyShippingCommand::from($data);


try {
app(static::getResource()::getCommandService())->dummyShipping($command);
} catch (AbstractException $abstractException) {
Notification::make()->danger()
->title($abstractException->getMessage())
->send();
return;
}
Notification::make()->success()
->title('OK')
->send();

$this->redirect(static::getResource()::getUrl('index'));

}

public function logistics(Form $form) : Form
{

$record = $this->record;
return $form->schema([

Forms\Components\ToggleButtons::make('is_split')
->default(false)
->grouped()
->boolean(),
Forms\Components\CheckboxList::make('order_products')
->options($record->products->pluck('title', 'id')->toArray()),

Forms\Components\TextInput::make('express_company_code')->required(),
Forms\Components\TextInput::make('express_no')->required(),

])
->statePath('data.logistics');
}
public function logisticsSubmit()
{
$data = $this->logistics->getState();

$data['id'] = $this->record->id;
$command = OrderLogisticsShippingCommand::from($data);
try {
app(static::getResource()::getCommandService())->logisticsShipping($command);
} catch (AbstractException $abstractException) {
Notification::make()->danger()
->title($abstractException->getMessage())
->send();
return;
}
Notification::make()->success()
->title('OK')
->send();

$this->redirect(static::getResource()::getUrl('index'));

}

protected function getHeaderActions() : array
{
return [
Action::make('test')->button(),
Action::make('test')->button(),
Action::make('test')->button(),
Action::make('test')->button(),


];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public function handle(OrderLogisticsShippingCommand $command) : void
$order = $this->find($command->id);
$orderLogistics = OrderLogistics::newModel();
$orderLogistics->shippable_id = $order->id;
$orderLogistics->seller = $order->seller;
$orderLogistics->buyer = $order->buyer;
$orderLogistics->seller_type = $order->seller_type;
$orderLogistics->seller_id = $order->seller_id;
$orderLogistics->buyer_type = $order->buyer_type;
$orderLogistics->buyer_id = $order->buyer_id;
$orderLogistics->shipper = LogisticsShipperEnum::SELLER;
$orderLogistics->order_product_id = $command->orderProducts;
$orderLogistics->express_company_code = $command->expressCompanyCode;
Expand Down

0 comments on commit f3fe909

Please sign in to comment.