edit.blade.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. @extends('layouts.app')
  2. @section('content')
  3. <div class="container-fluid">
  4. <div class="row">
  5. <div class="col-12">
  6. <div class="row mb-2">
  7. <div class="col-6">
  8. <h2>{{ $spare_part ? 'Редактирование запчасти' : 'Создание запчасти' }}</h2>
  9. </div>
  10. <div class="col-6 text-end">
  11. @if($spare_part && hasRole('admin'))
  12. <button class="btn btn-sm text-success" onclick="$('#upl-image').trigger('click');"><i class="bi bi-plus-circle-fill"></i> Загрузить изображение</button>
  13. <form action="{{ route('spare_parts.upload_image', ['sparePart' => $spare_part]) }}" class="visually-hidden" method="POST" enctype="multipart/form-data">
  14. @csrf
  15. <input type="file" name="image" onchange="$(this).parent().submit()" required id="upl-image" accept="image/*" />
  16. </form>
  17. @endif
  18. </div>
  19. </div>
  20. <form action="{{ $spare_part ? route('spare_parts.update', $spare_part) : route('spare_parts.store') }}"
  21. method="POST">
  22. @csrf
  23. @if($spare_part)
  24. @method('PUT')
  25. @endif
  26. <input type="hidden" name="previous_url" value="{{ $previous_url ?? url()->previous() }}">
  27. <div class="row">
  28. {{-- Левая колонка --}}
  29. <div class="col-md-6">
  30. @if($spare_part && $spare_part->image)
  31. <div class="mb-3">
  32. <img src="{{ $spare_part->image }}" alt="{{ $spare_part->article }}" class="img-fluid" style="max-width: 200px;">
  33. </div>
  34. @endif
  35. <div class="mb-3">
  36. <label for="article" class="form-label">Артикул <span class="text-danger">*</span></label>
  37. <input type="text"
  38. class="form-control"
  39. id="article"
  40. name="article"
  41. value="{{ old('article', $spare_part->article ?? '') }}"
  42. {{ hasRole('admin') ? '' : 'readonly' }}
  43. required>
  44. </div>
  45. <div class="mb-3">
  46. <label for="used_in_maf" class="form-label">Где используется</label>
  47. <input type="text"
  48. class="form-control"
  49. id="used_in_maf"
  50. name="used_in_maf"
  51. value="{{ old('used_in_maf', $spare_part->used_in_maf ?? '') }}"
  52. {{ hasRole('admin') ? '' : 'readonly' }}>
  53. </div>
  54. <div class="mb-3">
  55. <label for="note" class="form-label">Примечание</label>
  56. <textarea class="form-control"
  57. id="note"
  58. name="note"
  59. rows="3"
  60. {{ hasRole('admin') ? '' : 'readonly' }}>{{ old('note', $spare_part->note ?? '') }}</textarea>
  61. </div>
  62. </div>
  63. {{-- Правая колонка --}}
  64. <div class="col-md-6">
  65. @if(hasRole('admin'))
  66. <div class="mb-3">
  67. <label for="purchase_price" class="form-label">Цена закупки (руб.)</label>
  68. <input type="number"
  69. class="form-control"
  70. id="purchase_price"
  71. name="purchase_price"
  72. step="0.01"
  73. value="{{ old('purchase_price', $spare_part->purchase_price ?? '') }}">
  74. </div>
  75. @endif
  76. <div class="mb-3">
  77. <label for="customer_price" class="form-label">Цена для заказчика (руб.)</label>
  78. <input type="number"
  79. class="form-control"
  80. id="customer_price"
  81. name="customer_price"
  82. step="0.01"
  83. value="{{ old('customer_price', $spare_part->customer_price ?? '') }}"
  84. {{ hasRole('admin') ? '' : 'readonly' }}>
  85. </div>
  86. <div class="mb-3">
  87. <label for="expertise_price" class="form-label">Цена экспертизы (руб.)</label>
  88. <input type="number"
  89. class="form-control"
  90. id="expertise_price"
  91. name="expertise_price"
  92. step="0.01"
  93. value="{{ old('expertise_price', $spare_part->expertise_price ?? '') }}"
  94. {{ hasRole('admin') ? '' : 'readonly' }}>
  95. </div>
  96. <div class="mb-3">
  97. <label for="tsn_number" class="form-label">№ по ТСН</label>
  98. <div class="row">
  99. <div class="col-md-5 position-relative">
  100. <input type="text"
  101. class="form-control"
  102. id="tsn_number"
  103. name="tsn_number"
  104. value="{{ old('tsn_number', $spare_part->tsn_number ?? '') }}"
  105. autocomplete="off"
  106. {{ hasRole('admin') ? '' : 'readonly' }}>
  107. <div class="autocomplete-dropdown" id="tsn_number_dropdown"></div>
  108. </div>
  109. <div class="col-md-7">
  110. <input type="text"
  111. class="form-control"
  112. id="tsn_number_description"
  113. name="tsn_number_description"
  114. placeholder="Расшифровка"
  115. {{ hasRole('admin') ? '' : 'readonly' }}>
  116. </div>
  117. </div>
  118. <div class="form-text" id="tsn_number_hint"></div>
  119. </div>
  120. <div class="mb-3">
  121. <label class="form-label">Шифр расценки и коды ресурсов</label>
  122. <div id="pricing_codes_container">
  123. @php
  124. $existingCodes = old('pricing_codes', $spare_part ? $spare_part->pricingCodes->pluck('code')->toArray() : []);
  125. @endphp
  126. @forelse($existingCodes as $index => $code)
  127. <div class="pricing-code-row row mb-2" data-index="{{ $index }}">
  128. <div class="col-md-5 position-relative">
  129. <input type="text"
  130. class="form-control pricing-code-input"
  131. name="pricing_codes[]"
  132. value="{{ $code }}"
  133. autocomplete="off"
  134. placeholder="Код"
  135. {{ hasRole('admin') ? '' : 'readonly' }}>
  136. <div class="autocomplete-dropdown pricing-code-dropdown"></div>
  137. </div>
  138. <div class="col-md-5">
  139. <input type="text"
  140. class="form-control pricing-code-description-input"
  141. name="pricing_codes_descriptions[]"
  142. placeholder="Расшифровка"
  143. {{ hasRole('admin') ? '' : 'readonly' }}>
  144. </div>
  145. <div class="col-md-2">
  146. @if(hasRole('admin'))
  147. <button type="button" class="btn btn-outline-danger btn-remove-pricing-code" title="Удалить">
  148. <i class="bi bi-trash"></i>
  149. </button>
  150. @endif
  151. </div>
  152. <div class="col-12"><div class="form-text pricing-code-hint"></div></div>
  153. </div>
  154. @empty
  155. <div class="pricing-code-row row mb-2" data-index="0">
  156. <div class="col-md-5 position-relative">
  157. <input type="text"
  158. class="form-control pricing-code-input"
  159. name="pricing_codes[]"
  160. value=""
  161. autocomplete="off"
  162. placeholder="Код"
  163. {{ hasRole('admin') ? '' : 'readonly' }}>
  164. <div class="autocomplete-dropdown pricing-code-dropdown"></div>
  165. </div>
  166. <div class="col-md-5">
  167. <input type="text"
  168. class="form-control pricing-code-description-input"
  169. name="pricing_codes_descriptions[]"
  170. placeholder="Расшифровка"
  171. {{ hasRole('admin') ? '' : 'readonly' }}>
  172. </div>
  173. <div class="col-md-2">
  174. @if(hasRole('admin'))
  175. <button type="button" class="btn btn-outline-danger btn-remove-pricing-code" title="Удалить">
  176. <i class="bi bi-trash"></i>
  177. </button>
  178. @endif
  179. </div>
  180. <div class="col-12"><div class="form-text pricing-code-hint"></div></div>
  181. </div>
  182. @endforelse
  183. </div>
  184. @if(hasRole('admin'))
  185. <button type="button" class="btn btn-sm btn-outline-primary" id="btn_add_pricing_code">
  186. <i class="bi bi-plus-circle"></i> Добавить код
  187. </button>
  188. @endif
  189. </div>
  190. <div class="mb-3">
  191. <label for="min_stock" class="form-label">Минимальный остаток</label>
  192. <input type="number"
  193. class="form-control"
  194. id="min_stock"
  195. name="min_stock"
  196. value="{{ old('min_stock', $spare_part->min_stock ?? 0) }}"
  197. {{ hasRole('admin') ? '' : 'readonly' }}>
  198. </div>
  199. </div>
  200. </div>
  201. <div class="row">
  202. <div class="col-12">
  203. @if(hasRole('admin'))
  204. <button type="submit" class="btn btn-success">Сохранить</button>
  205. @endif
  206. <a href="{{ $previous_url ?? route('spare_parts.index') }}" class="btn btn-secondary">Назад</a>
  207. @if($spare_part && hasRole('admin'))
  208. <button type="button" class="btn btn-danger float-end" data-bs-toggle="modal" data-bs-target="#deleteModal">
  209. Удалить
  210. </button>
  211. @endif
  212. </div>
  213. </div>
  214. </form>
  215. </div>
  216. </div>
  217. </div>
  218. @if($spare_part && hasRole('admin'))
  219. {{-- Модальное окно удаления --}}
  220. <div class="modal fade" id="deleteModal" tabindex="-1">
  221. <div class="modal-dialog">
  222. <div class="modal-content">
  223. <div class="modal-header">
  224. <h5 class="modal-title">Подтверждение удаления</h5>
  225. <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
  226. </div>
  227. <div class="modal-body">
  228. Вы действительно хотите удалить запчасть "{{ $spare_part->article }}"?
  229. </div>
  230. <div class="modal-footer">
  231. <form action="{{ route('spare_parts.destroy', $spare_part) }}" method="POST">
  232. @csrf
  233. @method('DELETE')
  234. <button type="submit" class="btn btn-danger">Удалить</button>
  235. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
  236. </form>
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. @endif
  242. @push('scripts')
  243. <style>
  244. .autocomplete-dropdown {
  245. position: absolute;
  246. top: 100%;
  247. left: 0;
  248. right: 0;
  249. z-index: 1050;
  250. background: white;
  251. border: 1px solid #dee2e6;
  252. border-top: none;
  253. border-radius: 0 0 .375rem .375rem;
  254. max-height: 250px;
  255. overflow-y: auto;
  256. display: none;
  257. box-shadow: 0 4px 6px rgba(0,0,0,.1);
  258. }
  259. .autocomplete-dropdown .autocomplete-item {
  260. padding: 8px 12px;
  261. cursor: pointer;
  262. border-bottom: 1px solid #f0f0f0;
  263. }
  264. .autocomplete-dropdown .autocomplete-item:last-child {
  265. border-bottom: none;
  266. }
  267. .autocomplete-dropdown .autocomplete-item:hover,
  268. .autocomplete-dropdown .autocomplete-item.active {
  269. background-color: #e9ecef;
  270. }
  271. .autocomplete-dropdown .autocomplete-item .code {
  272. font-weight: 600;
  273. color: #495057;
  274. }
  275. .autocomplete-dropdown .autocomplete-item .description {
  276. font-size: 0.875em;
  277. color: #6c757d;
  278. }
  279. </style>
  280. <script>
  281. function waitForJQuery(callback) {
  282. if (typeof $ !== 'undefined') {
  283. callback();
  284. } else {
  285. setTimeout(function() { waitForJQuery(callback); }, 50);
  286. }
  287. }
  288. waitForJQuery(function() {
  289. $(document).ready(function() {
  290. @if(hasRole('admin'))
  291. //console.log('Autocomplete init started');
  292. // Общая функция для инициализации автокомплита
  293. function initAutocomplete(inputId, dropdownId, descriptionId, hintId, type) {
  294. const $input = $('#' + inputId);
  295. const $dropdown = $('#' + dropdownId);
  296. const $description = $('#' + descriptionId);
  297. const $hint = $('#' + hintId);
  298. let currentFocus = -1;
  299. let searchTimeout;
  300. //console.log('Init autocomplete for:', inputId, $input.length);
  301. // Обработка ввода
  302. $input.on('input', function() {
  303. const query = $(this).val().trim();
  304. clearTimeout(searchTimeout);
  305. //console.log('Input event:', inputId, query);
  306. if (query.length > 0) {
  307. searchTimeout = setTimeout(function() {
  308. // Поиск вариантов для автокомплита
  309. $.get('{{ route('pricing_codes.search') }}', {
  310. type: type,
  311. query: query
  312. }).done(function(data) {
  313. //console.log('Search result:', data);
  314. showDropdown(data, query);
  315. }).fail(function(xhr) {
  316. console.error('Search error:', xhr.status, xhr.responseText);
  317. });
  318. // Проверка точного соответствия для расшифровки
  319. $.get('{{ route('pricing_codes.get_description') }}', {
  320. type: type,
  321. code: query
  322. }).done(function(data) {
  323. // console.log('Description result:', data);
  324. if (data.description) {
  325. $description.val(data.description);
  326. $description.prop('readonly', true);
  327. $hint.html('<i class="bi bi-check-circle text-success"></i> Код найден в справочнике');
  328. } else {
  329. $description.val('');
  330. $description.prop('readonly', false);
  331. $hint.html('<i class="bi bi-plus-circle text-primary"></i> Новый код - заполните расшифровку');
  332. }
  333. }).fail(function(xhr) {
  334. console.error('Description error:', xhr.status, xhr.responseText);
  335. });
  336. }, 200);
  337. } else {
  338. $dropdown.hide();
  339. $description.val('');
  340. $description.prop('readonly', false);
  341. $hint.text('');
  342. }
  343. });
  344. // Показать выпадающий список
  345. function showDropdown(items, query) {
  346. $dropdown.empty();
  347. currentFocus = -1;
  348. if (items.length === 0) {
  349. $dropdown.hide();
  350. return;
  351. }
  352. items.forEach(function(item, index) {
  353. const $item = $('<div class="autocomplete-item"></div>');
  354. const highlightedCode = highlightMatch(item.code, query);
  355. const highlightedDesc = item.description ? highlightMatch(item.description, query) : '';
  356. $item.html('<div class="code">' + highlightedCode + '</div>' +
  357. (item.description ? '<div class="description">' + highlightedDesc + '</div>' : ''));
  358. $item.data('code', item.code);
  359. $item.data('description', item.description || '');
  360. $item.on('click', function() {
  361. selectItem($(this));
  362. });
  363. $dropdown.append($item);
  364. });
  365. $dropdown.show();
  366. }
  367. // Подсветка совпадения
  368. function highlightMatch(text, query) {
  369. if (!text || !query) return text || '';
  370. const regex = new RegExp('(' + escapeRegex(query) + ')', 'gi');
  371. return text.replace(regex, '<strong>$1</strong>');
  372. }
  373. function escapeRegex(str) {
  374. return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  375. }
  376. // Выбор элемента
  377. function selectItem($item) {
  378. $input.val($item.data('code'));
  379. $description.val($item.data('description'));
  380. $description.prop('readonly', true);
  381. $hint.html('<i class="bi bi-check-circle text-success"></i> Код найден в справочнике');
  382. $dropdown.hide();
  383. }
  384. // Навигация клавиатурой
  385. $input.on('keydown', function(e) {
  386. const $items = $dropdown.find('.autocomplete-item');
  387. if (e.keyCode === 40) { // Стрелка вниз
  388. e.preventDefault();
  389. currentFocus++;
  390. if (currentFocus >= $items.length) currentFocus = 0;
  391. setActive($items);
  392. } else if (e.keyCode === 38) { // Стрелка вверх
  393. e.preventDefault();
  394. currentFocus--;
  395. if (currentFocus < 0) currentFocus = $items.length - 1;
  396. setActive($items);
  397. } else if (e.keyCode === 13) { // Enter
  398. e.preventDefault();
  399. if (currentFocus > -1 && $items.length > 0) {
  400. selectItem($items.eq(currentFocus));
  401. }
  402. } else if (e.keyCode === 27) { // Escape
  403. $dropdown.hide();
  404. }
  405. });
  406. function setActive($items) {
  407. $items.removeClass('active');
  408. if (currentFocus >= 0 && currentFocus < $items.length) {
  409. $items.eq(currentFocus).addClass('active');
  410. }
  411. }
  412. // Закрытие при клике вне
  413. $(document).on('click', function(e) {
  414. if (!$(e.target).closest('#' + inputId + ', #' + dropdownId).length) {
  415. $dropdown.hide();
  416. }
  417. });
  418. // При фокусе показать список если есть значение
  419. $input.on('focus', function() {
  420. const query = $(this).val().trim();
  421. if (query.length > 0) {
  422. $.get('{{ route('pricing_codes.search') }}', {
  423. type: type,
  424. query: query
  425. }, function(data) {
  426. showDropdown(data, query);
  427. });
  428. }
  429. });
  430. }
  431. // Инициализация автокомплитов
  432. initAutocomplete('tsn_number', 'tsn_number_dropdown', 'tsn_number_description', 'tsn_number_hint', 'tsn_number');
  433. // Загрузка расшифровок при открытии страницы
  434. function loadInitialDescription(inputId, descriptionId, hintId, type) {
  435. const code = $('#' + inputId).val().trim();
  436. if (code.length > 0) {
  437. $.get('{{ route('pricing_codes.get_description') }}', {
  438. type: type,
  439. code: code
  440. }).done(function(data) {
  441. if (data.description) {
  442. $('#' + descriptionId).val(data.description);
  443. $('#' + descriptionId).prop('readonly', true);
  444. $('#' + hintId).html('<i class="bi bi-check-circle text-success"></i> Код найден в справочнике');
  445. } else {
  446. $('#' + descriptionId).prop('readonly', false);
  447. $('#' + hintId).html('<i class="bi bi-plus-circle text-primary"></i> Новый код - заполните расшифровку');
  448. }
  449. }).fail(function(xhr) {
  450. console.error('Initial description error:', xhr.status, xhr.responseText);
  451. });
  452. }
  453. }
  454. loadInitialDescription('tsn_number', 'tsn_number_description', 'tsn_number_hint', 'tsn_number');
  455. // Функционал множественных шифров расценки
  456. function initPricingCodeAutocomplete($row) {
  457. const $input = $row.find('.pricing-code-input');
  458. const $dropdown = $row.find('.pricing-code-dropdown');
  459. const $description = $row.find('.pricing-code-description-input');
  460. const $hint = $row.find('.pricing-code-hint');
  461. let currentFocus = -1;
  462. let searchTimeout;
  463. $input.on('input', function() {
  464. const query = $(this).val().trim();
  465. clearTimeout(searchTimeout);
  466. if (query.length > 0) {
  467. searchTimeout = setTimeout(function() {
  468. $.get('{{ route('pricing_codes.search') }}', {
  469. type: 'pricing_code',
  470. query: query
  471. }).done(function(data) {
  472. showDropdownPricing($dropdown, data, query, $input, $description, $hint);
  473. });
  474. $.get('{{ route('pricing_codes.get_description') }}', {
  475. type: 'pricing_code',
  476. code: query
  477. }).done(function(data) {
  478. if (data.description) {
  479. $description.val(data.description);
  480. $description.prop('readonly', true);
  481. $hint.html('<i class="bi bi-check-circle text-success"></i> Код найден в справочнике');
  482. } else {
  483. $description.val('');
  484. $description.prop('readonly', false);
  485. $hint.html('<i class="bi bi-plus-circle text-primary"></i> Новый код - заполните расшифровку');
  486. }
  487. });
  488. }, 200);
  489. } else {
  490. $dropdown.hide();
  491. $description.val('');
  492. $description.prop('readonly', false);
  493. $hint.text('');
  494. }
  495. });
  496. $input.on('focus', function() {
  497. const query = $(this).val().trim();
  498. if (query.length > 0) {
  499. $.get('{{ route('pricing_codes.search') }}', {
  500. type: 'pricing_code',
  501. query: query
  502. }, function(data) {
  503. showDropdownPricing($dropdown, data, query, $input, $description, $hint);
  504. });
  505. }
  506. });
  507. $input.on('keydown', function(e) {
  508. const $items = $dropdown.find('.autocomplete-item');
  509. if (e.keyCode === 40) {
  510. e.preventDefault();
  511. currentFocus++;
  512. if (currentFocus >= $items.length) currentFocus = 0;
  513. $items.removeClass('active');
  514. if (currentFocus >= 0) $items.eq(currentFocus).addClass('active');
  515. } else if (e.keyCode === 38) {
  516. e.preventDefault();
  517. currentFocus--;
  518. if (currentFocus < 0) currentFocus = $items.length - 1;
  519. $items.removeClass('active');
  520. if (currentFocus >= 0) $items.eq(currentFocus).addClass('active');
  521. } else if (e.keyCode === 13) {
  522. e.preventDefault();
  523. if (currentFocus > -1 && $items.length > 0) {
  524. $items.eq(currentFocus).trigger('click');
  525. }
  526. } else if (e.keyCode === 27) {
  527. $dropdown.hide();
  528. }
  529. });
  530. $(document).on('click', function(e) {
  531. if (!$(e.target).closest($row).length) {
  532. $dropdown.hide();
  533. }
  534. });
  535. }
  536. function showDropdownPricing($dropdown, items, query, $input, $description, $hint) {
  537. $dropdown.empty();
  538. if (items.length === 0) {
  539. $dropdown.hide();
  540. return;
  541. }
  542. items.forEach(function(item) {
  543. const $item = $('<div class="autocomplete-item"></div>');
  544. const highlightedCode = highlightMatchPricing(item.code, query);
  545. const highlightedDesc = item.description ? highlightMatchPricing(item.description, query) : '';
  546. $item.html('<div class="code">' + highlightedCode + '</div>' +
  547. (item.description ? '<div class="description">' + highlightedDesc + '</div>' : ''));
  548. $item.data('code', item.code);
  549. $item.data('description', item.description || '');
  550. $item.on('click', function() {
  551. $input.val($(this).data('code'));
  552. $description.val($(this).data('description'));
  553. $description.prop('readonly', true);
  554. $hint.html('<i class="bi bi-check-circle text-success"></i> Код найден в справочнике');
  555. $dropdown.hide();
  556. });
  557. $dropdown.append($item);
  558. });
  559. $dropdown.show();
  560. }
  561. function highlightMatchPricing(text, query) {
  562. if (!text || !query) return text || '';
  563. const regex = new RegExp('(' + query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi');
  564. return text.replace(regex, '<strong>$1</strong>');
  565. }
  566. function loadInitialPricingCodeDescription($row) {
  567. const code = $row.find('.pricing-code-input').val().trim();
  568. const $description = $row.find('.pricing-code-description-input');
  569. const $hint = $row.find('.pricing-code-hint');
  570. if (code.length > 0) {
  571. $.get('{{ route('pricing_codes.get_description') }}', {
  572. type: 'pricing_code',
  573. code: code
  574. }).done(function(data) {
  575. if (data.description) {
  576. $description.val(data.description);
  577. $description.prop('readonly', true);
  578. $hint.html('<i class="bi bi-check-circle text-success"></i> Код найден в справочнике');
  579. } else {
  580. $description.prop('readonly', false);
  581. $hint.html('<i class="bi bi-plus-circle text-primary"></i> Новый код - заполните расшифровку');
  582. }
  583. });
  584. }
  585. }
  586. // Инициализация существующих строк
  587. $('.pricing-code-row').each(function() {
  588. initPricingCodeAutocomplete($(this));
  589. loadInitialPricingCodeDescription($(this));
  590. });
  591. // Добавление новой строки
  592. $('#btn_add_pricing_code').on('click', function() {
  593. const $container = $('#pricing_codes_container');
  594. const newIndex = $container.find('.pricing-code-row').length;
  595. const $newRow = $(`
  596. <div class="pricing-code-row row mb-2" data-index="${newIndex}">
  597. <div class="col-md-5 position-relative">
  598. <input type="text"
  599. class="form-control pricing-code-input"
  600. name="pricing_codes[]"
  601. value=""
  602. autocomplete="off"
  603. placeholder="Код">
  604. <div class="autocomplete-dropdown pricing-code-dropdown"></div>
  605. </div>
  606. <div class="col-md-5">
  607. <input type="text"
  608. class="form-control pricing-code-description-input"
  609. name="pricing_codes_descriptions[]"
  610. placeholder="Расшифровка">
  611. </div>
  612. <div class="col-md-2">
  613. <button type="button" class="btn btn-outline-danger btn-remove-pricing-code" title="Удалить">
  614. <i class="bi bi-trash"></i>
  615. </button>
  616. </div>
  617. <div class="col-12"><div class="form-text pricing-code-hint"></div></div>
  618. </div>
  619. `);
  620. $container.append($newRow);
  621. initPricingCodeAutocomplete($newRow);
  622. $newRow.find('.pricing-code-input').focus();
  623. });
  624. // Удаление строки
  625. $(document).on('click', '.btn-remove-pricing-code', function() {
  626. const $container = $('#pricing_codes_container');
  627. if ($container.find('.pricing-code-row').length > 1) {
  628. $(this).closest('.pricing-code-row').remove();
  629. } else {
  630. // Если осталась одна строка, просто очищаем её
  631. const $row = $(this).closest('.pricing-code-row');
  632. $row.find('.pricing-code-input').val('');
  633. $row.find('.pricing-code-description-input').val('').prop('readonly', false);
  634. $row.find('.pricing-code-hint').text('');
  635. }
  636. });
  637. @endif
  638. });
  639. });
  640. </script>
  641. @endpush
  642. @endsection