table.blade.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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 table-interactive table-initial-hidden" id="tbl" data-table-name="{{ $id }}">
  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. @php
  73. $rowId = $string->id ?? null;
  74. $rowAnchor = $rowId ? 'row-' . $rowId : null;
  75. $rowHref = null;
  76. if (isset($routeName) && $rowId) {
  77. $rowHref = route($routeName, [$string->id, 'previous_url' => request()->fullUrl() . '#' . $rowAnchor]);
  78. }
  79. @endphp
  80. <tr
  81. @if($rowAnchor) id="{{ $rowAnchor }}" data-row-id="{{ $rowId }}" @endif
  82. @if($rowHref) data-row-href="{{ $rowHref }}" @endif
  83. @if($id === 'reclamations') data-open-target="_blank" @endif
  84. >
  85. @foreach($header as $headerName => $headerTitle)
  86. <td class="column_{{$headerName}}"
  87. >
  88. @if(str_contains($headerName, '-'))
  89. @php
  90. list($rel, $field) = explode('-', $headerName);
  91. @endphp
  92. @if(isset($string->$rel->$field))
  93. @if(str_ends_with($field, '_id'))
  94. @php
  95. $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $field));
  96. @endphp
  97. {!! $string->$rel->$relation?->name; !!}
  98. @else
  99. @if(str_contains($field, 'image') && $string->$rel->$field)
  100. <a href="{{ $string->$rel->$field }}" data-toggle="lightbox"
  101. data-gallery="photos" data-size="fullscreen">
  102. <img src="{{ $string->$rel->$field }}" alt="" class="img-thumbnail maf-img">
  103. </a>
  104. @else
  105. {!! $string->$rel->$field !!}
  106. @endif
  107. @endif
  108. @else
  109. <ul class="small mb-0 list-group list-group-flush bg-secondary">
  110. @foreach($string->$rel ?? [] as $item)
  111. <li class="list-group-item py-0 bg-body-secondary">
  112. {!! $item->$field !!}
  113. </li>
  114. @endforeach
  115. </ul>
  116. @endif
  117. @elseif(str_ends_with($headerName, '_id'))
  118. @php
  119. $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $headerName));
  120. @endphp
  121. @if($headerName == 'order_status_id')
  122. <div class="badge fs-5 text-bg-{{ App\Models\Order::STATUS_COLOR[$string->order_status_id] }}">{{ $string->$relation?->name }}</div>
  123. @else
  124. {!! $string->$relation?->name; !!}
  125. @endif
  126. @elseif(str_ends_with($headerName, '_date') && ($string->$headerName))
  127. {{ \App\Helpers\DateHelper::getHumanDate($string->$headerName, true) }}
  128. @elseif(str_contains($headerName, 'image') && $string->$headerName)
  129. <a href="{{ $string->$headerName }}" data-toggle="lightbox" data-gallery="photos"
  130. data-size="fullscreen">
  131. <img src="{{ $string->$headerName }}" alt="" class="img-thumbnail maf-img">
  132. </a>
  133. @elseif(str_contains($headerName, 'order_status_name'))
  134. <select name="order_status_name" data-order-id="{{ $string->id }}" @disabled(!hasRole('admin,manager')) class="change-order-status form-control form-control-sm" >
  135. @foreach($statuses as $statusId => $statusName)
  136. <option value="{{ $statusId }}" @selected($statusName == $string->$headerName)>{{ $statusName }}</option>
  137. @endforeach
  138. </select>
  139. @elseif($id === 'reclamations' && $headerName === 'status_name')
  140. <select name="status_id"
  141. data-reclamation-id="{{ $string->id }}"
  142. data-url="{{ route('reclamations.update-status', $string->id) }}"
  143. @disabled(!hasRole('admin,manager'))
  144. class="change-reclamation-status form-control form-control-sm">
  145. @foreach($statuses as $statusId => $statusName)
  146. <option value="{{ $statusId }}" @selected($statusId == $string->status_id)>{{ $statusName }}</option>
  147. @endforeach
  148. </select>
  149. @elseif($headerName === 'tsn_number' && $string->$headerName)
  150. <span data-bs-toggle="tooltip"
  151. data-bs-placement="top"
  152. title="{{ $string->tsn_number_description ?? 'Нет расшифровки' }}"
  153. class="tooltip-help">
  154. {{ $string->$headerName }}
  155. </span>
  156. @elseif($headerName === 'pricing_code' && $string->$headerName)
  157. <span data-bs-toggle="tooltip"
  158. data-bs-placement="top"
  159. title="{{ $string->pricing_code_description ?? 'Нет расшифровки' }}"
  160. class="tooltip-help">
  161. {{ $string->$headerName }}
  162. </span>
  163. @elseif($headerName === 'pricing_codes_list' && $string->pricingCodes->count() > 0)
  164. @foreach($string->pricingCodes as $pricingCode)
  165. <span data-bs-toggle="tooltip"
  166. data-bs-placement="top"
  167. title="{{ $pricingCode->description ?? 'Нет расшифровки' }}"
  168. class="tooltip-help">
  169. {{ $pricingCode->code }}
  170. </span>@if(!$loop->last)<br>@endif
  171. @endforeach
  172. @else
  173. <p title="{!! $string->$headerName !!}">
  174. {!! \Illuminate\Support\Str::words($string->$headerName, config('app.words_in_table_cell_limit'), ' ...') !!}
  175. </p>
  176. @endif
  177. </td>
  178. @endforeach
  179. </tr>
  180. @endforeach
  181. </tbody>
  182. </table>
  183. </div>
  184. <!-- Модальное окно настроек таблицы -->
  185. <div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="exampleModalLabel"
  186. aria-hidden="true">
  187. <div class="modal-dialog modal-fullscreen-sm-down">
  188. <div class="modal-content">
  189. <div class="modal-header">
  190. <h1 class="modal-title fs-5" id="exampleModalLabel">Выбор отображаемых колонок</h1>
  191. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  192. </div>
  193. <div class="modal-body">
  194. @foreach($header as $headerName => $headerTitle)
  195. <div>
  196. <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}"
  197. class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}
  198. </label>
  199. </div>
  200. @endforeach
  201. </div>
  202. <div class="modal-footer">
  203. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. <!-- Модальное окно фильтров -->
  209. <div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="exampleModalLabel"
  210. aria-hidden="true">
  211. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  212. <div class="modal-content">
  213. <div class="modal-header">
  214. <h1 class="modal-title fs-5" id="exampleModalLabel">Фильтры по колонкам таблицы</h1>
  215. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  216. </div>
  217. <div class="modal-body">
  218. <form class="filters">
  219. @if(isset($filters) && is_array($filters))
  220. @foreach($filters as $filterName => $filter)
  221. @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
  222. @include('partials.select', [
  223. 'name' => 'filters[' . $filterName . ']',
  224. 'title' => $filter['title'],
  225. 'options' => $filter['values'],
  226. 'value' => request()->filters[$filterName] ?? '',
  227. ])
  228. @endforeach
  229. @endif
  230. @if(isset($ranges) && is_array($ranges))
  231. @foreach($ranges as $rangeName => $range)
  232. @include('partials.input', [
  233. 'name' => 'filters[' . $rangeName . '_from]',
  234. 'type' => 'number',
  235. 'title' => $range['title'] . ' с:',
  236. 'min' => $range['min'],
  237. 'max' => $range['max'],
  238. 'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
  239. ])
  240. @include('partials.input', [
  241. 'name' => 'filters[' . $rangeName . '_to]',
  242. 'type' => 'number',
  243. 'title' => ' по:',
  244. 'min' => $range['min'],
  245. 'max' => $range['max'],
  246. 'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
  247. ])
  248. @endforeach
  249. @endif
  250. @if(isset($dates) && is_array($dates))
  251. @foreach($dates as $rangeName => $range)
  252. @include('partials.input', [
  253. 'name' => 'filters[' . $rangeName . '_from]',
  254. 'type' => 'date',
  255. 'title' => $range['title'] . ' с:',
  256. 'min' => $range['min'],
  257. 'max' => $range['max'],
  258. 'value' => request()->filters[$rangeName . '_from'] ?? '',
  259. ])
  260. @include('partials.input', [
  261. 'name' => 'filters[' . $rangeName . '_to]',
  262. 'type' => 'date',
  263. 'title' => $range['title'] . ' по:',
  264. 'min' => $range['min'],
  265. 'max' => $range['max'],
  266. 'value' => request()->filters[$rangeName . '_to'] ?? '',
  267. ])
  268. @endforeach
  269. @endif
  270. </form>
  271. </div>
  272. <div class="modal-footer">
  273. <button type="button" class="btn btn-primary accept-filters" data-bs-dismiss="modal">Применить</button>
  274. <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить
  275. </button>
  276. </div>
  277. </div>
  278. </div>
  279. </div>
  280. <!-- Модальное окно поиска -->
  281. <div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="exampleModalLabel"
  282. aria-hidden="true">
  283. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  284. <div class="modal-content">
  285. <div class="modal-header">
  286. <h1 class="modal-title fs-5" id="exampleModalLabel">Поиск</h1>
  287. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  288. </div>
  289. <div class="modal-body">
  290. <div>
  291. Поиск ведётся по следующим колонкам:
  292. <span class="fst-italic">
  293. @foreach($searchFields as $searchField)
  294. {{ $header[$searchField] }}
  295. @if(!$loop->last)
  296. ,
  297. @endif
  298. @endforeach
  299. </span>
  300. </div>
  301. <form class="search-form">
  302. @include('partials.input', [
  303. 'name' => 's',
  304. 'title' => 'Поиск',
  305. 'placeholder' => 'что ищем?',
  306. 'value' => request()->s ?? '',
  307. ])
  308. </form>
  309. </div>
  310. <div class="modal-footer">
  311. <button type="button" class="btn btn-primary accept-search" data-bs-dismiss="modal">Найти</button>
  312. <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить
  313. </button>
  314. </div>
  315. </div>
  316. </div>
  317. </div>
  318. @push('scripts')
  319. <script type="module">
  320. // Ждём загрузки jQuery через Vite
  321. function waitForJQuery(callback) {
  322. if (typeof window.$ !== 'undefined') {
  323. callback();
  324. } else {
  325. setTimeout(() => waitForJQuery(callback), 50);
  326. }
  327. }
  328. waitForJQuery(function () {
  329. // on page load set column visible
  330. let tbl = $('#tbl');
  331. let tableName = tbl.attr('data-table-name');
  332. let tables = JSON.parse(localStorage.getItem('table_' + tableName));
  333. // on first load create tables object
  334. if (!tables) {
  335. tables = {};
  336. }
  337. // hide disabled columns
  338. $.each(tables, function (colName, colStatus) {
  339. if (!colStatus) {
  340. $('.checkbox-' + colName).attr('checked', false);
  341. $('.column_' + colName).hide();
  342. }
  343. });
  344. // highlight search text
  345. let searchText = $('.search-form input').val();
  346. if (searchText !== '') {
  347. let innerHTML = tbl.html();
  348. let index = innerHTML.indexOf(searchText);
  349. if (index >= 0) {
  350. innerHTML = innerHTML.substring(0, index) + "<span class='highlight'>" + innerHTML.substring(index, index + searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
  351. tbl.html(innerHTML);
  352. }
  353. }
  354. $('.table').fadeIn();
  355. function isRowActionTarget(target) {
  356. return $(target).closest('a, button, input, select, textarea, label, .dropdown, [data-bs-toggle], [data-no-row-select]').length > 0;
  357. }
  358. function selectRow($row, updateHash = true) {
  359. if (!$row || !$row.length) {
  360. return;
  361. }
  362. $row.closest('tbody').find('tr.is-selected').removeClass('is-selected');
  363. $row.addClass('is-selected');
  364. if (updateHash) {
  365. const rowId = $row.data('row-id');
  366. if (rowId) {
  367. const hash = '#row-' + rowId;
  368. const newUrl = window.location.pathname + window.location.search + hash;
  369. history.replaceState(null, '', newUrl);
  370. if (tableName) {
  371. localStorage.setItem('table_last_row_' + tableName, String(rowId));
  372. }
  373. }
  374. }
  375. }
  376. $(document).on('click', '.table-interactive tbody tr', function (e) {
  377. if (isRowActionTarget(e.target)) {
  378. return;
  379. }
  380. selectRow($(this));
  381. });
  382. $(document).on('dblclick', '.table-interactive tbody tr', function (e) {
  383. if (isRowActionTarget(e.target)) {
  384. return;
  385. }
  386. const $row = $(this);
  387. const href = $row.data('row-href');
  388. if (!href) {
  389. return;
  390. }
  391. selectRow($row, false);
  392. const target = $row.data('open-target');
  393. if (target === '_blank') {
  394. window.open(href, '_blank');
  395. } else {
  396. window.location.href = href;
  397. }
  398. });
  399. $('.toggle-column').on('change', function () {
  400. let columnName = $(this).attr('data-name');
  401. let columnStatus = $(this).is(':checked');
  402. // save column status
  403. tables[columnName] = columnStatus;
  404. localStorage.setItem('table_' + tableName, JSON.stringify(tables));
  405. // show or hide column
  406. if (columnStatus) {
  407. $('.column_' + columnName).show('fast');
  408. } else {
  409. $('.column_' + columnName).hide('fast');
  410. }
  411. });
  412. $('.sort-by-column').on('click', function () {
  413. let columnName = $(this).attr('data-name');
  414. let currentUrl = new URL(document.location.href);
  415. let currentColumnName = currentUrl.searchParams.get('sortBy');
  416. currentUrl.searchParams.set('sortBy', columnName);
  417. if ((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
  418. currentUrl.searchParams.delete('order');
  419. } else {
  420. currentUrl.searchParams.set('order', 'desc');
  421. }
  422. document.location.href = currentUrl.href;
  423. });
  424. $('.accept-filters').on('click', function () {
  425. let filters = $('.filters').serializeArray();
  426. let currentUrl = new URL(document.location.href);
  427. $.each(filters, function (id, filter) {
  428. if (filter.value !== '') {
  429. currentUrl.searchParams.set(filter.name, filter.value);
  430. } else {
  431. currentUrl.searchParams.delete(filter.name);
  432. }
  433. });
  434. currentUrl.searchParams.delete('page');
  435. document.location.href = currentUrl.href;
  436. });
  437. $('.reset-filters').on('click', function () {
  438. let filters = $('.filters').serializeArray();
  439. let currentUrl = new URL(document.location.href);
  440. $.each(filters, function (id, filter) {
  441. currentUrl.searchParams.delete(filter.name);
  442. });
  443. currentUrl.searchParams.delete('page');
  444. document.location.href = currentUrl.href;
  445. });
  446. $('.accept-search').on('click', function () {
  447. let s = $('.search-form input').val();
  448. let currentUrl = new URL(document.location.href);
  449. if (s !== '') {
  450. currentUrl.searchParams.set('s', s);
  451. } else {
  452. currentUrl.searchParams.delete('s');
  453. }
  454. currentUrl.searchParams.delete('page');
  455. document.location.href = currentUrl.href;
  456. });
  457. $('.reset-search').on('click', function () {
  458. let currentUrl = new URL(document.location.href);
  459. currentUrl.searchParams.delete('s');
  460. currentUrl.searchParams.delete('page');
  461. document.location.href = currentUrl.href;
  462. });
  463. $('.change-order-status').on('change', function () {
  464. let orderStatusId = $(this).val();
  465. let orderId = $(this).attr('data-order-id');
  466. $.post(
  467. '{{ route('order.update') }}',
  468. {
  469. '_token' : '{{ csrf_token() }}',
  470. id: orderId,
  471. order_status_id: orderStatusId
  472. },
  473. function () {
  474. $('.alerts').append(
  475. '<div class="main-alert alert alert-success" role="alert">Обновлён статус площадки!</div>'
  476. );
  477. setTimeout(function () {
  478. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  479. $(".main-alert").slideUp(500);
  480. })
  481. }, 3000);
  482. }
  483. );
  484. });
  485. $('.change-reclamation-status').on('change', function () {
  486. let statusId = $(this).val();
  487. let url = $(this).attr('data-url');
  488. $.post(
  489. url,
  490. {
  491. '_token' : '{{ csrf_token() }}',
  492. status_id: statusId
  493. },
  494. function () {
  495. $('.alerts').append(
  496. '<div class="main-alert alert alert-success" role="alert">Обновлён статус рекламации!</div>'
  497. );
  498. setTimeout(function () {
  499. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  500. $(".main-alert").slideUp(500);
  501. })
  502. }, 3000);
  503. }
  504. );
  505. });
  506. $(document).ready(async function () {
  507. let height1 = $('.das').innerHeight();
  508. let height2 = $('.catalog').innerHeight();
  509. let totalHeight = (Number(height1) || 0) + (Number(height2) || 0);
  510. $(".table-responsive").css('maxHeight', $(window).height() - totalHeight - 50);
  511. // Инициализация tooltips для полей tsn_number и pricing_code
  512. const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  513. const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  514. const hash = window.location.hash;
  515. if (hash && hash.startsWith('#row-')) {
  516. const $row = $(hash);
  517. if ($row.length) {
  518. selectRow($row, false);
  519. $row[0].scrollIntoView({block: 'center'});
  520. const rowId = $row.data('row-id');
  521. if (rowId && tableName) {
  522. localStorage.setItem('table_last_row_' + tableName, String(rowId));
  523. }
  524. return;
  525. }
  526. }
  527. if (tableName) {
  528. const storedRowId = localStorage.getItem('table_last_row_' + tableName);
  529. if (storedRowId) {
  530. const $storedRow = $('#row-' + storedRowId);
  531. if ($storedRow.length) {
  532. selectRow($storedRow, false);
  533. $storedRow[0].scrollIntoView({block: 'center'});
  534. }
  535. }
  536. }
  537. });
  538. }); // end waitForJQuery
  539. </script>
  540. @endpush