From ee64915afc83561e039275144e6794e323bb1510 Mon Sep 17 00:00:00 2001 From: developer Date: Wed, 15 Apr 2026 12:05:55 +0800 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B8=D0=B5=D0=BD=D1=82=D0=BE=D0=B2:=20=D1=81=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=B8=D1=85=20=D0=B6?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Livewire/ClientCreateLivewire.php | 150 +++++++++--------- .../Views/livewire/form.blade.php | 45 ++++-- .../Http/Livewire/Plan7SelectorLivewire.php | 8 +- .../Plan7/Views/livewire/selector.blade.php | 4 +- resources/views/user/dashboard.blade.php | 22 ++- 5 files changed, 140 insertions(+), 89 deletions(-) diff --git a/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php b/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php index 978306e..b9e8715 100644 --- a/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php +++ b/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php @@ -21,8 +21,8 @@ class ClientCreateLivewire extends Component public $complexes; public $maxContactsCount; public $maxContactPhonesCount; - ///////////////////// + public $selectedObjects = []; public $agentId; public $contacts; public $objects = []; @@ -36,23 +36,24 @@ class ClientCreateLivewire extends Component protected function rules() { return [ - 'contacts.*' => ['required', 'min:1'], - 'contacts.*.firstName' => ['required', 'string', 'max:50'], + 'contacts.*' => ['required', 'min:1'], + 'contacts.*.firstName' => ['required', 'string', 'max:50'], 'contacts.*.secondName' => ['required', 'string', 'max:50'], - 'contacts.*.phones.*' => 'required|string|regex:/^(\+7)([(]{1})([0-9]{3})([)]{1})([\s]{1})([0-9]{3})([-]{1})([0-9]{2})([-]{1})([0-9]{2})/', - 'complexId' => ['required'], - 'agentId' => ['required'], + 'contacts.*.phones.*' => 'required|string|regex:/^(\+7)([(]{1})([0-9]{3})([)]{1})([\s]{1})([0-9]{3})([-]{1})([0-9]{2})([-]{1})([0-9]{2})/', + 'selectedObjects' => 'required', + 'agentId' => ['required'], ]; } protected function messages() { return [ - 'contacts.*.firstName.reqired' => 'Необходимо указать имя (отчество) клиента', + 'contacts.*.firstName.reqired' => 'Необходимо указать имя (отчество) клиента', 'contacts.*.secondName.reqired' => 'Необходимо указать фамилию клиента', - 'contacts.*.firstName.max' => 'Указанное имя клиента слишком длинное', - 'contacts.*.secondName.max' => 'Указанное имя клиента слишком длинное', - 'contacts.*.phones.*.reqired' => 'Необходимо указать номер телефона клиента', - 'contacts.*.phones.*.regex' => 'Указанный номер телефона некорректный', + 'contacts.*.firstName.max' => 'Указанное имя клиента слишком длинное', + 'contacts.*.secondName.max' => 'Указанное имя клиента слишком длинное', + 'contacts.*.phones.*.reqired' => 'Необходимо указать номер телефона клиента', + 'contacts.*.phones.*.regex' => 'Указанный номер телефона некорректный', + 'selectedObjects.required' => 'Необходимо выбрать хотя бы один интересующий ЖК', ]; } @@ -63,28 +64,28 @@ public function mount() $this->availableAgents = GetAvailableAgents(); $this->maxContactPhonesCount = 1; $this->contacts = []; + $this->contactLabels = ['Основной контакт', 'Супруг/супруга']; - if( array_key_exists('contact_form_count_max', DESIGN_PARAMETERS) && (int)DESIGN_PARAMETERS['contact_form_count_max'] > 0) { - $this->maxContactsCount = (int)DESIGN_PARAMETERS['contact_form_count_max']; + if (array_key_exists('contact_form_count_max', DESIGN_PARAMETERS) && (int) DESIGN_PARAMETERS['contact_form_count_max'] > 0) { + $this->maxContactsCount = (int) DESIGN_PARAMETERS['contact_form_count_max']; } else { - $this->maxContactsCount = 2; - }; - - if( array_key_exists('contact_form_count', DESIGN_PARAMETERS) && (int)DESIGN_PARAMETERS['contact_form_count'] > 0) { - for ($tabsCount = 1; $tabsCount <= (int)DESIGN_PARAMETERS['contact_form_count']; $tabsCount++) { + $this->maxContactsCount = 2; + } + + if (array_key_exists('contact_form_count', DESIGN_PARAMETERS) && (int) DESIGN_PARAMETERS['contact_form_count'] > 0) { + for ($tabsCount = 1; $tabsCount <= (int) DESIGN_PARAMETERS['contact_form_count']; $tabsCount++) { $this->addContact(); } } else { $this->addContact(); $this->addContact();//по-умолчанию сразу выводить супруга - }; - - $this->contactLabels = ['Основной контакт', 'Супруг/супруга']; + } + if (count($this->availableAgents) == 1) //чтобы не выводить в форму { //и не заставлять пользователя указывать вручную $this->agentId = $this->availableAgents[0]['id']; } - + $this->setCurrentContactIndex(0); } @@ -95,16 +96,14 @@ public function mount() */ public function addContact() { - if (!isset($this->contacts)) - { + if (!isset($this->contacts)) { $this->contacts = []; } - if ($this->maxContactsCount > count($this->contacts)) - { + if ($this->maxContactsCount > count($this->contacts)) { $this->contacts[] = [ - 'firstName' => '', + 'firstName' => '', 'secondName' => '', - 'phones' => [''] + 'phones' => [''] ]; } $this->setCurrentContactIndex(count($this->contacts) - 1); @@ -117,12 +116,10 @@ public function addContact() */ public function deleteContact($index = false) { - if ($index === false) - { + if ($index === false) { $index = $this->currentContactIndex; } - if ($index > 0) - { + if ($index > 0) { unset($this->contacts[$index]); $this->contacts = array_values($this->contacts); $this->setCurrentContactIndex($index - 1); @@ -145,14 +142,10 @@ public function setCurrentContactIndex($index) */ public function toggleSecondContact() { - if ($this->currentContactIndex == 0) - { - if (count($this->contacts) == 2) - { + if ($this->currentContactIndex == 0) { + if (count($this->contacts) == 2) { $this->deleteContact(1); - } - elseif (count($this->contacts) == 1) - { + } elseif (count($this->contacts) == 1) { $this->addContact(); } } @@ -164,8 +157,7 @@ public function toggleSecondContact() */ public function addPhoneForCurrentContact() { - if (count($this->contacts[$this->currentContactIndex]['phones']) < $this->maxContactPhonesCount) - { + if (count($this->contacts[$this->currentContactIndex]['phones']) < $this->maxContactPhonesCount) { $this->contacts[$this->currentContactIndex]['phones'][] = ''; } } @@ -173,22 +165,27 @@ public function updated($propertyName) { $this->status = FormStatus::IN_PROCESS; $this->validateOnly($propertyName); - if ($propertyName === 'complexId') { - $this->dispatch('client_form_complex_updated', complexId: $this->complexId); + foreach ($this->selectedObjects as $complexId => $selectedObject) { + if ($selectedObject == null) { + unset($this->selectedObjects[$complexId]); + } } - try - { + if ($propertyName === 'complexId') { + $this->dispatch('client_form_complex_updated', complexId: $this->complexId); + } + try { $this->validate(); $this->status = FormStatus::READY; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $this->status = FormStatus::IN_PROCESS; } } - #[On('plan7_selector_set_room')] - public function setPlan7Room($room) { - $this->plan7Room = $room; + #[On('plan7_selector_set_room')] + public function setPlan7Room($data) + { + if ($data) { + $this->selectedObjects[$data['complexId']] = $data['room']; + } } public function render() { @@ -211,48 +208,55 @@ public function back() } public function save() + { + $hasErrors = false; + foreach ($this->selectedObjects as $complexId=>$room) { + if ($this->createDeal($complexId, $room)) { + unset($this->selectedObjects[$complexId]); + } else { + $hasErrors = true; + } + } + if ($hasErrors) { + return $this->status = FormStatus::ERROR; + } + $this->status = FormStatus::SUCCESS; + } + + private function createDeal($complexId, $room) { if ( - !$deal = Deal::create([ - 'agent_id' => $this->agentId, - 'complex_id' => $this->complexId, - 'plan7_data' => ($this->plan7Room) ? json_encode($this->plan7Room) : null + 'agent_id' => $this->agentId, + 'complex_id' => $complexId, + 'plan7_data' => ($this->plan7Room) ? json_encode($room) : null ]) - ) - { - $this->status = FormStatus::ERROR; - return; + ) { + return false; } - foreach ($this->contacts as $contact) - { + foreach ($this->contacts as $contact) { if ( !$newUser = Client::updateOrCreate( ['phone' => $contact['phones'][0]], [ - 'name' => trim($contact['firstName'] . ' ' . $contact['secondName']), + 'name' => trim($contact['firstName'] . ' ' . $contact['secondName']), 'phone' => $contact['phones'][0] ] ) - ) - { - $this->status = FormStatus::ERROR; - return; + ) { + return false; } if ( !$dealClient = DealClients::firstOrCreate([ - 'deal_id' => $deal->id, + 'deal_id' => $deal->id, 'client_id' => $newUser->id ]) - ) - { - $this->status = FormStatus::ERROR; - return; + ) { + return false; } } - $this->status = FormStatus::SUCCESS; $this->dispatch('clientCreated'); - + return true; } } \ No newline at end of file diff --git a/app/Modules/ClientCreateForm/Views/livewire/form.blade.php b/app/Modules/ClientCreateForm/Views/livewire/form.blade.php index 476c043..750e5fb 100644 --- a/app/Modules/ClientCreateForm/Views/livewire/form.blade.php +++ b/app/Modules/ClientCreateForm/Views/livewire/form.blade.php @@ -144,22 +144,47 @@ class="bi bi-plus-circle" viewBox="0 0 16 16"> -
-
-
+ @if(count($selectedObjects)) +
+ @foreach($selectedObjects as $selectedComplexId=>$object) + @if(ComplexHasPlan7ApiData($selectedComplexId)) +
+ +
+ @livewire('plan7Selector', [ + 'complexId' => $selectedComplexId + ], + key($selectedComplexId)) +
+
+ @endif + @endforeach +
+ @endif +
@@ -208,7 +233,7 @@ class="bi bi-plus-circle" viewBox="0 0 16 16"> @endif @if ($status != FormStatus::READY) -
+