селектор помещений из апи

This commit is contained in:
developer 2026-04-02 11:49:13 +08:00
parent 97a48aa657
commit b2a11b212b
2 changed files with 156 additions and 118 deletions

View File

@ -14,7 +14,7 @@ class Plan7SelectorLivewire extends Component
public $types; public $types;
public $access; public $access;
public $summary; public $summary;
public $room; public $room = false;
public $objects = []; public $objects = [];
private $apiSummary = 'https://plan7.ru/catalog/exp/json/summary/?token=0754c5e6a3824322&zk=614'; private $apiSummary = 'https://plan7.ru/catalog/exp/json/summary/?token=0754c5e6a3824322&zk=614';
private $apiAll = 'https://plan7.ru/catalog/exp/json/?token=0754c5e6a3824322&zk=614'; private $apiAll = 'https://plan7.ru/catalog/exp/json/?token=0754c5e6a3824322&zk=614';
@ -63,7 +63,10 @@ public function setHouse($id)
public function setRoom($id) public function setRoom($id)
{ {
$this->room = $this->allObjects['data'][$id]; $this->room = $this->allObjects['data'][$id];
$this->filter['id'] = $id; //$this->filter['id'] = $id;
}
public function unsetRoom() {
$this->room = false;
} }
public function resetFilter() { public function resetFilter() {
$this->filter = []; $this->filter = [];
@ -71,6 +74,7 @@ public function resetFilter() {
public function start() { public function start() {
$this->mode = 'select'; $this->mode = 'select';
$this->filter = []; $this->filter = [];
//$this->room = false;
$this->getData(); $this->getData();
} }
public function done() { public function done() {
@ -83,19 +87,19 @@ public function render()
if (count($this->filter)) { if (count($this->filter)) {
foreach ($this->allObjects['data'] as $key => $room) { foreach ($this->allObjects['data'] as $key => $room) {
if ($room['access'] != 0) { if ($room['access'] != 0) {
if (array_key_exists('id', $this->filter) && $this->filter['id'] !== null && $room['id'] != $this->filter['id']) { if (array_key_exists('id', $this->filter) && $this->filter['id'] != null && $room['id'] != $this->filter['id']) {
continue; continue;
} }
if (array_key_exists('bs', $this->filter) && $this->filter['bs'] !== null && $room['bs'] != $this->filter['bs']) { if (array_key_exists('bs', $this->filter) && $this->filter['bs'] != null && $room['bs'] != $this->filter['bs']) {
continue; continue;
} }
if (array_key_exists('type', $this->filter) && $this->filter['type'] !== null && $room['type'] != $this->filter['type']) { if (array_key_exists('type', $this->filter) && $this->filter['type'] != null && $room['type'] != $this->filter['type']) {
continue; continue;
} }
if (array_key_exists('min_area', $this->filter) && $this->filter['min_area'] !== null && $room['area'] < $this->filter['min_area']) { if (array_key_exists('min_area', $this->filter) && $this->filter['min_area'] != null && $room['area'] < $this->filter['min_area']) {
continue; continue;
} }
if (array_key_exists('max_area', $this->filter) && $this->filter['max_area'] !== null && $room['area'] > $this->filter['max_area']) { if (array_key_exists('max_area', $this->filter) && $this->filter['max_area'] != null && $room['area'] > $this->filter['max_area']) {
continue; continue;
} }
$room['mode'] = 'room'; $room['mode'] = 'room';

View File

@ -13,7 +13,8 @@
</div> </div>
</div> </div>
@endif @endif
<button type="button" wire:click="start()" class="btn btn-primary" onclick="plan7SelectorModal = new bootstrap.Modal(document.getElementById('plan7_selector_modal'), {});plan7SelectorModal.show()"> <button type="button" wire:click="start()" class="btn btn-primary"
onclick="plan7SelectorModal = new bootstrap.Modal(document.getElementById('plan7_selector_modal'), {});plan7SelectorModal.show()">
@if($room) @if($room)
Изменить Изменить
@else @else
@ -34,130 +35,163 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="d-flex gap-2"> @if($room)
<div class="col-4 p-2 rounded-4 mb-3 bg-light border d-flex gap-2"> <div class="d-flex">
<div class="flex-fill"> <div class="col-12 col-md-7">
<label>Дом/секция:</label> <img src="{{ array_key_exists($room['pla'], $allObjects['pla']) ? $allObjects['pla'][$room['pla']]['pla'] : '...' }}"
<div> class="img-fluid rounded-start" alt="...">
<select wire:loading.attr="disabled" class="form-select"
wire:model.change="filter.bs">
<option></option>
@foreach($allObjects['values']['bs'] as $bs)
<option value="{{ $bs['id'] }}">{{ $bs['name'] }} </option>
@endforeach
</select>
</div>
</div> </div>
<div class="flex-fill"> <div class="col px-3">
<label>Тип помещения:</label> <h3 class="fw-bold mb-3 text-uppercase">
<div> {{ (($room['type'] == 0) ? $room['room'] . ' комн. ' . mb_strtolower($this->types[$room['type']]) : $this->types[$room['type']]) }}
<select wire:loading.attr="disabled" class="form-select" </h3>
wire:model.change="filter.type"> <div class="d-flex flex-wrap gap-3">
<option></option> <div class="hstack gap-3 w-100">
@foreach($summary as $typeSummary) <div class="d-flex flex-column w-50 p-2 bg-light border border-1 rounded-4">
@if(array_key_exists('type', $typeSummary)) <span class="text-secondary">Помещение</span><span class="fs-3">{{ $room['name'] }}</span>
<option value="{{ $typeSummary['type'] }}">{{ $types[$typeSummary['type']] }} </div>
</option> <div class="d-flex flex-column w-50 p-2 bg-light border border-1 rounded-4">
@endif <span class="text-secondary">Этаж</span><span class="fs-3">{{ $room['level'] }}</span>
@endforeach </div>
</select> </div>
<div class="d-flex flex-column w-100 p-2 bg-light border border-1 rounded-4">
<span class="text-secondary">Площадь</span><span class="fs-3">{{ $room['area'] }} м<sup>2</sup></span>
</div>
<div class="d-flex flex-column w-100 p-2 bg-light border border-1 rounded-4">
<span class="text-secondary">Стоимость</span><span class="fs-3">{{ ($room['summ']) ? number_format($room['summ'], 0, '', ' ') . ' р.' : '' }}</span>
</div>
</div> </div>
</div> </div>
</div> </div>
@if(array_key_exists('type', $filter)) @endif
@foreach($summary as $typeSummary) @if(!$room)
@if(array_key_exists('type', $typeSummary) && $typeSummary['type'] == $filter['type']) <div class="d-flex gap-2">
<div class="col-4 p-2 rounded-4 mb-3 bg-light border"> <div class="col-4 p-2 rounded-4 mb-3 bg-light border d-flex gap-2">
<label>Площадь:</label> <div class="flex-fill">
<div class="input-group"> <label>Дом/строение:</label>
<span class="input-group-text">от</span> <div>
<input wire:loading.attr="disabled" type="number" wire:model.live="filter.min_area" <select wire:loading.attr="disabled" class="form-select"
class="form-control w-25" placeholder="{{ $typeSummary['min_area'] }}"> wire:model.change="filter.bs">
<span class="input-group-text">до</span> <option></option>
<input wire:loading.attr="disabled" type="number" wire:model.live="filter.max_area" @foreach($allObjects['values']['bs'] as $bs)
class="form-control w-25" placeholder="{{ $typeSummary['max_area'] }}"> <option value="{{ $bs['id'] }}">{{ $bs['name'] }} </option>
</div> @endforeach
</select>
</div> </div>
<div class="col-4 p-2 rounded-4 mb-3 bg-light border"> </div>
<label>Стоимость:</label> <div class="flex-fill">
<div class="input-group"> <label>Тип помещения:</label>
<span class="input-group-text">от</span> <div>
<input wire:loading.attr="disabled" wire:model.live="filter.min_price" type="number" <select wire:loading.attr="disabled" class="form-select"
class="form-control w-25" wire:model.change="filter.type">
placeholder="{{ number_format($typeSummary['min_price'], 0, '', ' ') . ' р.' }}"> <option></option>
<span class="input-group-text">до</span>
<input wire:loading.attr="disabled" wire:model.live="filter.max_price" type="number"
class="form-control w-25"
placeholder="{{ number_format($typeSummary['max_price'], 0, '', ' ') . ' р.' }}">
</div>
</div>
<div class="d-none p-2 rounded-4 mb-3 bg-light border">
<label>На каком этаже:</label>
<div>
@foreach($summary as $typeSummary) @foreach($summary as $typeSummary)
@if(array_key_exists('type', $typeSummary) && $typeSummary['type'] == $filter['type']) @if(array_key_exists('type', $typeSummary))
@foreach($typeSummary['floor'] as $floor) <option value="{{ $typeSummary['type'] }}">{{ $types[$typeSummary['type']] }}
</option>
@endforeach
@endif @endif
@endforeach @endforeach
</div> </select>
</div> </div>
@endif </div>
@endforeach </div>
@endif @if(array_key_exists('type', $filter))
</div> @foreach($summary as $typeSummary)
@if(count($filter) && count($objs)) @if(array_key_exists('type', $typeSummary) && $typeSummary['type'] == $filter['type'])
<div>Всего помещений: {{ count($objs) }}</div> <div class="col-4 p-2 rounded-4 mb-3 bg-light border">
@endif <label>Площадь:</label>
@if(!count($objs)) <div class="input-group">
<div wire:loading.remove class="p-5 text-secondary w-100 text-center fs-3"> <span class="input-group-text">от</span>
Нет помещений для отображения по выбранным параметрам <input wire:loading.attr="disabled" type="number" wire:model.live="filter.min_area"
</div> class="form-control w-25" placeholder="{{ $typeSummary['min_area'] }}">
@endif <span class="input-group-text">до</span>
<div wire:loading.class="opacity-50" class="d-flex flex-wrap"> <input wire:loading.attr="disabled" type="number" wire:model.live="filter.max_area"
@foreach($objs as $obj) class="form-control w-25" placeholder="{{ $typeSummary['max_area'] }}">
<div class="p-2 col-12 col-md-4">
@if($obj['mode'] == 'bs')
<div class="card" wire:click="setHouse({{ $obj['id'] }})">
<div class="card-body">
<h5 class="card-title">{{ $obj['name'] }}</h5>
<h6 class="card-subtitle mb-2 text-body-secondary">Секция/дoм</h6>
<p class="card-text"></p>
<a href="#" class="card-link">Выбрать</a>
</div>
</div>
@elseif($obj['mode'] == 'room')
<div wire:click="setRoom({{ $obj['id'] }})" class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4 d-none d-md-block">
<img src="{{ array_key_exists($obj['pla'], $allObjects['pla']) ? $allObjects['pla'][$obj['pla']]['pla'] : '...' }}"
class="img-fluid rounded-start" alt="...">
</div> </div>
<div class="col-md-8"> </div>
<div class="card-body"> <div class="col-4 p-2 rounded-4 mb-3 bg-light border">
<h5 class="card-title"> <label>Стоимость:</label>
{{ (($obj['type'] == 0) ? $obj['room'] . ' комн. ' . mb_strtolower($this->types[$obj['type']]) : $this->types[$obj['type']]) }} <div class="input-group">
</h5> <span class="input-group-text">от</span>
<p class="card-text"> <input wire:loading.attr="disabled" wire:model.live="filter.min_price" type="number"
<div>Помещение: {{ $obj['name'] }}</div> class="form-control w-25"
<div>Площадь: {{ $obj['area'] }}</div> placeholder="{{ number_format($typeSummary['min_price'], 0, '', ' ') . ' р.' }}">
<div>Этаж: {{ $obj['level'] }}</div> <span class="input-group-text">до</span>
</p> <input wire:loading.attr="disabled" wire:model.live="filter.max_price" type="number"
<p class="card-text"> class="form-control w-25"
{{ ($obj['summ']) ? number_format($obj['summ'], 0, '', ' ') . ' р.' : '' }} placeholder="{{ number_format($typeSummary['max_price'], 0, '', ' ') . ' р.' }}">
</p> </div>
</div>
<div class="d-none p-2 rounded-4 mb-3 bg-light border">
<label>На каком этаже:</label>
<div>
@foreach($summary as $typeSummary)
@if(array_key_exists('type', $typeSummary) && $typeSummary['type'] == $filter['type'])
@foreach($typeSummary['floor'] as $floor)
@endforeach
@endif
@endforeach
</div>
</div>
@endif
@endforeach
@endif
</div>
@if(count($filter) && count($objs))
<div>Всего помещений: {{ count($objs) }}</div>
@endif
<? print_r($filter) ?>
@if(!count($objs))
<div wire:loading.remove class="p-5 text-secondary w-100 text-center fs-3">
Нет помещений для отображения по выбранным параметрам
</div>
@endif
<div wire:loading.class="opacity-50" class="d-flex flex-wrap">
@foreach($objs as $obj)
<div class="p-2 col-12 col-md-4">
@if($obj['mode'] == 'bs')
<div class="card" wire:click="setHouse({{ $obj['id'] }})">
<div class="card-body">
<h5 class="card-title">{{ $obj['name'] }}</h5>
<h6 class="card-subtitle mb-2 text-body-secondary">Секция/дoм</h6>
<p class="card-text"></p>
<a href="#" class="card-link">Выбрать</a>
</div>
</div>
@elseif($obj['mode'] == 'room')
<div wire:click="setRoom({{ $obj['id'] }})" class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4 d-none d-md-block">
<img src="{{ array_key_exists($obj['pla'], $allObjects['pla']) ? $allObjects['pla'][$obj['pla']]['pla'] : '...' }}"
class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">
{{ (($obj['type'] == 0) ? $obj['room'] . ' комн. ' . mb_strtolower($this->types[$obj['type']]) : $this->types[$obj['type']]) }}
</h5>
<p class="card-text">
<div>Помещение: {{ $obj['name'] }}</div>
<div>Площадь: {{ $obj['area'] }}</div>
<div>Этаж: {{ $obj['level'] }}</div>
</p>
<p class="card-text">
{{ ($obj['summ']) ? number_format($obj['summ'], 0, '', ' ') . ' р.' : '' }}
</p>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> @endif
@endif </div>
</div> @endforeach
@endforeach </div>
</div> @endif
</div> </div>
@if(array_key_exists('id', $filter)) @if($room)
<div class="modal-footer"> <div class="modal-footer">
<button wire:click="unsetRoom()" type="button" class="btn btn-secondary">Выбрать другое</button>
<button wire:click="done()" type="button" class="btn btn-primary" data-bs-dismiss="modal">Выбрать и <button wire:click="done()" type="button" class="btn btn-primary" data-bs-dismiss="modal">Выбрать и
закрыть</button> закрыть</button>
</div> </div>