|
|
@@ -6,6 +6,9 @@
|
|
|
<div class="col-5">
|
|
|
<div class="">Всего найдено: {{ $products->total() }}</div>
|
|
|
{{ $products->links() }}
|
|
|
+ Выбрано: <span id="count_selected">0</span>
|
|
|
+ <button class="btn btn-sm btn-primary mx-3" onclick="select_export()">Экспорт</button>
|
|
|
+ <button class="btn btn-sm btn-primary" onclick="reset_selected()">Сбросить выбор</button>
|
|
|
</div>
|
|
|
<div class="col-7">
|
|
|
<form class="" action="" method="get">
|
|
|
@@ -63,9 +66,8 @@
|
|
|
<thead>
|
|
|
<tr class="align-middle">
|
|
|
<th class="text-center">Артикул, Серия<br>
|
|
|
- <label><input type="checkbox" onchange="toggle(this)"> Все</label>
|
|
|
+ <label><input type="checkbox" class="check_all" onchange="toggle(this)"> Все</label>
|
|
|
</th>
|
|
|
-
|
|
|
<th>Группа <br> Наименование <br> Наименование под образец формы</th>
|
|
|
<th>Цена</th>
|
|
|
<th>Характеристики</th>
|
|
|
@@ -79,7 +81,7 @@
|
|
|
<tr class="align-middle prod-tr">
|
|
|
<td class="text-center">
|
|
|
<label>
|
|
|
- <input type="checkbox" class="form-check-inline me-0 prd-chk" name="ids" value="{{ $product->id }}"><br>
|
|
|
+ <input type="checkbox" onchange="select_product({{ $product->id }}, this)" class="form-check-inline me-0 prd-chk" name="ids" value="{{ $product->id }}"><br>
|
|
|
{{ $product->article }}<br>
|
|
|
{{ $product->series }}
|
|
|
</label>
|
|
|
@@ -116,15 +118,80 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
+ <form action="{{ route('select_export') }}" method="post" class="visually-hidden" id="select_export">
|
|
|
+ @csrf
|
|
|
+ <textarea name="ids" id="ids"></textarea>
|
|
|
+
|
|
|
+ </form>
|
|
|
|
|
|
<script>
|
|
|
function toggle(source) {
|
|
|
let checkboxes = document.querySelectorAll('.prd-chk');
|
|
|
for(let i =0; i < checkboxes.length; i++){
|
|
|
checkboxes[i].checked = source.checked;
|
|
|
+ select_product(checkboxes[i].value, source);
|
|
|
+ }
|
|
|
+ calc_selected();
|
|
|
+ }
|
|
|
+
|
|
|
+ function select_product(id, status){
|
|
|
+ let selected_products = JSON.parse(localStorage.getItem('selected_products'));
|
|
|
+ if(!selected_products) selected_products = [];
|
|
|
+
|
|
|
+ console.log(status.checked);
|
|
|
+
|
|
|
+ if(status.checked){
|
|
|
+ // console.log('select '+id);
|
|
|
+ if(!selected_products.includes(id)){
|
|
|
+ selected_products.push(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // console.log('deselect '+id);
|
|
|
+ const index = selected_products.indexOf(id);
|
|
|
+ if(index > -1){
|
|
|
+ selected_products.splice(index, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ localStorage.setItem('selected_products', JSON.stringify(selected_products));
|
|
|
+ calc_selected();
|
|
|
+ }
|
|
|
+
|
|
|
+ function calc_selected(){
|
|
|
+ let selected_products = JSON.parse(localStorage.getItem('selected_products'));
|
|
|
+ if(!selected_products) selected_products = [];
|
|
|
+ document.getElementById('count_selected').innerText = selected_products.length;
|
|
|
+
|
|
|
+ let checkboxes = document.querySelectorAll('.prd-chk');
|
|
|
+ for(let i =0; i < checkboxes.length; i++){
|
|
|
+
|
|
|
+ if(selected_products.includes(checkboxes[i].value)){
|
|
|
+ checkboxes[i].checked = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function reset_selected(){
|
|
|
+ localStorage.setItem('selected_products', JSON.stringify([]));
|
|
|
+ let checkboxes = document.querySelectorAll('.prd-chk');
|
|
|
+ for(let i =0; i < checkboxes.length; i++) {
|
|
|
+ checkboxes[i].checked = false;
|
|
|
}
|
|
|
+ document.querySelector('.check_all').checked = false;
|
|
|
+
|
|
|
+ calc_selected();
|
|
|
}
|
|
|
|
|
|
+ function select_export(){
|
|
|
+ let selected_products = localStorage.getItem('selected_products')
|
|
|
+ //document.location = '{{ route('select_export') }}?ids='+selected_products;
|
|
|
+ document.getElementById('ids').value = selected_products;
|
|
|
+ document.getElementById('select_export').submit();
|
|
|
+ }
|
|
|
+
|
|
|
+ calc_selected();
|
|
|
+
|
|
|
|
|
|
|
|
|
|