edit.blade.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. @extends('layouts.app')
  2. @section('content')
  3. <div class="px-3">
  4. <form class="row" action="{{ route('order.store') }}" method="post">
  5. <div class="col-xxl-6">
  6. <h4>Общая информация об объекте</h4>
  7. @csrf
  8. @if(isset($order))
  9. <input type="hidden" name="id" value="{{ $order->id }}">
  10. @endif
  11. @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'value' => $order?->district_id ?? old('district_id'), 'first_empty' => true, 'required' => true])
  12. @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'value' => $order?->area_id ?? old('area_id'), 'required' => true, 'first_empty' => true])
  13. @include('partials.input', ['name' => 'object_address', 'title' => 'Адрес объекта', 'value' => $order->object_address ?? old('object_address'), 'required' => true])
  14. @include('partials.select', ['name' => 'object_type_id', 'title' => 'Тип объекта', 'options' => $objectTypes, 'value' => $order->object_type_id ?? old('object_type_id'), 'required' => true, 'first_empty' => true])
  15. @include('partials.select', ['name' => 'order_status_id', 'title' => 'Статус', 'options' => $orderStatuses, 'value' => $order->order_status_id ?? old('order_status_id'), 'required' => true])
  16. @include('partials.input', ['name' => 'contract_date', 'title' => 'Дата договора', 'type' => 'date', 'value' => $order->contract_date ?? old('contract_date')])
  17. @include('partials.input', ['name' => 'contract_number', 'title' => 'Номер договора', 'value' => $order->contract_number ?? old('contract_number')])
  18. @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий', 'value' => $order->comment ?? old('comment')])
  19. @include('partials.input', ['name' => 'installation_date', 'title' => 'Дата выхода на монтаж', 'type' => 'date', 'value' => $order->installation_date ?? old('installation_date')])
  20. @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'value' => $order->brigadier_id ?? old('brigadier_id')])
  21. @include('partials.select', ['name' => 'user_id', 'title' => 'Менеджер', 'options' => $users, 'value' => $order->user_id ?? old('user_id') ?? auth()->user()->id])
  22. @include('partials.input', ['name' => 'tg_group_name', 'title' => 'Название группы в ТГ', 'value' => $order->tg_group_name ?? old('tg_group_name')])
  23. @include('partials.input', ['name' => 'tg_group_link', 'title' => 'Ссылка на группу в ТГ', 'value' => $order->tg_group_link ?? old('tg_group_link')])
  24. </div>
  25. <div class="col-xxl-6">
  26. <h4>МАФ</h4>
  27. <div>
  28. <input type="text" class="form-control mb-2" placeholder="Поиск номенклатуры" id="search_maf">
  29. <select id="select_maf" class="form-select mb-3" multiple></select>
  30. </div>
  31. <div id="selected_maf">
  32. @isset($order)
  33. <div class="changes-message small text-warning visually-hidden">* необходимо сохранить изменения</div>
  34. @endisset
  35. @if(isset($order) && $order->products)
  36. @foreach($order->products as $p)
  37. <div class="maf d-flex justify-content-between mb-1">
  38. <input type="hidden" class="visually-hidden" name="products[]" value="{{ $p->id }}">
  39. <div>{!! $p->common_name !!}</div>
  40. <i onclick="$(this).parent().remove(); $('.changes-message').removeClass('visually-hidden');" class="bi bi-trash text-danger cursor-pointer"></i>
  41. </div>
  42. @endforeach
  43. @endif
  44. </div>
  45. </div>
  46. <div class="col-12 text-end">
  47. @include('partials.submit')
  48. </div>
  49. </form>
  50. </div>
  51. @if($errors->any())
  52. @dump($errors->all())
  53. @endif
  54. @endsection
  55. @push('scripts')
  56. <script type="module">
  57. let selectMaf = $('#select_maf');
  58. $('#search_maf').on('keyup', function () {
  59. // search products on backend
  60. $.get('{{ route('product.search') }}?s=' + $(this).val(),
  61. function (data) {
  62. selectMaf.children().remove()
  63. $.each(data, function (id, name) {
  64. selectMaf.append('<option value=\'' + id + '\'>' + name + '</option>');
  65. });
  66. }
  67. );
  68. });
  69. selectMaf.on('change', function () {
  70. $('#selected_maf').append(
  71. '<div class="maf d-flex justify-content-between mb-1">' +
  72. '<input type="hidden" name="products[]" value="'+ $(this).val() +'">' +
  73. '<div>'+ $('#select_maf option:selected').text() +'</div> ' +
  74. '<i onclick="$(this).parent().remove();" class="bi bi-trash text-danger cursor-pointer"></i>' +
  75. '</div>'
  76. );
  77. $('#select_maf').children().remove();
  78. $('#search_maf').val('');
  79. $('.changes-message').removeClass('visually-hidden');
  80. });
  81. $('#district_id').on('change', function () {
  82. // load areas of selected district
  83. console.log($(this).val());
  84. $.get('{{ route('area.ajax-get-areas-by-district') }}/' + $(this).val(),
  85. function (data) {
  86. $('#area_id').children().remove();
  87. $.each(data, function (id, name) {
  88. $('#area_id').append('<option value=\'' + id + '\'>' + name + '</option>');
  89. });
  90. }
  91. );
  92. });
  93. </script>
  94. @endpush