обновлена форма добавления клиентов: сделан выбор нескольких жк
This commit is contained in:
parent
e7a11d356c
commit
ee64915afc
@ -21,8 +21,8 @@ class ClientCreateLivewire extends Component
|
|||||||
public $complexes;
|
public $complexes;
|
||||||
public $maxContactsCount;
|
public $maxContactsCount;
|
||||||
public $maxContactPhonesCount;
|
public $maxContactPhonesCount;
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
|
public $selectedObjects = [];
|
||||||
public $agentId;
|
public $agentId;
|
||||||
public $contacts;
|
public $contacts;
|
||||||
public $objects = [];
|
public $objects = [];
|
||||||
@ -40,7 +40,7 @@ protected function rules()
|
|||||||
'contacts.*.firstName' => ['required', 'string', 'max:50'],
|
'contacts.*.firstName' => ['required', 'string', 'max:50'],
|
||||||
'contacts.*.secondName' => ['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})/',
|
'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'],
|
'selectedObjects' => 'required',
|
||||||
'agentId' => ['required'],
|
'agentId' => ['required'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -53,6 +53,7 @@ protected function messages()
|
|||||||
'contacts.*.secondName.max' => 'Указанное имя клиента слишком длинное',
|
'contacts.*.secondName.max' => 'Указанное имя клиента слишком длинное',
|
||||||
'contacts.*.phones.*.reqired' => 'Необходимо указать номер телефона клиента',
|
'contacts.*.phones.*.reqired' => 'Необходимо указать номер телефона клиента',
|
||||||
'contacts.*.phones.*.regex' => 'Указанный номер телефона некорректный',
|
'contacts.*.phones.*.regex' => 'Указанный номер телефона некорректный',
|
||||||
|
'selectedObjects.required' => 'Необходимо выбрать хотя бы один интересующий ЖК',
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -63,23 +64,23 @@ public function mount()
|
|||||||
$this->availableAgents = GetAvailableAgents();
|
$this->availableAgents = GetAvailableAgents();
|
||||||
$this->maxContactPhonesCount = 1;
|
$this->maxContactPhonesCount = 1;
|
||||||
$this->contacts = [];
|
$this->contacts = [];
|
||||||
|
$this->contactLabels = ['Основной контакт', 'Супруг/супруга'];
|
||||||
|
|
||||||
if( array_key_exists('contact_form_count_max', DESIGN_PARAMETERS) && (int)DESIGN_PARAMETERS['contact_form_count_max'] > 0) {
|
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'];
|
$this->maxContactsCount = (int) DESIGN_PARAMETERS['contact_form_count_max'];
|
||||||
} else {
|
} else {
|
||||||
$this->maxContactsCount = 2;
|
$this->maxContactsCount = 2;
|
||||||
};
|
}
|
||||||
|
|
||||||
if( array_key_exists('contact_form_count', DESIGN_PARAMETERS) && (int)DESIGN_PARAMETERS['contact_form_count'] > 0) {
|
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++) {
|
for ($tabsCount = 1; $tabsCount <= (int) DESIGN_PARAMETERS['contact_form_count']; $tabsCount++) {
|
||||||
$this->addContact();
|
$this->addContact();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->addContact();
|
$this->addContact();
|
||||||
$this->addContact();//по-умолчанию сразу выводить супруга
|
$this->addContact();//по-умолчанию сразу выводить супруга
|
||||||
};
|
}
|
||||||
|
|
||||||
$this->contactLabels = ['Основной контакт', 'Супруг/супруга'];
|
|
||||||
if (count($this->availableAgents) == 1) //чтобы не выводить в форму
|
if (count($this->availableAgents) == 1) //чтобы не выводить в форму
|
||||||
{ //и не заставлять пользователя указывать вручную
|
{ //и не заставлять пользователя указывать вручную
|
||||||
$this->agentId = $this->availableAgents[0]['id'];
|
$this->agentId = $this->availableAgents[0]['id'];
|
||||||
@ -95,12 +96,10 @@ public function mount()
|
|||||||
*/
|
*/
|
||||||
public function addContact()
|
public function addContact()
|
||||||
{
|
{
|
||||||
if (!isset($this->contacts))
|
if (!isset($this->contacts)) {
|
||||||
{
|
|
||||||
$this->contacts = [];
|
$this->contacts = [];
|
||||||
}
|
}
|
||||||
if ($this->maxContactsCount > count($this->contacts))
|
if ($this->maxContactsCount > count($this->contacts)) {
|
||||||
{
|
|
||||||
$this->contacts[] = [
|
$this->contacts[] = [
|
||||||
'firstName' => '',
|
'firstName' => '',
|
||||||
'secondName' => '',
|
'secondName' => '',
|
||||||
@ -117,12 +116,10 @@ public function addContact()
|
|||||||
*/
|
*/
|
||||||
public function deleteContact($index = false)
|
public function deleteContact($index = false)
|
||||||
{
|
{
|
||||||
if ($index === false)
|
if ($index === false) {
|
||||||
{
|
|
||||||
$index = $this->currentContactIndex;
|
$index = $this->currentContactIndex;
|
||||||
}
|
}
|
||||||
if ($index > 0)
|
if ($index > 0) {
|
||||||
{
|
|
||||||
unset($this->contacts[$index]);
|
unset($this->contacts[$index]);
|
||||||
$this->contacts = array_values($this->contacts);
|
$this->contacts = array_values($this->contacts);
|
||||||
$this->setCurrentContactIndex($index - 1);
|
$this->setCurrentContactIndex($index - 1);
|
||||||
@ -145,14 +142,10 @@ public function setCurrentContactIndex($index)
|
|||||||
*/
|
*/
|
||||||
public function toggleSecondContact()
|
public function toggleSecondContact()
|
||||||
{
|
{
|
||||||
if ($this->currentContactIndex == 0)
|
if ($this->currentContactIndex == 0) {
|
||||||
{
|
if (count($this->contacts) == 2) {
|
||||||
if (count($this->contacts) == 2)
|
|
||||||
{
|
|
||||||
$this->deleteContact(1);
|
$this->deleteContact(1);
|
||||||
}
|
} elseif (count($this->contacts) == 1) {
|
||||||
elseif (count($this->contacts) == 1)
|
|
||||||
{
|
|
||||||
$this->addContact();
|
$this->addContact();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,8 +157,7 @@ public function toggleSecondContact()
|
|||||||
*/
|
*/
|
||||||
public function addPhoneForCurrentContact()
|
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'][] = '';
|
$this->contacts[$this->currentContactIndex]['phones'][] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,22 +165,27 @@ public function updated($propertyName)
|
|||||||
{
|
{
|
||||||
$this->status = FormStatus::IN_PROCESS;
|
$this->status = FormStatus::IN_PROCESS;
|
||||||
$this->validateOnly($propertyName);
|
$this->validateOnly($propertyName);
|
||||||
|
foreach ($this->selectedObjects as $complexId => $selectedObject) {
|
||||||
|
if ($selectedObject == null) {
|
||||||
|
unset($this->selectedObjects[$complexId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($propertyName === 'complexId') {
|
if ($propertyName === 'complexId') {
|
||||||
$this->dispatch('client_form_complex_updated', complexId: $this->complexId);
|
$this->dispatch('client_form_complex_updated', complexId: $this->complexId);
|
||||||
}
|
}
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$this->validate();
|
$this->validate();
|
||||||
$this->status = FormStatus::READY;
|
$this->status = FormStatus::READY;
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
catch (\Exception $e)
|
|
||||||
{
|
|
||||||
$this->status = FormStatus::IN_PROCESS;
|
$this->status = FormStatus::IN_PROCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[On('plan7_selector_set_room')]
|
#[On('plan7_selector_set_room')]
|
||||||
public function setPlan7Room($room) {
|
public function setPlan7Room($data)
|
||||||
$this->plan7Room = $room;
|
{
|
||||||
|
if ($data) {
|
||||||
|
$this->selectedObjects[$data['complexId']] = $data['room'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
@ -212,21 +209,33 @@ public function back()
|
|||||||
|
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
if (
|
$hasErrors = false;
|
||||||
|
foreach ($this->selectedObjects as $complexId=>$room) {
|
||||||
!$deal = Deal::create([
|
if ($this->createDeal($complexId, $room)) {
|
||||||
'agent_id' => $this->agentId,
|
unset($this->selectedObjects[$complexId]);
|
||||||
'complex_id' => $this->complexId,
|
} else {
|
||||||
'plan7_data' => ($this->plan7Room) ? json_encode($this->plan7Room) : null
|
$hasErrors = true;
|
||||||
])
|
}
|
||||||
)
|
}
|
||||||
{
|
if ($hasErrors) {
|
||||||
$this->status = FormStatus::ERROR;
|
return $this->status = FormStatus::ERROR;
|
||||||
return;
|
}
|
||||||
|
$this->status = FormStatus::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->contacts as $contact)
|
private function createDeal($complexId, $room)
|
||||||
{
|
{
|
||||||
|
if (
|
||||||
|
!$deal = Deal::create([
|
||||||
|
'agent_id' => $this->agentId,
|
||||||
|
'complex_id' => $complexId,
|
||||||
|
'plan7_data' => ($this->plan7Room) ? json_encode($room) : null
|
||||||
|
])
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->contacts as $contact) {
|
||||||
if (
|
if (
|
||||||
!$newUser = Client::updateOrCreate(
|
!$newUser = Client::updateOrCreate(
|
||||||
['phone' => $contact['phones'][0]],
|
['phone' => $contact['phones'][0]],
|
||||||
@ -235,24 +244,19 @@ public function save()
|
|||||||
'phone' => $contact['phones'][0]
|
'phone' => $contact['phones'][0]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
) {
|
||||||
{
|
return false;
|
||||||
$this->status = FormStatus::ERROR;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!$dealClient = DealClients::firstOrCreate([
|
!$dealClient = DealClients::firstOrCreate([
|
||||||
'deal_id' => $deal->id,
|
'deal_id' => $deal->id,
|
||||||
'client_id' => $newUser->id
|
'client_id' => $newUser->id
|
||||||
])
|
])
|
||||||
)
|
) {
|
||||||
{
|
return false;
|
||||||
$this->status = FormStatus::ERROR;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->status = FormStatus::SUCCESS;
|
|
||||||
$this->dispatch('clientCreated');
|
$this->dispatch('clientCreated');
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,14 +144,16 @@ class="bi bi-plus-circle" viewBox="0 0 16 16">
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group d-none">
|
<div class="btn-group w-100">
|
||||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
|
<button class="btn btn-light d-flex justify-content-between rounded-4 p-3 align-items-center dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
|
||||||
Выберите жилой комплекс
|
Выберите жилой комплекс
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
@foreach ($complexes as $complex)
|
@foreach ($complexes as $complex)
|
||||||
<li><div class="dropdown-item"><input class="form-check-input" type="checkbox" value="" id="checkDefault">
|
<li>
|
||||||
<label class="form-check-label" for="checkDefault">
|
<div class="dropdown-item">
|
||||||
|
<input wire:model.live="selectedObjects.{{ $complex['id'] }}" class="form-check-input" type="checkbox" id="complex_selector_{{ $complex['id'] }}">
|
||||||
|
<label class="form-check-label" for="complex_selector_{{ $complex['id'] }}">
|
||||||
{{ $complex['name'] }}
|
{{ $complex['name'] }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@ -159,7 +161,30 @@ class="bi bi-plus-circle" viewBox="0 0 16 16">
|
|||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-floating mb-2">
|
@if(count($selectedObjects))
|
||||||
|
<div class="d-flex flex-column gap-2 rounded-bottom-4 p-2" style="padding-top:25px!important;margin-top:-20px;background-color: #ffffff3b;">
|
||||||
|
@foreach($selectedObjects as $selectedComplexId=>$object)
|
||||||
|
@if(ComplexHasPlan7ApiData($selectedComplexId))
|
||||||
|
<div class="px-2 py-1 bg-light border border-1 rounded-4 bg-light">
|
||||||
|
<label for="complexId">Помещение в ЖК
|
||||||
|
@foreach ($complexes as $complex)
|
||||||
|
@if($complex['id'] == $selectedComplexId)
|
||||||
|
{{ $complex['name'] }}
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</label>
|
||||||
|
<div>
|
||||||
|
@livewire('plan7Selector', [
|
||||||
|
'complexId' => $selectedComplexId
|
||||||
|
],
|
||||||
|
key($selectedComplexId))
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<div class="d-none form-floating mb-2">
|
||||||
<select wire:model.live="complexId" class="form-select rounded-4 @error('complexId') is-invalid @enderror"
|
<select wire:model.live="complexId" class="form-select rounded-4 @error('complexId') is-invalid @enderror"
|
||||||
id="complexId" name="complexId" aria-label="Жилой комплекс">
|
id="complexId" name="complexId" aria-label="Жилой комплекс">
|
||||||
<option selected></option>
|
<option selected></option>
|
||||||
@ -175,8 +200,8 @@ class="bi bi-plus-circle" viewBox="0 0 16 16">
|
|||||||
<strong>{{ $message }}</strong>
|
<strong>{{ $message }}</strong>
|
||||||
</span>
|
</span>
|
||||||
@enderror
|
@enderror
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if($complexId && ComplexHasPlan7ApiData($complexId))
|
@if($complexId && ComplexHasPlan7ApiData($complexId))
|
||||||
<div class="p-2 bg-light border border-1 rounded-4 mb-3 bg-light">
|
<div class="p-2 bg-light border border-1 rounded-4 mb-3 bg-light">
|
||||||
<label for="complexId">Помещение</label>
|
<label for="complexId">Помещение</label>
|
||||||
@ -188,7 +213,7 @@ class="bi bi-plus-circle" viewBox="0 0 16 16">
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@if (count($availableAgents) > 1)
|
@if (count($availableAgents) > 1)
|
||||||
<div class="form-floating mb-3">
|
<div class="mt-3 form-floating mb-3">
|
||||||
<select wire:model.live="agentId" class="form-select rounded-4 @error('agentId') is-invalid @enderror"
|
<select wire:model.live="agentId" class="form-select rounded-4 @error('agentId') is-invalid @enderror"
|
||||||
id="agentId" name="agent" aria-label="Агент">
|
id="agentId" name="agent" aria-label="Агент">
|
||||||
<option selected></option>
|
<option selected></option>
|
||||||
@ -208,7 +233,7 @@ class="bi bi-plus-circle" viewBox="0 0 16 16">
|
|||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($status != FormStatus::READY)
|
@if ($status != FormStatus::READY)
|
||||||
<div class="">
|
<div class="d-none">
|
||||||
<button disabled class="btn btn-secondary disabled rounded-4 fw-bold fs-5 w-100 py-3"
|
<button disabled class="btn btn-secondary disabled rounded-4 fw-bold fs-5 w-100 py-3"
|
||||||
style="background-color: #20184d;">
|
style="background-color: #20184d;">
|
||||||
Создать нового клиента
|
Создать нового клиента
|
||||||
|
|||||||
@ -80,11 +80,15 @@ public function setHouse($id)
|
|||||||
public function setRoom($id)
|
public function setRoom($id)
|
||||||
{
|
{
|
||||||
$this->room = $this->allObjects['data'][$id];
|
$this->room = $this->allObjects['data'][$id];
|
||||||
$this->dispatch('plan7_selector_set_room', room: $this->room);
|
$data = [
|
||||||
|
'complexId' => $this->complexId,
|
||||||
|
'room' => $this->room
|
||||||
|
];
|
||||||
|
$this->dispatch('plan7_selector_set_room', data: $data);
|
||||||
}
|
}
|
||||||
public function unsetRoom() {
|
public function unsetRoom() {
|
||||||
$this->room = false;
|
$this->room = false;
|
||||||
$this->dispatch('plan7_selector_set_room', room: false);
|
$this->dispatch('plan7_selector_set_room', data: false);
|
||||||
}
|
}
|
||||||
public function resetFilter() {
|
public function resetFilter() {
|
||||||
$this->filter = [];
|
$this->filter = [];
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
@endif
|
@endif
|
||||||
<div>
|
<div>
|
||||||
<button type="button" class="btn btn-primary" wire:click="start()" wire:loading.class="opacity-50" wire:target="load" class="btn btn-primary"
|
<button type="button" class="btn btn-primary" wire:click="start()" wire:loading.class="opacity-50" wire:target="load" class="btn btn-primary"
|
||||||
onclick="plan7SelectorModal = new bootstrap.Modal(document.getElementById('plan7_selector_modal'), {});plan7SelectorModal.show()">
|
onclick="plan7SelectorModal = new bootstrap.Modal(document.getElementById('plan7_selector_modal_{{ $complexId }}'), {});plan7SelectorModal.show()">
|
||||||
@if($room)
|
@if($room)
|
||||||
Изменить
|
Изменить
|
||||||
@else
|
@else
|
||||||
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
<div class="modal fade" wire:ignore.self id="plan7_selector_modal" tabindex="-1"
|
<div class="modal fade" wire:ignore.self id="plan7_selector_modal_{{ $complexId }}" tabindex="-1"
|
||||||
aria-labelledby="exampleModalLabel" aria-hidden="true">
|
aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-dialog-scrollable modal-xl modal-fullscreen-lg-down">
|
<div class="modal-dialog modal-dialog-scrollable modal-xl modal-fullscreen-lg-down">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
|
|||||||
@ -46,8 +46,8 @@ class="btn list-group-item list-group-item-action p-3 bg-white rounded border bo
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-lg-6">
|
<div class="form-wrap col-12 col-lg-6">
|
||||||
<div class="p-2 px-sm-4 py-sm-3 bg-primary border rounded-3 mx-auto h-100" style="">
|
<div class="form-wrap__inner p-2 px-sm-4 py-sm-3 bg-primary border rounded-3 mx-auto" style="">
|
||||||
<div class="h4 pb-2 mb-2 fw-bold d-flex flex-column">
|
<div class="h4 pb-2 mb-2 fw-bold d-flex flex-column">
|
||||||
<small>Добавить клиента</small>
|
<small>Добавить клиента</small>
|
||||||
</div>
|
</div>
|
||||||
@ -57,6 +57,24 @@ class="btn list-group-item list-group-item-action p-3 bg-white rounded border bo
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
<style>
|
||||||
|
.form-wrap {
|
||||||
|
position: relative;
|
||||||
|
min-height:450px;
|
||||||
|
max-height: 600px;
|
||||||
|
overflow: visible; /* чтобы нижняя часть могла выйти наружу */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-wrap__inner {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
min-height: 100%;
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<div class="fs-5 fw-bold">Новости</div>
|
<div class="fs-5 fw-bold">Новости</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user