dialog.blade.php 21.9 KB
@extends('layout.frontend', ['title' => 'Диалог-переписка - РекаМоре'])

@section('scripts')
    <script>
        $(function(){
            var chatbox_div = $('.chatbox__list');
            chatbox_div.scrollTop(chatbox_div.prop("scrollHeight"));

            $('form.chatbox__bottom [name="file"]').on('change', function() {
                var fileName = $(this).val().split('\\').pop();
                $('.chatbox-file-name-wrap').text('Добавлен файл: ' + fileName);
            });
        });

        $(document).on('change', '#send_btn', function() {
            var this_ = $(this);
            var val_ = this_.val();
            console.log('sort items '+val_);

            $.ajax({
                type: "GET",
                url: "{{ route('shipping_companies') }}",
                data: "sort="+val_+"&block=1",
                success: function (data) {
                    console.log('Выбор сортировки');
                    console.log(data);
                    $('#block_1').html(data);
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                error: function (data) {
                    data = JSON.stringify(data);
                    console.log('Error: ' + data);
                }
            });

            $.ajax({
                type: "GET",
                url: "{{ route('shipping_companies') }}",
                data: "sort="+val_+"&block=2",
                success: function (data) {
                    console.log('Выбор сортировки2');
                    console.log(data);
                    history.pushState({}, '', "{{ route('shipping_companies') }}?sort="+val_+"@if (isset($_GET['page']))&page={{ $_GET['page'] }}@endif");
                    $('#block_2').html(data);
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                error: function (data) {
                    data = JSON.stringify(data);
                    console.log('Error: ' + data);
                }
            });
        });
    </script>
@endsection

@section('content')
    <section class="cabinet">
        <div class="container">
            <ul class="breadcrumbs cabinet__breadcrumbs">
                <li><a href="{{ route('index') }}">Главная</a></li>
                <li><b>Личный кабинет</b></li>
            </ul>
            <div class="cabinet__wrapper">
                <div class="cabinet__side">
                    <div class="cabinet__side-toper">
                        @include('employers.emblema')
                    </div>
                    @include('employers.menu', ['item' => 5])
                </div>
                <div class="cabinet__body">
                    <div class="cabinet__body-item">
                        <h2 class="title cabinet__title">Сообщения</h2>
                    </div>
                    <div class="cabinet__body-item">
                        <a href="{{ route('employer.messages', ['type_message' => 'input']) }}" class="back">
                            <svg>
                                <use xlink:href="{{ asset('images/sprite.svg#back') }}"></use>
                            </svg>
                            <span>
                                    К списку чатов
                            </span>
                        </a>
                        <div class="chatbox">
                            <div class="chatbox__toper">
                                @if($chat->is_admin_chat)
                                    <div class="chatbox__toper-info messages__item-info">
                                        @include('svg.logo_icon')
                                        <div class="messages__item-text bold font20">
                                            Администратор сайта
                                        </div>
                                    </div>
                                @elseif ($companion->is_worker)
                                    <div class="chatbox__toper-info messages__item-info">
                                        <div class="messages__item-photo">
                                            <svg>
                                                <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
                                            </svg>
                                            @if ((isset($companion->workers[0]->photo)) &&
                                             (!empty($companion->workers[0]->photo)))
                                                <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($companion->workers[0]->photo)) }}" alt="">
                                            @else
                                                <img src="{{ asset('images/default_man.jpg') }}" alt="">
                                            @endif
                                        </div>
                                        <div class="messages__item-text">
                                            <div>{{ $companion->surname." ".$companion->name_man." ".$companion->surname2." (".$companion->id.")" }} </div>
                                        </div>
                                    </div>
                                    @if (isset($companion->workers[0]->id))
                                    <a href="{{ route('resume_profile', ['worker' => $companion->workers[0]->id]) }}" class="button chatbox__toper-button">
                                        <svg>
                                            <use xlink:href="{{ asset('images/sprite.svg#cabinet-1') }}"></use>
                                        </svg>
                                        Перейти в профиль
                                    </a>
                                    @endif
                                @else
                                    <div class="chatbox__toper-info messages__item-info">
                                        <div class="messages__item-photo">
                                            <svg>
                                                <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
                                            </svg>
                                            @if ((isset($companion->employers[0]->logo)) &&
                                               (!empty($companion->employers[0]->logo)))
                                                <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($companion->employers[0]->logo)) }}" alt="">
                                            @else
                                                <img src="{{ asset('images/default_man.jpg') }}" alt="">
                                            @endif
                                        </div>
                                        <div class="messages__item-text">
                                            <div>{{ $companion->surname." ".$companion->name_man." ".$companion->surname2." (".$companion->id.")" }} </div>
                                            <div><span>Статус:</span> Работодатель или Администратор</div>
                                        </div>
                                    </div>
                                    @if (isset($companion->employer->id))
                                    <a href="" class="button chatbox__toper-button">
                                        <svg>
                                            <use xlink:href="{{ asset('images/sprite.svg#cabinet-1') }}"></use>
                                        </svg>
                                        Перейти в профиль
                                    </a>
                                    @endif
                                @endif
                            </div>

                            @if ($errors->any())
                                <div class="red bold">
                                    <ul>
                                        @foreach ($errors->all() as $error)
                                            <li>{{ $error }}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif

                            <div class="chatbox__list" id="dialogs" name="dialogs">
                                @if ($Messages->count())
                                    @foreach ($Messages as $it)
                                        @if ($it->user_id == $companion->id)
                                            <div class="chatbox__item">
                                                <div class="@if(!$companion->id != $superAdmin->id) chatbox__item-photo @endif ">
                                                    @if(!$companion->id == $superAdmin->id)
                                                        <svg>
                                                            <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
                                                        </svg>
                                                    @endif
                                                    @if($companion->is_worker)
                                                        @if ((isset($companion->workers[0]->photo)) &&
                                                            (!empty($companion->workers[0]->photo)))
                                                            <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($companion->workers[0]->photo)) }}" alt="">
                                                        @else
                                                            <img src="{{ asset('images/default_man.jpg') }}" alt="">
                                                        @endif
                                                    @elseif($companion->id == $superAdmin->id)
                                                        @include('svg.logo_icon')
                                                    @else
                                                        @if ((isset($companion->employers[0]->logo)) &&
                                                        (!empty($companion->employers[0]->logo)))
                                                            <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($companion->employers[0]->logo)) }}" alt="">
                                                        @else
                                                            <div class="chatbox__item-photo ">

                                                                <img src="{{ asset('images/default_man.jpg') }}" alt="">
                                                            </div>

                                                        @endif
                                                    @endif
                                                </div>
                                                <div class="chatbox__item-body">
                                                    @if(\App\Models\Ad_employer::where('id', $it->ad_employer_id)->exists())
                                                        <div class="chatbox__item-text">
                                                            Отклик на вакансию {{ \App\Models\Ad_employer::find($it->ad_employer_id)->name }}
                                                            @if($it->text)
                                                                Комментарий: {{ $it->text }}
                                                            @endif
                                                        </div>
                                                    @else
                                                        @if($it->text)
                                                            <div class="chatbox__item-text">
                                                                {{ $it->text }}
                                                            </div>
                                                        @endif
                                                    @endif
                                                    @if ((isset($it->file)) && (!empty($it->file)))
                                                        <div class="chatbox__item-text chatbox__item-body-file-name-wrap">
                                                            <div class="">
                                                                @if($it->original_file_name)
                                                                    {{ $it->original_file_name }}
                                                                @else
                                                                    <svg>
                                                                        <use xlink:href="{{ asset('images/sprite.svg#clip') }}"></use>
                                                                    </svg>
                                                                @endif
                                                            </div>
                                                            <a href="{{ asset(Storage::url($it->file)) }}" class="">
                                                                Скачать
                                                            </a>
                                                        </div>
                                                    @endif
                                                </div>
                                                <div class="chatbox__item-time">{{ $it->created_at }}</div>
                                            </div>
                                        @else
                                            <div class="chatbox__item chatbox__item_reverse">
                                                <div class="@if($sender->id!=$superAdmin->id) chatbox__item-photo @endif">
                                                    @if ($sender->is_worker)
                                                        @if ((isset($sender->workers[0]->photo)) &&
                                                         (!empty($sender->workers[0]->photo)))
                                                            <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($sender->workers[0]->photo)) }}" alt="">
                                                        @else
                                                            <img src="{{ asset('images/default_man.jpg') }}" alt="">
                                                        @endif
                                                    @elseif($sender->id == $superAdmin->id)
                                                        @include('svg.logo_icon')
                                                    @else
                                                        <svg>
                                                            <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
                                                        </svg>

                                                        @if ((isset($sender->employers[0]->logo)) &&
                                                        (!empty($sender->employers[0]->logo)))
                                                            <img src="{{ asset(\Illuminate\Support\Facades\Storage::url($sender->employers[0]->logo)) }}" alt="">
                                                        @else
                                                            <img src="{{ asset('images/default_man.jpg') }}" alt="">
                                                        @endif
                                                    @endif
                                                </div>
                                                <div class="chatbox__item-body">
                                                    @if($chat->is_admin_chat || $it->text || $it->reply_message_id || $it->ad_employer_id > 0)
                                                        <div class="chatbox__item-text">

                                                    @if($chat->is_admin_chat)
                                                        <button class="button admin-chat-answer" data-fancybox data-src="#answer_from_admin_chat_modal"
                                                            data-to-user-id="{{ $it->user_id }}" data-message-id="{{ $it->id }}"
                                                        >
                                                            Ответить
                                                        </button>
                                                    @endif

                                                            @if(\App\Models\Ad_employer::where('id', $it->ad_employer_id)->exists()))
                                                            <b>Отклик на вакансию</b> "{{ \App\Models\Ad_employer::find($it->ad_employer_id)->name }}"<br>
                                                            @if($it->text)
                                                                <b>Комментарий:</b> {{ $it->text }}
                                                            @endif
                                                            @else
                                                                @if($it->text)
                                                                    {{ $it->text }}
                                                                @endif
                                                            @endif

                                                            @if($it->reply_message_id)
                                                                <div class="reply-message">
                                                                    {{ $it->reply_message->text }}
                                                                </div>
                                                            @endif
                                                        </div>
                                                    @endif
                                                    @if ((isset($it->file)) && (!empty($it->file)))
                                                        <div class="chatbox__item-text chatbox__item-body-file-name-wrap">
                                                            <a href="{{ asset(Storage::url($it->file)) }}" class="">
                                                                Скачать
                                                            </a>
                                                            <div class="">
                                                                @if($it->original_file_name)
                                                                    {{ $it->original_file_name }}
                                                                @else
                                                                    <svg>
                                                                        <use xlink:href="{{ asset('images/sprite.svg#clip') }}"></use>
                                                                    </svg>
                                                                @endif
                                                            </div>
                                                        </div>
                                                    @endif
                                                </div>
                                                <div class="chatbox__item-time">{{ $it->created_at }}</div>
                                            </div>
                                        @endif

                                    @endforeach
                                @endif
                            </div>
                            <div>
                                <form action="{{ route('employer.test123') }}" class="chatbox__bottom" enctype="multipart/form-data" method="POST" >
                                    @csrf
                                    <label class="chatbox__bottom-file">
                                        <input id="file" name="file" type="file" accept=".pdf, .doc, .docx">
                                        <svg>
                                            <use xlink:href="{{ asset('images/sprite.svg#clip') }}"></use>
                                        </svg>
                                    </label>
                                    <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                                    <input type="hidden" id="user_id" name="user_id" value="{{ $sender->id }}"/>
                                    <input type="hidden" id="to_user_id" name="to_user_id" value="{{ $companion->id }}"/>
                                    <input type="hidden" id="ad_employer_id" name="ad_employer_id" value="{{ $ad_employer }}"/>
                                    <input type="hidden" id="ad_name" name="ad_name" value="@if (isset($_GET['ad_name'])){{ $_GET['ad_name'] }} @endif"/>
                                    <input id="text" name="text" type="text" class="input chatbox__bottom-text" placeholder="Ответить">
                                    <button type="submit" id="send_btn" name="send_btn" class="chatbox__bottom-send">
                                        <svg>
                                            <use xlink:href="{{ asset('images/sprite.svg#arrow') }}"></use>
                                        </svg>
                                    </button>
                                </form>
                                <div class="chatbox-file-name-wrap mt-5 fw600"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    </div>
@endsection