table.blade.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <div class="table-responsive">
  2. <div class="table-buttons py-2 bg-primary rounded-start d-flex flex-column ">
  3. <button type="button" class="btn btn-sm text-white" data-bs-toggle="modal"
  4. data-bs-target="#table_{{ $id }}_modal_search">
  5. <i class="bi bi-search-heart @if(request()->has('s')) text-danger @endif"></i>
  6. </button>
  7. <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
  8. data-bs-target="#table_{{ $id }}_modal_filters">
  9. <i class="bi bi-funnel-fill @if(request()->has('filters')) text-danger @endif"></i>
  10. </button>
  11. <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
  12. data-bs-target="#table_{{ $id }}_modal_settings">
  13. <i class="bi bi-gear-fill"></i>
  14. </button>
  15. </div>
  16. <table class="table" id="tbl" data-table-name="{{ $id }}" style="display: none; min-height: 380px;">
  17. <thead>
  18. <tr>
  19. @foreach($header as $headerName => $headerTitle)
  20. <th scope="col" class="bg-primary-subtle column_{{ $headerName }}">
  21. <div class="d-flex align-items-center justify-content-between">
  22. <div class="cursor-pointer sort-by-column" data-name="{{ $headerName }}">
  23. {{ $headerTitle }}
  24. </div>
  25. <div class="text-center mx-1 cursor-pointer" data-name="{{ $headerName }}">
  26. @if(($headerName== $sortBy))
  27. @if($orderBy === 'asc')
  28. <i class="bi bi-arrow-down-square-fill text-primary"></i>
  29. @else
  30. <i class="bi bi-arrow-up-square-fill text-primary"></i>
  31. @endif
  32. @endif
  33. </div>
  34. @if($headerName !== 'image')
  35. @php
  36. $type = null;
  37. $data = (array_merge($filters, $ranges, $dates))[$headerName] ?? null;
  38. if (isset($filters[$headerName])) {
  39. $type = 'filters';
  40. } elseif (isset($ranges[$headerName])) {
  41. // Для dropdown фильтров вместо диапазона используем список всех вариантов
  42. $type = 'filters';
  43. } elseif (isset($dates[$headerName])) {
  44. $type = 'dates';
  45. }
  46. @endphp
  47. <div class="text-end cursor-pointer dropdown" data-bs-auto-close="outside" aria-expanded="false">
  48. <i
  49. data-bs-auto-close="outside"
  50. aria-expanded="false"
  51. data-bs-toggle="dropdown"
  52. class="dropdown-toggle bi
  53. @if(isset(request()->filters[$headerName]) ||
  54. isset(request()->filters[str_replace('_txt', '', $headerName) . '_from']) ||
  55. isset(request()->filters[str_replace('_txt', '', $headerName) . '_to'])
  56. )
  57. bi-funnel-fill text-danger
  58. @else
  59. bi-funnel
  60. @endif
  61. " id="{{$headerName}}"></i>
  62. @include('partials.newFilterElement', ['id' => $headerName, 'data' => $data, 'type' => $type, 'table' => $id, 'isSort' => $headerName == $sortBy, '$orderBy' => $orderBy])
  63. </div>
  64. @endif
  65. </div>
  66. </th>
  67. @endforeach
  68. </tr>
  69. </thead>
  70. <tbody>
  71. @foreach($strings as $string)
  72. <tr>
  73. @foreach($header as $headerName => $headerTitle)
  74. <td class="column_{{$headerName}}"
  75. @if(isset($routeName)
  76. && !str_contains($headerName, 'image')
  77. && !str_contains($headerName, 'order_status_name')
  78. && !($id === 'reclamations' && $headerName === 'status_name'))
  79. onclick="location.href='{{ route($routeName, $string->id) }}'"
  80. @endif>
  81. @if(str_contains($headerName, '-'))
  82. @php
  83. list($rel, $field) = explode('-', $headerName);
  84. @endphp
  85. @if(isset($string->$rel->$field))
  86. @if(str_ends_with($field, '_id'))
  87. @php
  88. $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $field));
  89. @endphp
  90. {!! $string->$rel->$relation?->name; !!}
  91. @else
  92. @if(str_contains($field, 'image') && $string->$rel->$field)
  93. <a href="{{ $string->$rel->$field }}" data-toggle="lightbox"
  94. data-gallery="photos" data-size="fullscreen">
  95. <img src="{{ $string->$rel->$field }}" alt="" class="img-thumbnail maf-img">
  96. </a>
  97. @else
  98. {!! $string->$rel->$field !!}
  99. @endif
  100. @endif
  101. @else
  102. <ul class="small mb-0 list-group list-group-flush bg-secondary">
  103. @foreach($string->$rel ?? [] as $item)
  104. <li class="list-group-item py-0 bg-body-secondary">
  105. {!! $item->$field !!}
  106. </li>
  107. @endforeach
  108. </ul>
  109. @endif
  110. @elseif(str_ends_with($headerName, '_id'))
  111. @php
  112. $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $headerName));
  113. @endphp
  114. @if($headerName == 'order_status_id')
  115. <div class="badge fs-5 text-bg-{{ App\Models\Order::STATUS_COLOR[$string->order_status_id] }}">{{ $string->$relation?->name }}</div>
  116. @else
  117. {!! $string->$relation?->name; !!}
  118. @endif
  119. @elseif(str_ends_with($headerName, '_date') && ($string->$headerName))
  120. {{ \App\Helpers\DateHelper::getHumanDate($string->$headerName, true) }}
  121. @elseif(str_contains($headerName, 'image') && $string->$headerName)
  122. <a href="{{ $string->$headerName }}" data-toggle="lightbox" data-gallery="photos"
  123. data-size="fullscreen">
  124. <img src="{{ $string->$headerName }}" alt="" class="img-thumbnail maf-img">
  125. </a>
  126. @elseif(str_contains($headerName, 'order_status_name'))
  127. <select name="order_status_name" data-order-id="{{ $string->id }}" @disabled(!hasRole('admin,manager')) class="change-order-status form-control form-control-sm" >
  128. @foreach($statuses as $statusId => $statusName)
  129. <option value="{{ $statusId }}" @selected($statusName == $string->$headerName)>{{ $statusName }}</option>
  130. @endforeach
  131. </select>
  132. @elseif($id === 'reclamations' && $headerName === 'status_name')
  133. <select name="status_id"
  134. data-reclamation-id="{{ $string->id }}"
  135. data-url="{{ route('reclamations.update-status', $string->id) }}"
  136. @disabled(!hasRole('admin,manager'))
  137. class="change-reclamation-status form-control form-control-sm">
  138. @foreach($statuses as $statusId => $statusName)
  139. <option value="{{ $statusId }}" @selected($statusId == $string->status_id)>{{ $statusName }}</option>
  140. @endforeach
  141. </select>
  142. @elseif($headerName === 'tsn_number' && $string->$headerName)
  143. <span data-bs-toggle="tooltip"
  144. data-bs-placement="top"
  145. title="{{ $string->tsn_number_description ?? 'Нет расшифровки' }}"
  146. style="cursor: help; text-decoration: underline dotted;">
  147. {{ $string->$headerName }}
  148. </span>
  149. @elseif($headerName === 'pricing_code' && $string->$headerName)
  150. <span data-bs-toggle="tooltip"
  151. data-bs-placement="top"
  152. title="{{ $string->pricing_code_description ?? 'Нет расшифровки' }}"
  153. style="cursor: help; text-decoration: underline dotted;">
  154. {{ $string->$headerName }}
  155. </span>
  156. @elseif($headerName === 'pricing_codes_list' && $string->pricingCodes->count() > 0)
  157. @foreach($string->pricingCodes as $pricingCode)
  158. <span data-bs-toggle="tooltip"
  159. data-bs-placement="top"
  160. title="{{ $pricingCode->description ?? 'Нет расшифровки' }}"
  161. style="cursor: help; text-decoration: underline dotted;">
  162. {{ $pricingCode->code }}
  163. </span>@if(!$loop->last)<br>@endif
  164. @endforeach
  165. @else
  166. <p title="{!! $string->$headerName !!}">
  167. {!! \Illuminate\Support\Str::words($string->$headerName, config('app.words_in_table_cell_limit'), ' ...') !!}
  168. </p>
  169. @endif
  170. </td>
  171. @endforeach
  172. </tr>
  173. @endforeach
  174. </tbody>
  175. </table>
  176. </div>
  177. <!-- Модальное окно настроек таблицы -->
  178. <div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="exampleModalLabel"
  179. aria-hidden="true">
  180. <div class="modal-dialog modal-fullscreen-sm-down">
  181. <div class="modal-content">
  182. <div class="modal-header">
  183. <h1 class="modal-title fs-5" id="exampleModalLabel">Выбор отображаемых колонок</h1>
  184. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  185. </div>
  186. <div class="modal-body">
  187. @foreach($header as $headerName => $headerTitle)
  188. <div>
  189. <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}"
  190. class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}
  191. </label>
  192. </div>
  193. @endforeach
  194. </div>
  195. <div class="modal-footer">
  196. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
  197. </div>
  198. </div>
  199. </div>
  200. </div>
  201. <!-- Модальное окно фильтров -->
  202. <div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="exampleModalLabel"
  203. aria-hidden="true">
  204. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  205. <div class="modal-content">
  206. <div class="modal-header">
  207. <h1 class="modal-title fs-5" id="exampleModalLabel">Фильтры по колонкам таблицы</h1>
  208. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  209. </div>
  210. <div class="modal-body">
  211. <form class="filters">
  212. @if(isset($filters) && is_array($filters))
  213. @foreach($filters as $filterName => $filter)
  214. @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
  215. @include('partials.select', [
  216. 'name' => 'filters[' . $filterName . ']',
  217. 'title' => $filter['title'],
  218. 'options' => $filter['values'],
  219. 'value' => request()->filters[$filterName] ?? '',
  220. ])
  221. @endforeach
  222. @endif
  223. @if(isset($ranges) && is_array($ranges))
  224. @foreach($ranges as $rangeName => $range)
  225. @include('partials.input', [
  226. 'name' => 'filters[' . $rangeName . '_from]',
  227. 'type' => 'number',
  228. 'title' => $range['title'] . ' с:',
  229. 'min' => $range['min'],
  230. 'max' => $range['max'],
  231. 'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
  232. ])
  233. @include('partials.input', [
  234. 'name' => 'filters[' . $rangeName . '_to]',
  235. 'type' => 'number',
  236. 'title' => ' по:',
  237. 'min' => $range['min'],
  238. 'max' => $range['max'],
  239. 'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
  240. ])
  241. @endforeach
  242. @endif
  243. @if(isset($dates) && is_array($dates))
  244. @foreach($dates as $rangeName => $range)
  245. @include('partials.input', [
  246. 'name' => 'filters[' . $rangeName . '_from]',
  247. 'type' => 'date',
  248. 'title' => $range['title'] . ' с:',
  249. 'min' => $range['min'],
  250. 'max' => $range['max'],
  251. 'value' => request()->filters[$rangeName . '_from'] ?? '',
  252. ])
  253. @include('partials.input', [
  254. 'name' => 'filters[' . $rangeName . '_to]',
  255. 'type' => 'date',
  256. 'title' => $range['title'] . ' по:',
  257. 'min' => $range['min'],
  258. 'max' => $range['max'],
  259. 'value' => request()->filters[$rangeName . '_to'] ?? '',
  260. ])
  261. @endforeach
  262. @endif
  263. </form>
  264. </div>
  265. <div class="modal-footer">
  266. <button type="button" class="btn btn-primary accept-filters" data-bs-dismiss="modal">Применить</button>
  267. <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить
  268. </button>
  269. </div>
  270. </div>
  271. </div>
  272. </div>
  273. <!-- Модальное окно поиска -->
  274. <div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="exampleModalLabel"
  275. aria-hidden="true">
  276. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  277. <div class="modal-content">
  278. <div class="modal-header">
  279. <h1 class="modal-title fs-5" id="exampleModalLabel">Поиск</h1>
  280. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  281. </div>
  282. <div class="modal-body">
  283. <div>
  284. Поиск ведётся по следующим колонкам:
  285. <span class="fst-italic">
  286. @foreach($searchFields as $searchField)
  287. {{ $header[$searchField] }}
  288. @if(!$loop->last)
  289. ,
  290. @endif
  291. @endforeach
  292. </span>
  293. </div>
  294. <form class="search-form">
  295. @include('partials.input', [
  296. 'name' => 's',
  297. 'title' => 'Поиск',
  298. 'placeholder' => 'что ищем?',
  299. 'value' => request()->s ?? '',
  300. ])
  301. </form>
  302. </div>
  303. <div class="modal-footer">
  304. <button type="button" class="btn btn-primary accept-search" data-bs-dismiss="modal">Найти</button>
  305. <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить
  306. </button>
  307. </div>
  308. </div>
  309. </div>
  310. </div>
  311. @push('scripts')
  312. <script type="module">
  313. // Ждём загрузки jQuery через Vite
  314. function waitForJQuery(callback) {
  315. if (typeof window.$ !== 'undefined') {
  316. callback();
  317. } else {
  318. setTimeout(() => waitForJQuery(callback), 50);
  319. }
  320. }
  321. waitForJQuery(function () {
  322. // on page load set column visible
  323. let tbl = $('#tbl');
  324. let tableName = tbl.attr('data-table-name');
  325. let tables = JSON.parse(localStorage.getItem('table_' + tableName));
  326. // on first load create tables object
  327. if (!tables) {
  328. tables = {};
  329. }
  330. // hide disabled columns
  331. $.each(tables, function (colName, colStatus) {
  332. if (!colStatus) {
  333. $('.checkbox-' + colName).attr('checked', false);
  334. $('.column_' + colName).hide();
  335. }
  336. });
  337. // highlight search text
  338. let searchText = $('.search-form input').val();
  339. if (searchText !== '') {
  340. let innerHTML = tbl.html();
  341. let index = innerHTML.indexOf(searchText);
  342. if (index >= 0) {
  343. innerHTML = innerHTML.substring(0, index) + "<span class='highlight'>" + innerHTML.substring(index, index + searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
  344. tbl.html(innerHTML);
  345. }
  346. }
  347. $('.table').fadeIn();
  348. $('.toggle-column').on('change', function () {
  349. let columnName = $(this).attr('data-name');
  350. let columnStatus = $(this).is(':checked');
  351. // save column status
  352. tables[columnName] = columnStatus;
  353. localStorage.setItem('table_' + tableName, JSON.stringify(tables));
  354. // show or hide column
  355. if (columnStatus) {
  356. $('.column_' + columnName).show('fast');
  357. } else {
  358. $('.column_' + columnName).hide('fast');
  359. }
  360. });
  361. $('.sort-by-column').on('click', function () {
  362. let columnName = $(this).attr('data-name');
  363. let currentUrl = new URL(document.location.href);
  364. let currentColumnName = currentUrl.searchParams.get('sortBy');
  365. currentUrl.searchParams.set('sortBy', columnName);
  366. if ((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
  367. currentUrl.searchParams.delete('order');
  368. } else {
  369. currentUrl.searchParams.set('order', 'desc');
  370. }
  371. document.location.href = currentUrl.href;
  372. });
  373. $('.accept-filters').on('click', function () {
  374. let filters = $('.filters').serializeArray();
  375. let currentUrl = new URL(document.location.href);
  376. $.each(filters, function (id, filter) {
  377. if (filter.value !== '') {
  378. currentUrl.searchParams.set(filter.name, filter.value);
  379. } else {
  380. currentUrl.searchParams.delete(filter.name);
  381. }
  382. });
  383. currentUrl.searchParams.delete('page');
  384. document.location.href = currentUrl.href;
  385. });
  386. $('.reset-filters').on('click', function () {
  387. let filters = $('.filters').serializeArray();
  388. let currentUrl = new URL(document.location.href);
  389. $.each(filters, function (id, filter) {
  390. currentUrl.searchParams.delete(filter.name);
  391. });
  392. currentUrl.searchParams.delete('page');
  393. document.location.href = currentUrl.href;
  394. });
  395. $('.accept-search').on('click', function () {
  396. let s = $('.search-form input').val();
  397. let currentUrl = new URL(document.location.href);
  398. if (s !== '') {
  399. currentUrl.searchParams.set('s', s);
  400. } else {
  401. currentUrl.searchParams.delete('s');
  402. }
  403. currentUrl.searchParams.delete('page');
  404. document.location.href = currentUrl.href;
  405. });
  406. $('.reset-search').on('click', function () {
  407. let currentUrl = new URL(document.location.href);
  408. currentUrl.searchParams.delete('s');
  409. currentUrl.searchParams.delete('page');
  410. document.location.href = currentUrl.href;
  411. });
  412. $('.change-order-status').on('change', function () {
  413. let orderStatusId = $(this).val();
  414. let orderId = $(this).attr('data-order-id');
  415. $.post(
  416. '{{ route('order.update') }}',
  417. {
  418. '_token' : '{{ csrf_token() }}',
  419. id: orderId,
  420. order_status_id: orderStatusId
  421. },
  422. function () {
  423. $('.alerts').append(
  424. '<div class="main-alert alert alert-success" role="alert">Обновлён статус площадки!</div>'
  425. );
  426. setTimeout(function () {
  427. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  428. $(".main-alert").slideUp(500);
  429. })
  430. }, 3000);
  431. }
  432. );
  433. });
  434. $('.change-reclamation-status').on('change', function () {
  435. let statusId = $(this).val();
  436. let url = $(this).attr('data-url');
  437. $.post(
  438. url,
  439. {
  440. '_token' : '{{ csrf_token() }}',
  441. status_id: statusId
  442. },
  443. function () {
  444. $('.alerts').append(
  445. '<div class="main-alert alert alert-success" role="alert">Обновлён статус рекламации!</div>'
  446. );
  447. setTimeout(function () {
  448. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  449. $(".main-alert").slideUp(500);
  450. })
  451. }, 3000);
  452. }
  453. );
  454. });
  455. $(document).ready(async function () {
  456. let height1 = $('.das').innerHeight();
  457. let height2 = $('.catalog').innerHeight();
  458. let totalHeight = (Number(height1) || 0) + (Number(height2) || 0);
  459. $(".table-responsive").css('maxHeight', $(window).height() - totalHeight - 50);
  460. // Инициализация tooltips для полей tsn_number и pricing_code
  461. const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  462. const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  463. });
  464. }); // end waitForJQuery
  465. </script>
  466. @endpush