edit.blade.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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' => 'order_status_id', 'title' => 'Статус', 'options' => $orderStatuses, 'value' => $order->order_status_id ?? old('order_status_id'), 'required' => true])
  12. @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'value' => $order?->district_id ?? old('district_id'), 'first_empty' => true, 'required' => true, 'disabled' => !hasRole('admin')])
  13. @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'value' => $order?->area_id ?? old('area_id'), 'required' => true, 'first_empty' => true, 'disabled' => !hasRole('admin')])
  14. @include('partials.input', ['name' => 'object_address', 'title' => 'Адрес объекта', 'value' => $order->object_address ?? old('object_address'), 'required' => true, 'disabled' => !hasRole('admin')])
  15. @include('partials.input', ['name' => 'name', 'title' => 'Название', 'value' => $order->name ?? old('name'), 'required' => true, 'disabled' => !hasRole('admin')])
  16. @include('partials.select', ['name' => 'object_type_id', 'title' => 'Тип объекта', 'options' => $objectTypes, 'value' => $order->object_type_id ?? old('object_type_id'), 'required' => true, 'first_empty' => true, 'disabled' => !hasRole('admin')])
  17. @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий', 'value' => $order->comment ?? old('comment')])
  18. @include('partials.input', ['name' => 'installation_date', 'title' => 'Дата выхода на монтаж', 'type' => 'date', 'value' => $order->installation_date ?? old('installation_date'), 'disabled' => !hasRole('admin')])
  19. @include('partials.input', ['name' => 'install_days', 'title' => 'Дней на монтаж', 'type' => 'number', 'min' => 1, 'value' => $order->install_days ?? old('install_days'), 'disabled' => !hasRole('admin')])
  20. @include('partials.input', ['name' => 'ready_date', 'title' => 'Дата готовности площадки', 'type' => 'date', 'value' => $order->ready_date ?? old('ready_date'), 'disabled' => !hasRole('admin')])
  21. @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'value' => $order->brigadier_id ?? old('brigadier_id'), 'first_empty' => true, 'disabled' => !hasRole('admin')])
  22. @include('partials.select', ['name' => 'user_id', 'title' => 'Менеджер', 'options' => $users, 'value' => $order->user_id ?? old('user_id') ?? auth()->user()->id, 'disabled' => !hasRole('admin')])
  23. @include('partials.input', ['name' => 'tg_group_name', 'title' => 'Название группы в ТГ', 'value' => $order->tg_group_name ?? old('tg_group_name')])
  24. @include('partials.input', ['name' => 'tg_group_link', 'title' => 'Ссылка на группу в ТГ', 'value' => $order->tg_group_link ?? old('tg_group_link')])
  25. </div>
  26. <div class="col-xxl-6">
  27. @php
  28. $hasAttachedMaf = isset($order) && $order->products_sku->contains(fn ($sku) => !empty($sku->maf_order_id));
  29. @endphp
  30. <h4>МАФ</h4>
  31. <div>
  32. <input type="text" class="form-control mb-2" @disabled((($order->order_status_id ?? 0) > 1) || !hasRole('admin') || $hasAttachedMaf) placeholder="Поиск номенклатуры" id="search_maf">
  33. <select id="select_maf" class="form-select mb-3" multiple @disabled((($order->order_status_id ?? 0) > 1) || !hasRole('admin') || $hasAttachedMaf)></select>
  34. @if($hasAttachedMaf)
  35. <div class="small text-warning mb-2">Добавление новых позиций МАФ недоступно, пока есть привязанные МАФ.</div>
  36. @endif
  37. </div>
  38. <div id="selected_maf">
  39. @isset($order)
  40. <div class="changes-message small text-warning visually-hidden">* необходимо сохранить изменения</div>
  41. @endisset
  42. @if(isset($order) && $order->products_sku)
  43. @foreach($order->products_sku as $p)
  44. <div class="maf d-flex justify-content-between mb-1">
  45. <div>
  46. <input type="hidden" class="visually-hidden" name="products_sku[]" value="{{ $p->id }}">
  47. <input type="hidden" class="visually-hidden" name="products[]" value="{{ $p->product->id }}">
  48. <div class="p-1">{!! $p->product->common_name !!}</div>
  49. </div>
  50. <div class="col-1 d-flex justify-content-end">
  51. <div>
  52. <input @disabled((($order->order_status_id ?? 0) > 1) || !hasRole('admin')) class="form-control text-end form-control-sm quantity" type="number" name="quantity[]" value="1" @disabled($order->order_status_id > 1)>
  53. </div>
  54. <div class="p-1">
  55. @if(($order->order_status_id == 1) && hasRole('admin') && !$p->maf_order_id)
  56. <i onclick="$(this).parent().parent().parent().remove(); $('.changes-message').removeClass('visually-hidden');" class="bi bi-trash text-danger cursor-pointer"></i>
  57. @elseif($p->maf_order_id)
  58. <i class="bi bi-lock text-secondary" title="Привязанный МАФ нельзя удалить"></i>
  59. @endif
  60. </div>
  61. </div>
  62. </div>
  63. @endforeach
  64. @endif
  65. </div>
  66. </div>
  67. <div class="col-12 text-end">
  68. @include('partials.submit')
  69. </div>
  70. </form>
  71. </div>
  72. @endsection
  73. @push('scripts')
  74. <script type="module">
  75. $('#select_maf').on('change', function () {
  76. $('#selected_maf').append(
  77. '<div class="maf d-flex justify-content-between mb-1">' +
  78. '<div>' +
  79. '<input type="hidden" name="products[]" value="'+ $(this).val() +'">' +
  80. '<div class="p-1">'+ $('#select_maf option:selected').text() +'</div> ' +
  81. '</div>' +
  82. '<div class="col-1 d-flex justify-content-end">' +
  83. '<div>' +
  84. '<input class="form-control text-end form-control-sm quantity" type="number" name="quantity[]" value="1">' +
  85. '</div>' +
  86. '<div class="p-1">' +
  87. '<i onclick="$(this).parent().parent().parent().remove();" class="bi bi-trash text-danger cursor-pointer"></i>' +
  88. '</div>' +
  89. '</div>'
  90. );
  91. $('#select_maf').children().remove();
  92. $('#search_maf').val('');
  93. $('.changes-message').removeClass('visually-hidden');
  94. });
  95. $('#district_id').on('change', function () {
  96. // load areas of selected district
  97. $.get('{{ route('area.ajax-get-areas-by-district') }}/' + $(this).val(),
  98. function (data) {
  99. $('#area_id').children().remove();
  100. $.each(data, function (id, name) {
  101. $('#area_id').append('<option value=\'' + id + '\'>' + name + '</option>');
  102. });
  103. }
  104. );
  105. });
  106. </script>
  107. @endpush