селектор помещений из апи
This commit is contained in:
parent
914c045fac
commit
a45afdba88
@ -8,21 +8,39 @@ class Plan7SelectorLivewire extends Component
|
||||
{
|
||||
public $mode = 'new';
|
||||
public $containerId;
|
||||
public $filter = [];
|
||||
|
||||
public $allObjects;
|
||||
public $types;
|
||||
public $access;
|
||||
public $bs;
|
||||
public $summary;
|
||||
public $room;
|
||||
public $objects = [];
|
||||
private $api = 'https://plan7.ru/catalog/exp/json/?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';
|
||||
public function mount($containerId = 'plan7__selector')
|
||||
{
|
||||
$this->containerId = $containerId;
|
||||
$this->getSummary();
|
||||
$this->getData();
|
||||
}
|
||||
|
||||
private function getSummary() {
|
||||
$URL = $this->apiSummary;
|
||||
$opt = [];
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $URL);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
$fields = http_build_query($opt);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
|
||||
$out = curl_exec($curl);
|
||||
$this->summary = json_decode($out, true);
|
||||
curl_close($curl);
|
||||
}
|
||||
private function getData()
|
||||
{
|
||||
$URL = $this->api;
|
||||
$URL = $this->apiAll;
|
||||
$opt = [];
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $URL);
|
||||
@ -39,28 +57,61 @@ private function getData()
|
||||
|
||||
public function setHouse($id)
|
||||
{
|
||||
$this->bs = $id;
|
||||
$this->room = null;
|
||||
$this->filter['bs'] = $id;
|
||||
}
|
||||
|
||||
public function setRoom($id)
|
||||
{
|
||||
$this->room = $this->allObjects['data'][$id];
|
||||
$this->filter['id'] = $id;
|
||||
}
|
||||
public function resetFilter() {
|
||||
$this->filter = [];
|
||||
}
|
||||
|
||||
public function start() {
|
||||
$this->mode = 'select';
|
||||
$this->filter = [];
|
||||
$this->getData();
|
||||
}
|
||||
public function done() {
|
||||
$this->mode = 'selected';
|
||||
$this->bs = null;
|
||||
$this->room = null;
|
||||
$this->filter = [];
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
$objs = [];
|
||||
if (!$this->bs && !$this->room) {
|
||||
if (count($this->filter)) {
|
||||
foreach ($this->allObjects['data'] as $key => $room) {
|
||||
if ($room['access'] != 0) {
|
||||
if (array_key_exists('id', $this->filter) && $this->filter['id'] && $room['id'] != $this->filter['id']) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists('bs', $this->filter) && $this->filter['bs'] && $room['bs'] != $this->filter['bs']) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists('type', $this->filter) && $this->filter['type'] && $room['type'] != $this->filter['type']) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists('min_area', $this->filter) && $room['area'] < $this->filter['min_area']) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists('max_area', $this->filter) && $room['area'] > $this->filter['max_area']) {
|
||||
continue;
|
||||
}
|
||||
$room['mode'] = 'room';
|
||||
$objs[] = $room;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($this->allObjects['values']['bs'] as $key => $house) {
|
||||
$objs[] = [
|
||||
'mode' => 'bs',
|
||||
'id' => $house['id'],
|
||||
'name' => $house['name'],
|
||||
];
|
||||
}
|
||||
}
|
||||
/*if (!$this->bs && !$this->room) {
|
||||
foreach ($this->allObjects['values']['bs'] as $key => $house) {
|
||||
$objs[] = [
|
||||
'mode' => 'bs',
|
||||
@ -82,7 +133,7 @@ public function render()
|
||||
$objs[] = $room;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return view('plan7::livewire.selector', [
|
||||
'objs' => $objs
|
||||
]);
|
||||
|
||||
@ -1,9 +1,28 @@
|
||||
<div class="">
|
||||
<!-- Button trigger modal -->
|
||||
<div class="d-flex justify-content-between">
|
||||
@if($room)
|
||||
<div class="text-primary">
|
||||
<div class="text-uppercase fw-bold">
|
||||
{{ (($room['type'] == 0) ? $room['room'] . ' комн. ' . mb_strtolower($this->types[$room['type']]) : $this->types[$room['type']]) }}
|
||||
</div>
|
||||
<div class="d-flex gap-2 fs-6">
|
||||
<div class="badge text-bg-secondary">Помещение: {{ $room['name'] }}</div>
|
||||
<div class="badge text-bg-secondary">Площадь: {{ $room['area'] }}</div>
|
||||
<div class="badge text-bg-secondary">Этаж: {{ $room['level'] }}</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<button type="button" wire:click="start()" class="btn btn-primary" data-bs-toggle="modal"
|
||||
data-bs-target="#plan7_selector_modal">
|
||||
@if($room)
|
||||
Изменить
|
||||
@else
|
||||
Выбрать помещение
|
||||
@endif
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" wire:ignore.self id="plan7_selector_modal" tabindex="-1" aria-labelledby="exampleModalLabel"
|
||||
@ -15,7 +34,88 @@
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="d-flex flex-wrap">
|
||||
<div class="d-flex gap-2">
|
||||
<div class="col-4 p-2 rounded-4 mb-3 bg-light border d-flex gap-2">
|
||||
<div class="flex-fill">
|
||||
<label>Дом/секция:</label>
|
||||
<div>
|
||||
<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 class="flex-fill">
|
||||
<label>Тип помещения:</label>
|
||||
<div>
|
||||
<select wire:loading.attr="disabled" class="form-select"
|
||||
wire:model.change="filter.type">
|
||||
<option></option>
|
||||
@foreach($summary as $typeSummary)
|
||||
@if(array_key_exists('type', $typeSummary))
|
||||
<option value="{{ $typeSummary['type'] }}">{{ $types[$typeSummary['type']] }}
|
||||
</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@if(array_key_exists('type', $filter))
|
||||
@foreach($summary as $typeSummary)
|
||||
@if(array_key_exists('type', $typeSummary) && $typeSummary['type'] == $filter['type'])
|
||||
<div class="col-4 p-2 rounded-4 mb-3 bg-light border">
|
||||
<label>Площадь:</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">от</span>
|
||||
<input wire:loading.attr="disabled" type="number" wire:model.live="filter.min_area"
|
||||
class="form-control w-25" placeholder="{{ $typeSummary['min_area'] }}">
|
||||
<span class="input-group-text">до</span>
|
||||
<input wire:loading.attr="disabled" type="number" wire:model.live="filter.max_area"
|
||||
class="form-control w-25" placeholder="{{ $typeSummary['max_area'] }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4 p-2 rounded-4 mb-3 bg-light border">
|
||||
<label>Стоимость:</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">от</span>
|
||||
<input wire:loading.attr="disabled" wire:model.live="filter.min_price" type="number"
|
||||
class="form-control w-25"
|
||||
placeholder="{{ number_format($typeSummary['min_price'], 0, '', ' ') . ' р.' }}">
|
||||
<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)
|
||||
@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
|
||||
@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')
|
||||
@ -58,7 +158,8 @@ class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
@if($room)
|
||||
<div class="modal-footer">
|
||||
<button wire:click="done()" type="button" class="btn btn-primary" data-bs-dismiss="modal">Выбрать и закрыть</button>
|
||||
<button wire:click="done()" type="button" class="btn btn-primary" data-bs-dismiss="modal">Выбрать и
|
||||
закрыть</button>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user