table.blade.php 32 KB

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