селектор помещений из апи
This commit is contained in:
parent
60684b424d
commit
914c045fac
@ -161,7 +161,16 @@ class="bi bi-plus-circle" viewBox="0 0 16 16">
|
|||||||
<strong>{{ $message }}</strong>
|
<strong>{{ $message }}</strong>
|
||||||
</span>
|
</span>
|
||||||
@enderror
|
@enderror
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@if($complexId)
|
||||||
|
<div class="p-2 rounded-4 mb-3 bg-light">
|
||||||
|
<label for="complexId">Помещение</label>
|
||||||
|
<div>
|
||||||
|
<livewire:plan7Selector />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@if (count($availableAgents) > 1)
|
@if (count($availableAgents) > 1)
|
||||||
|
|
||||||
<div class="form-floating mb-3">
|
<div class="form-floating mb-3">
|
||||||
|
|||||||
5
app/Modules/Plan7/Config/config.php
Normal file
5
app/Modules/Plan7/Config/config.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
];
|
||||||
24
app/Modules/Plan7/Http/Controllers/DocsController.php
Normal file
24
app/Modules/Plan7/Http/Controllers/DocsController.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Docs\Http\Controllers;
|
||||||
|
|
||||||
|
use Modules\Docs\Models\Document;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
class DocsController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$docs = Document::orderBy('name')->get();
|
||||||
|
return view('docs::index', [
|
||||||
|
'docs' => $docs
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
public function download(Document $document)
|
||||||
|
{
|
||||||
|
$ext = explode('.', $document->path);
|
||||||
|
$ext = end($ext);
|
||||||
|
return Storage::download($document->path, $document->name . '.' . $ext);
|
||||||
|
}
|
||||||
|
}
|
||||||
92
app/Modules/Plan7/Http/Livewire/Plan7SelectorLivewire.php
Normal file
92
app/Modules/Plan7/Http/Livewire/Plan7SelectorLivewire.php
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Plan7\Http\Livewire;
|
||||||
|
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class Plan7SelectorLivewire extends Component
|
||||||
|
{
|
||||||
|
public $mode = 'new';
|
||||||
|
public $containerId;
|
||||||
|
public $allObjects;
|
||||||
|
public $types;
|
||||||
|
public $access;
|
||||||
|
public $bs;
|
||||||
|
public $room;
|
||||||
|
public $objects = [];
|
||||||
|
private $api = 'https://plan7.ru/catalog/exp/json/?token=0754c5e6a3824322&zk=614';
|
||||||
|
public function mount($containerId = 'plan7__selector')
|
||||||
|
{
|
||||||
|
$this->containerId = $containerId;
|
||||||
|
$this->getData();
|
||||||
|
}
|
||||||
|
private function getData()
|
||||||
|
{
|
||||||
|
$URL = $this->api;
|
||||||
|
$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->allObjects = json_decode($out, true);
|
||||||
|
$this->types = $this->allObjects['values']['type'];
|
||||||
|
$this->access = $this->allObjects['values']['access'];
|
||||||
|
curl_close($curl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHouse($id)
|
||||||
|
{
|
||||||
|
$this->bs = $id;
|
||||||
|
$this->room = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRoom($id)
|
||||||
|
{
|
||||||
|
$this->room = $this->allObjects['data'][$id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function start() {
|
||||||
|
$this->mode = 'select';
|
||||||
|
$this->getData();
|
||||||
|
}
|
||||||
|
public function done() {
|
||||||
|
$this->mode = 'selected';
|
||||||
|
$this->bs = null;
|
||||||
|
$this->room = null;
|
||||||
|
}
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
$objs = [];
|
||||||
|
if (!$this->bs && !$this->room) {
|
||||||
|
foreach ($this->allObjects['values']['bs'] as $key => $house) {
|
||||||
|
$objs[] = [
|
||||||
|
'mode' => 'bs',
|
||||||
|
'id' => $house['id'],
|
||||||
|
'name' => $house['name'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} elseif ($this->bs && !$this->room) {
|
||||||
|
foreach ($this->allObjects['data'] as $key => $room) {
|
||||||
|
if ($room['access'] != 0) {
|
||||||
|
$room['mode'] = 'room';
|
||||||
|
$objs[] = $room;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($this->bs && $this->room) {
|
||||||
|
foreach ($this->allObjects['data'] as $key => $room) {
|
||||||
|
if ($room['id'] == $this->room['id']) {
|
||||||
|
$room['mode'] = 'room';
|
||||||
|
$objs[] = $room;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return view('plan7::livewire.selector', [
|
||||||
|
'objs' => $objs
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
9
app/Modules/Plan7/Models/Plan7Selector.php
Normal file
9
app/Modules/Plan7/Models/Plan7Selector.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Plan7\Models;
|
||||||
|
|
||||||
|
|
||||||
|
class Plan7Selector
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
71
app/Modules/Plan7/Providers/ModuleServiceProvider.php
Normal file
71
app/Modules/Plan7/Providers/ModuleServiceProvider.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Plan7\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
class ModuleServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
protected string $moduleName = 'Plan7';
|
||||||
|
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->register(RouteServiceProvider::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$this->registerViews();
|
||||||
|
$this->registerLivewireViews();
|
||||||
|
$this->registerMigrations();
|
||||||
|
$this->registerConfig();
|
||||||
|
$this->registerComponent();
|
||||||
|
$this->registerLivewire();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerViews()
|
||||||
|
{
|
||||||
|
$moduleViewsPath = __DIR__ . '/../Views';
|
||||||
|
$this->loadViewsFrom(
|
||||||
|
$moduleViewsPath,
|
||||||
|
strtolower($this->moduleName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerLivewireViews()
|
||||||
|
{
|
||||||
|
$moduleViewsPath = __DIR__ . '/../Views/livewire';
|
||||||
|
$this->loadViewsFrom(
|
||||||
|
$moduleViewsPath,
|
||||||
|
strtolower($this->moduleName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerMigrations()
|
||||||
|
{
|
||||||
|
$this->loadMigrationsFrom(
|
||||||
|
app_path('Modules/' . $this->moduleName . '/Database/Migrations')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerConfig()
|
||||||
|
{
|
||||||
|
$path = app_path('Modules/' . $this->moduleName . '/Config/config.php');
|
||||||
|
$this->mergeConfigFrom(
|
||||||
|
$path,
|
||||||
|
strtolower($this->moduleName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerLivewire()
|
||||||
|
{
|
||||||
|
Livewire::component('plan7Selector', \Modules\Plan7\Http\Livewire\Plan7SelectorLivewire::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerComponent()
|
||||||
|
{
|
||||||
|
//Blade::component('document', \Modules\Plan7\Http\Components\DocumentComponent::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Modules/Plan7/Providers/RouteServiceProvider.php
Normal file
24
app/Modules/Plan7/Providers/RouteServiceProvider.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Plan7\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
class RouteServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
public function map()
|
||||||
|
{
|
||||||
|
$this->registerWebRoutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerWebRoutes()
|
||||||
|
{
|
||||||
|
//Add Web Routes with web Guard
|
||||||
|
Route::middleware('web')
|
||||||
|
//Set Default Controllers Namespace
|
||||||
|
->namespace('Modules\\Plan7\\Http\\Controllers')
|
||||||
|
->group(app_path('Modules/Plan7/Routes/web.php'));
|
||||||
|
}
|
||||||
|
}
|
||||||
12
app/Modules/Plan7/Routes/web.php
Normal file
12
app/Modules/Plan7/Routes/web.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Modules\Docs\Http\Controllers\DocsController;
|
||||||
|
|
||||||
|
Route::middleware(['auth'])->group(function ()
|
||||||
|
{
|
||||||
|
|
||||||
|
Route::get('/doc', [DocsController::class, 'index'])->name('docs.index');
|
||||||
|
Route::get('/docs/{document}/download', [DocsController::class, 'download'])->name('docs.download');
|
||||||
|
|
||||||
|
});
|
||||||
12
app/Modules/Plan7/Views/index.blade.php
Normal file
12
app/Modules/Plan7/Views/index.blade.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
@php($title = 'Документы')
|
||||||
|
@extends('layouts.app')
|
||||||
|
@section('content')
|
||||||
|
<div class="row g-2">
|
||||||
|
@foreach ($docs as $document)
|
||||||
|
<div class="col-6">
|
||||||
|
<div class="p-3"><x-document id="{{ $document->id }}" /></div>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
67
app/Modules/Plan7/Views/livewire/selector.blade.php
Normal file
67
app/Modules/Plan7/Views/livewire/selector.blade.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<div class="">
|
||||||
|
<!-- Button trigger modal -->
|
||||||
|
<button type="button" wire:click="start()" class="btn btn-primary" data-bs-toggle="modal"
|
||||||
|
data-bs-target="#plan7_selector_modal">
|
||||||
|
Выбрать помещение
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Modal -->
|
||||||
|
<div class="modal fade" wire:ignore.self id="plan7_selector_modal" tabindex="-1" aria-labelledby="exampleModalLabel"
|
||||||
|
aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-scrollable modal-xl modal-fullscreen-lg-down">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h1 class="modal-title fs-5" id="exampleModalLabel">Выбор помещения</h1>
|
||||||
|
<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">
|
||||||
|
@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>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@if($room)
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button wire:click="done()" type="button" class="btn btn-primary" data-bs-dismiss="modal">Выбрать и закрыть</button>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@ -132,4 +132,5 @@ class="" alt="...">
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@livewire('plan7Selector')
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user