исправил таблицу с клиентами, добавил поиск
This commit is contained in:
parent
ac6c271dfc
commit
bbf324b092
@ -6,6 +6,7 @@
|
|||||||
use Livewire\WithPagination;
|
use Livewire\WithPagination;
|
||||||
use Livewire\WithoutUrlPagination;
|
use Livewire\WithoutUrlPagination;
|
||||||
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Modules\Main\Models\Deal\Client;
|
use Modules\Main\Models\Deal\Client;
|
||||||
use Modules\Main\Models\Agent\Agent;
|
use Modules\Main\Models\Agent\Agent;
|
||||||
@ -23,14 +24,25 @@ class ClientsTable extends Component
|
|||||||
public $status;
|
public $status;
|
||||||
public $count;
|
public $count;
|
||||||
public $mode;//short || full
|
public $mode;//short || full
|
||||||
|
private $filter = [];
|
||||||
|
|
||||||
public function mount($status = null, $count = 10, $mode = 'full')
|
public function mount($status = null, $count = 10, $mode = 'full')
|
||||||
{
|
{
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
$this->count = $count;
|
$this->count = $count;
|
||||||
$this->mode = $mode;
|
$this->mode = $mode;
|
||||||
|
$this->filter = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[On('clientsTableFilterUpdated')]
|
||||||
|
public function appendFilter($filter) {
|
||||||
|
if ($filter) {
|
||||||
|
$this->filter = $filter;
|
||||||
|
} else {
|
||||||
|
$this->filter = [];
|
||||||
|
}
|
||||||
|
$this->getClients();
|
||||||
|
}
|
||||||
#[On('clientCreated')]
|
#[On('clientCreated')]
|
||||||
public function getDeals()
|
public function getDeals()
|
||||||
{
|
{
|
||||||
@ -59,6 +71,9 @@ public function getDeals()
|
|||||||
{
|
{
|
||||||
$deals = Deal::where('agent_id', $agent->id);
|
$deals = Deal::where('agent_id', $agent->id);
|
||||||
}
|
}
|
||||||
|
if (array_key_exists('status', $this->filter)) {
|
||||||
|
$deals->where('status', $this->filter['status']);
|
||||||
|
}
|
||||||
if (!$deals) {
|
if (!$deals) {
|
||||||
return Client::where('id',0);
|
return Client::where('id',0);
|
||||||
}
|
}
|
||||||
@ -81,6 +96,9 @@ function getClients()
|
|||||||
$clients = $clients->select('users.*');
|
$clients = $clients->select('users.*');
|
||||||
$clients = $clients->orderBy('name');
|
$clients = $clients->orderBy('name');
|
||||||
|
|
||||||
|
if (array_key_exists('search', $this->filter) && $searchString = trim($this->filter['search'])) {
|
||||||
|
$clients->whereFullText(['name', 'phone', 'email'], $this->filter['search']);
|
||||||
|
}
|
||||||
if ($this->status && $this->status == DealStatus::UNIQUE)
|
if ($this->status && $this->status == DealStatus::UNIQUE)
|
||||||
{
|
{
|
||||||
$clients = $clients->whereHas('deals', function ($query)
|
$clients = $clients->whereHas('deals', function ($query)
|
||||||
|
|||||||
38
app/Modules/Main/Http/Livewire/ClientSearchInputLivewire.php
Normal file
38
app/Modules/Main/Http/Livewire/ClientSearchInputLivewire.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Main\Http\Livewire;
|
||||||
|
|
||||||
|
use Livewire\Component;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
|
use Modules\Main\Models\Deal\DealStatus;
|
||||||
|
|
||||||
|
class ClientSearchInputLivewire extends Component
|
||||||
|
{
|
||||||
|
public $filter = [];
|
||||||
|
public function mount()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus($status)
|
||||||
|
{
|
||||||
|
if (array_key_exists('status', $this->filter) && $this->filter['status'] === $status) {
|
||||||
|
unset($this->filter['status']);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->filter['status'] = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updated($propertyName)
|
||||||
|
{
|
||||||
|
$this->dispatch('clientsTableFilterUpdated', filter: $this->filter);
|
||||||
|
}
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('main::clients.livewire.search.input', [
|
||||||
|
'statuses' => DealStatus::class
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -78,6 +78,7 @@ protected function registerLivewire()
|
|||||||
//Livewire::component('<name>', \Modules\<NAME>\Http\Livewire\<NAME>::class);
|
//Livewire::component('<name>', \Modules\<NAME>\Http\Livewire\<NAME>::class);
|
||||||
Livewire::component('company.agent.create', \Modules\Main\Http\Livewire\CreateAgentLivewire::class);
|
Livewire::component('company.agent.create', \Modules\Main\Http\Livewire\CreateAgentLivewire::class);
|
||||||
Livewire::component('company.admin.create', \Modules\Main\Http\Livewire\CreateCompanyAdminLivewire::class);
|
Livewire::component('company.admin.create', \Modules\Main\Http\Livewire\CreateCompanyAdminLivewire::class);
|
||||||
|
Livewire::component('clients.search.input', \Modules\Main\Http\Livewire\ClientSearchInputLivewire::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerComponent()
|
protected function registerComponent()
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
use Modules\Main\Models\Deal\DealStatus;
|
||||||
|
?>
|
||||||
|
<div class="d-flex gap-2 flex-row">
|
||||||
|
<div class="col-12 col-md-auto p-2 border rounded-3 border-1 p-1 bg-white">
|
||||||
|
<input wire:model.live="filter.status" type="radio" class="btn-check" name="status" value="{{ DealStatus::UNIQUE }}" id="option6" autocomplete="off"
|
||||||
|
{{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::UNIQUE) ? 'checked' : '' }}>
|
||||||
|
<label class="btn p-2 fs-5" for="option6">Уникальные</label>
|
||||||
|
|
||||||
|
<input wire:model.live="filter.status" type="radio" class="btn-check" name="status" value="{{ DealStatus::NOT_UNIQUE }}" id="option7" autocomplete="off"
|
||||||
|
{{ (array_key_exists('status', $filter) && $filter['status'] == DealStatus::NOT_UNIQUE) ? 'checked' : '' }}>
|
||||||
|
<label class="btn p-2 fs-5" for="option7">Неуникальные</label>
|
||||||
|
</div>
|
||||||
|
<input wire:model.live="filter.search" class="flex-fill form-control form-control-lg" type="text" placeholder="Поиск по имени, телефону, электронной почте">
|
||||||
|
</div>
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
DB::statement('ALTER TABLE users ADD FULLTEXT search(name, phone, email)');
|
||||||
|
Schema::table('users', function (Blueprint $table)
|
||||||
|
{
|
||||||
|
$table->engine = 'MyISAM';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -3,26 +3,14 @@
|
|||||||
@extends('layouts.app')
|
@extends('layouts.app')
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="">
|
<div class="">
|
||||||
<form class=" d-flex flex-row mb-3 sticky-top bg-light rounded-3" method="GET" action="{{ route('clients.table') }}">
|
<div class=" d-flex gap-2 p-1 flex-row mb-3 sticky-top bg-light rounded-3" method="GET" action="{{ route('clients.table') }}">
|
||||||
<div class="col-12 col-md-auto p-2 border rounded-3 border-1 p-1 bg-white">
|
<div class="w-100">
|
||||||
<input type="radio" class="btn-check" name="status" value="all" id="option5" autocomplete="off"
|
@livewire('clients.search.input')
|
||||||
onclick="this.form.submit()" {{ $status == 'all' ? 'checked' : '' }}>
|
|
||||||
<label class="btn p-2 fs-5" for="option5">Все</label>
|
|
||||||
|
|
||||||
<input type="radio" class="btn-check" name="status" value="unique" id="option6" autocomplete="off"
|
|
||||||
onclick="this.form.submit()" {{ $status == 'unique' ? 'checked' : '' }}>
|
|
||||||
<label class="btn p-2 fs-5" for="option6">Уникальные</label>
|
|
||||||
|
|
||||||
<input type="radio" class="btn-check" name="status" value="not unique" id="option7" autocomplete="off"
|
|
||||||
onclick="this.form.submit()" {{ $status == 'not unique' ? 'checked' : '' }}>
|
|
||||||
<label class="btn p-2 fs-5" for="option7">Не
|
|
||||||
уникальные</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="d-none d-md-flex flex-fill"></div>
|
|
||||||
<div class="ms-auto p-2 d-none d-md-block">
|
<div class="ms-auto p-2 d-none d-md-block">
|
||||||
<button type="button" class="btn btn-primary py-2 px-3 fs-5" data-bs-toggle="modal"
|
<button type="button" class="btn btn-primary py-2 px-3 fs-5" data-bs-toggle="modal"
|
||||||
data-bs-target="#createClientModal">
|
data-bs-target="#createClientModal">
|
||||||
<i class="bi bi-person-plus"></i> <span class="d-inline d-none d-md-inline">Добавить клиента</span>
|
<i class="bi bi-person-plus"></i> <span class="d-inline d-none">Добавить клиента</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-block d-md-none position-fixed bottom-0 end-0 me-3" style="margin-bottom:90px;">
|
<div class="d-block d-md-none position-fixed bottom-0 end-0 me-3" style="margin-bottom:90px;">
|
||||||
@ -32,20 +20,10 @@
|
|||||||
<i class="bi bi-person-plus"></i>
|
<i class="bi bi-person-plus"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
@if (!$status || $status == 'all' || $status == 'unique')
|
|
||||||
<h4 class="fw-bold mt-5 mb-3">Уникальные</h4>
|
|
||||||
<div class="fs-5 bg-light mb-2">
|
|
||||||
@livewire('clientsTable', ['status' => 'UNIQUE'])
|
|
||||||
</div>
|
</div>
|
||||||
@endif
|
<div class="fs-5 mb-2">
|
||||||
|
@livewire('clientsTable')
|
||||||
@if (!$status || $status == 'all' || $status == 'not unique')
|
|
||||||
<h4 class="fw-bold mt-5 mb-3">Не уникальные</h4>
|
|
||||||
<div class="fs-5 bg-light mb-2">
|
|
||||||
@livewire('clientsTable', ['status' => 'NOT UNIQUE'])
|
|
||||||
</div>
|
</div>
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.bg-primary {
|
.bg-primary {
|
||||||
|
color:#fff;
|
||||||
background-color:
|
background-color:
|
||||||
{{ DESIGN_PARAMETERS['primary_color'] }}
|
{{ DESIGN_PARAMETERS['primary_color'] }}
|
||||||
!important;
|
!important;
|
||||||
@ -51,6 +52,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn-primary {
|
.btn-primary {
|
||||||
|
color:#aaaaaa;
|
||||||
background-color:
|
background-color:
|
||||||
{{ DESIGN_PARAMETERS['primary_color'] }}
|
{{ DESIGN_PARAMETERS['primary_color'] }}
|
||||||
!important;
|
!important;
|
||||||
@ -59,6 +61,14 @@
|
|||||||
!important;
|
!important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn:hover {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
color:#fff;
|
||||||
|
}
|
||||||
|
|
||||||
input[type="radio"]:checked+label {
|
input[type="radio"]:checked+label {
|
||||||
background-color: {{ DESIGN_PARAMETERS['primary_color'] }} !important;
|
background-color: {{ DESIGN_PARAMETERS['primary_color'] }} !important;
|
||||||
border-color: {{ DESIGN_PARAMETERS['primary_color'] }} !important;
|
border-color: {{ DESIGN_PARAMETERS['primary_color'] }} !important;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user