2025-05-14 15:32:54 +08:00
|
|
|
<?php
|
|
|
|
|
2025-07-26 17:22:09 +08:00
|
|
|
namespace App\Livewire\Grids;
|
2025-05-14 15:32:54 +08:00
|
|
|
|
|
|
|
use App\Models\Room;
|
|
|
|
use App\Models\Branch;
|
2025-05-21 17:53:05 +08:00
|
|
|
use App\Enums\RoomType;
|
2025-05-14 15:32:54 +08:00
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
|
|
|
|
class RoomGrid extends Component
|
|
|
|
{
|
2025-07-29 00:24:03 +08:00
|
|
|
public ?int $selectedBranchId = null;
|
|
|
|
public string $external_ip= "";
|
2025-05-21 17:53:05 +08:00
|
|
|
public array $roomTypes;
|
2025-05-14 15:32:54 +08:00
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2025-07-29 00:24:03 +08:00
|
|
|
$this->roomTypes = ['all' => '全部'] + collect(RoomType::cases())->mapWithKeys(
|
|
|
|
fn($e) => [$e->value => $e->labels()]
|
|
|
|
)->toArray();
|
|
|
|
$this->selectChanged(Branch::first()->id,"","");
|
|
|
|
|
2025-05-14 15:32:54 +08:00
|
|
|
}
|
2025-07-29 00:24:03 +08:00
|
|
|
public function selectChanged($value,$fieldName, $modelId): void
|
|
|
|
{
|
|
|
|
$branch = $value ? Branch::find($value) : null;
|
|
|
|
$this->selectedBranchId=$branch?->id ?? '';
|
|
|
|
$this->external_ip = $branch?->external_ip ?? '';
|
2025-05-21 17:53:05 +08:00
|
|
|
}
|
2025-05-14 15:32:54 +08:00
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
2025-07-29 00:24:03 +08:00
|
|
|
|
|
|
|
$rooms = Room::where('branch_id', $this->selectedBranchId)->orderBy('name')->get();
|
|
|
|
|
2025-05-21 17:53:05 +08:00
|
|
|
$floors = $rooms->pluck('floor')->unique()->sort()->values()->toArray();
|
|
|
|
|
2025-07-29 00:24:03 +08:00
|
|
|
return view('livewire.grids.room-grid', [
|
|
|
|
'rooms' => $rooms,
|
|
|
|
'floors' => $floors,
|
|
|
|
]);
|
2025-05-14 15:32:54 +08:00
|
|
|
}
|
|
|
|
}
|