From 42bc369227702b8f5a0b8548f073ad70e2ec0d9d Mon Sep 17 00:00:00 2001 From: developer Date: Thu, 23 Apr 2026 16:56:09 +0800 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D1=8B=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=BE=D0=B2:=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BD=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/ClientsTable.php | 62 +++++++++---------- .../views/livewire/clients-table.blade.php | 42 ++++++++----- 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/app/Livewire/ClientsTable.php b/app/Livewire/ClientsTable.php index eca8c50..b21f5d6 100644 --- a/app/Livewire/ClientsTable.php +++ b/app/Livewire/ClientsTable.php @@ -25,6 +25,8 @@ class ClientsTable extends Component public $count; public $mode;//short || full private $filter = []; + public $clientsCount; + public $currentPage; public function mount($status = null, $count = 10, $mode = 'full') { @@ -34,8 +36,13 @@ public function mount($status = null, $count = 10, $mode = 'full') $this->filter = []; } + public function goToPage($page) { + $this->currentPage = $page; + } + #[On('clientsTableFilterUpdated')] - public function appendFilter($filter) { + public function appendFilter($filter) + { if ($filter) { $this->filter = $filter; } else { @@ -50,32 +57,27 @@ public function getDeals() $clients = false; $user = auth()->user(); - if($cityManager = CityManager::where('user_id', auth()->id())->first()) { + if ($cityManager = CityManager::where('user_id', auth()->id())->first()) { $companies = $cityManager->city->companies->pluck('id'); - $deals = Deal::whereIn('agent_id', function ($query) use ($companies) - { + $deals = Deal::whereIn('agent_id', function ($query) use ($companies) { $query->select('id'); $query->from('agents'); $query->whereIn('company_id', $companies); }); - } - else if ($company = AdminCompanyOfUser()) { - $deals = Deal::whereIn('agent_id', function ($query) use ($company) - { + } else if ($company = AdminCompanyOfUser()) { + $deals = Deal::whereIn('agent_id', function ($query) use ($company) { $query->select('id'); $query->from('agents'); $query->where('company_id', $company->id); }); - } - elseif ($agent = Agent::where('user_id', $user->id)->first()) - { + } elseif ($agent = Agent::where('user_id', $user->id)->first()) { $deals = Deal::where('agent_id', $agent->id); } if (array_key_exists('status', $this->filter)) { $deals->where('status', $this->filter['status']); } if (!$deals) { - return Client::where('id',0); + return Client::where('id', 0); } return $deals; } @@ -84,15 +86,13 @@ function getClients() { $deals = $this->getDeals(); $clients = Client::join('deal_clients', 'users.id', '=', 'deal_clients.client_id') - ->whereIn('users.id', function ($query) use ($deals) - { + ->whereIn('users.id', function ($query) use ($deals) { $query->select('client_id') ->from('deal_clients') ->whereIn('deal_id', $deals->get()->pluck('id')); }) ->orderBy('deal_clients.id', 'desc') ->with('deals'); - ; $clients = $clients->select('users.*'); $clients = $clients->orderBy('name'); @@ -100,33 +100,31 @@ function getClients() $clients->whereFullText(['name', 'phone', 'email'], $this->filter['search']); } - if (array_key_exists('status', $this->filter) && $this->status == DealStatus::UNIQUE) - { - $clients = $clients->whereHas('deals', function ($query) - { + if (array_key_exists('status', $this->filter) && $this->status == DealStatus::UNIQUE) { + $clients = $clients->whereHas('deals', function ($query) { $query->where('status', DealStatus::UNIQUE); - })->paginate($this->count, ['*'], 'clients'); - } - elseif (array_key_exists('status', $this->filter) && $this->status == DealStatus::NOT_UNIQUE) - { - $clients = $clients->whereHas('deals', function ($query) - { + }); + } elseif (array_key_exists('status', $this->filter) && $this->status == DealStatus::NOT_UNIQUE) { + $clients = $clients->whereHas('deals', function ($query) { $query->whereIn('status', [DealStatus::MODERATION, DealStatus::NEW , DealStatus::NOT_UNIQUE]); - })->paginate($this->count, ['*'], 'clients'); - } - else - { - $clients = $clients->paginate($this->count, ['*'], 'clients'); + }); } + //$clients = $clients->skip($this->currentPage)->take(10)->get(); return $clients; } public function render() { - + $clients = $this->getClients(); + + if ($this->clientsCount != $clients->count()) { + $this->clientsCount = $clients->count(); + $this->currentPage = 1; + } + $clients = $clients->skip(($this->currentPage - 1) * $this->count)->take($this->count)->get(); return view( 'livewire.clients-table', [ - 'clients' => $this->getClients(), + 'clients' => $clients, 'statuses' => DealStatus::class ] ); diff --git a/resources/views/livewire/clients-table.blade.php b/resources/views/livewire/clients-table.blade.php index 80d05f8..a6bdfcd 100644 --- a/resources/views/livewire/clients-table.blade.php +++ b/resources/views/livewire/clients-table.blade.php @@ -1,7 +1,9 @@
-
+
- Loading... + Loading...
@@ -20,10 +22,10 @@ foreach ($clientDeals as $deal) { //echo 'dId:' . $deal->id; $filterRow[] = 'filter[deal_id][]=' . $deal->id; - $complexesNames[] = '' - . $deal->complex?->name - . (($deal->unique_until) ? ''. '' . '' : '' ) - . ''; + $complexesNames[] = '' + . $deal->complex?->name + . (($deal->unique_until) ? '' . '' . '' : '') + . ''; $companiesNames[] = $deal->agent?->company?->name; $agentsNames[] = $deal->agent?->user?->name; } @@ -35,7 +37,7 @@ $agentsNames = array_unique($agentsNames); $agentsNames = implode('
', $agentsNames); $dealsWithContracts = $client->deals()->whereHas('contract'); - ?> + ?> @if ($mode == 'full')
@@ -43,7 +45,7 @@ {{ $client->name }} @if (env('APP_DEBUG')) @foreach($client->deals as $deal) -
Bitrix ID: {{ $deal->bitrixId() }}
+
Bitrix ID: {{ $deal->bitrixId() }}
@endforeach @endif
@@ -114,7 +116,7 @@ class="bi bi-file-earmark-text ms-auto" viewBox="0 0 16 16"> $filterRow[] = 'filter[deal_id][]=' . $deal->id; } $filterRow = implode('&', $filterRow); - ?> + ?> {{ $client->name }} @@ -144,10 +146,22 @@ class="bi bi-arrow-right ms-auto" viewBox="0 0 16 16"> @endforeach
- @if ($mode == 'full') -
- {{ $clients->links('vendor.pagination.bootstrap-5', ['scrollTo' => false]) }} -
+ @if($mode == 'full') + @if($clientsCount > $count) +
+ @endif @endif -
\ No newline at end of file