до прорисовки страницы, ajax отправлял один массив, после фильтрации и прорисовки отфильтрованных данных ajax стал отсылать 2 и более массива почему ? и как это исправить ?
let idDelivery = $('#select-delivery').val();
//let jsonData = $('#transfer').val();
$('#btn__submit').click(function(e) {
e.preventDefault();//выключает дефолтное поведение формы
let result = [];
$('.row__delivery').each(function () {
let values = {
row_id: null,
dep: idDelivery,
count: 0
};
//если не будет лагать, то оставляй такую реализацию
$(this).find('input').each(function () {
if ($(this).attr('name') === 'id') {
values.row_id = $(this).val();
}
if ($(this).attr('name') === 'quantity') {
values.count = Number($(this).val());
}
});
if (values.count > 0) {
result.push(values);
}
});
console.log(result)
$.ajax({
type: 'POST',
url: "{{route('pharmacy.transfer.to.dep')}}",
data: {
'_token': $('meta[name="_token"]').attr('content'),
'json': result,
},
success: function (data) {
if (data.status == false) {
alert(data.msg)
}
}
});
// jsonData = JSON.stringify(result);
});
function ajaxReq(el) {
data = {...data, ...el, '_token': $('meta[name="_token"]').attr('content')};
const url = el.url ? el.url : "{{route('pharmacy.filter.sklad')}}";
delete el.url
$.ajax({
type: 'POST',
url,
data,
success: function (response) {
const rows = response.data.reduce(function (result, item) {
result += `
<div class="row row__delivery">
<input name="id" type="hidden" value="${item.id}" class="input__delivery-row">
<div class="cell cell__tbody cell__tbody-width-318">
<p class="tbody__text tbody__text-name">${item.name}</p>
</div>
<div class="cell cell__tbody cell__tbody-width-158">
<p class="tbody__text">${item.mnn}</p>
</div>
<div class="cell cell__tbody cell__tbody-width-160">
<p class="tbody__text">${item.party}</p>
</div>
<div class="cell cell__tbody cell__tbody-width-92">
<p class="tbody__text">${item.purpose}</p>
</div>
<div class="cell cell__tbody cell__tbody-width-92">
<p class="tbody__text">${modifyDate(item.date_of_receipt)}</p>
</div>
<div class="cell cell__tbody cell__tbody-width-92 reletive">
<p class="tbody__text">${modifyDate(item.expiration_date)}</p>
<div class="attantion__box">
<div class="attention">
<img src="{{$_SERVER['REQUEST_SCHEME']}}://{{$_SERVER['SERVER_NAME']}}/img/attention.svg" alt="" class="attention__img">
</div>
<p class="attantion-text">ДАТА ПОСТАВКИ УЖЕ ПРОШЛА</p>
</div>
<div class="attention__orange-box">
<div class="attention-orange">
<img src="{{$_SERVER['REQUEST_SCHEME']}}://{{$_SERVER['SERVER_NAME']}}/img/attention_black.svg" alt="" class="attention__img">
</div>
<p class="attantion__orange-text">ДАТА ПОСТАВКИ УЖЕ ПРОШЛА</p>
</div>
</div>
<div class="cell cell__tbody cell__tbody-width-92">
<p class="tbody__text">${item.quantity}</p>
</div>
<div class="cell cell__tbody cell__tbody-width-92">
<p class="tbody__text">${item.status}</p>
</div>
<div class="cell cell__tbody cell__tbody-width-160">
<div class="pharmacy__counter">
<div class="counter__button pharmacy__counter-plus">
<img src="{{$_SERVER['REQUEST_SCHEME']}}://{{$_SERVER['SERVER_NAME']}}/img/plus_icon.svg" alt="icon" class="pharmacy__counter-plus-img">
</div>
<input type="text" class="tbody__text count__click count__delivery" name="quantity" value="0">
<div class="counter__button pharmacy__counter-minus">
<img src="{{$_SERVER['REQUEST_SCHEME']}}://{{$_SERVER['SERVER_NAME']}}/img/minus_icon.svg" alt="icon" class="pharmacy__counter-minus-img">
</div>
</div>
</div>
</div>
`;
return result;
}, '');
rowsH.innerHTML = rows;
let counterDelivery = document.querySelectorAll('.counter__delivery');
let inputDeliveryRow = document.querySelectorAll('.input__delivery-row');
let rowDelivery = document.querySelectorAll('.row__delivery');
const pharmacyCounterPlus = document.querySelectorAll('.pharmacy__counter-plus');
const pharmacyCounterMinus = document.querySelectorAll('.pharmacy__counter-minus');
pharmacyCounterPlus.forEach(el => {
el.addEventListener('click', () => {
let val = el.nextElementSibling.value++;
el.nextElementSibling.defaultValue = val + 1;
});
});
pharmacyCounterMinus.forEach(el => {
el.addEventListener('click', () => {
if (el.previousElementSibling.value < 1) {
el.previousElementSibling.value = 0;
} else {
let val = el.previousElementSibling.value--;
el.previousElementSibling.defaultValue = val - 1;
}
});
});
const paginationLinks = response.links.reduce(function (result, item) {
if (!item.url) return result;
result += `
<li class="page-item">
<a class="page-link" href='#' onclick="changePage({url: '${item.url}'})">${item.label}</a>
</li>
`;
return result
}, '');
pagination.innerHTML = paginationLinks;
let idDelivery = $('#select-delivery').val();
$('#btn__submit').click(function (e) {
e.preventDefault();
e.stopPropagation();
let result = [];
$('.row__delivery').each(function () {
let values = {
row_id: null,
dep: idDelivery,
count: 0
};
//если не будет лагать, то оставляй такую реализацию
$(this).find('input').each(function () {
if ($(this).attr('name') === 'id') {
values.row_id = $(this).val();
}
if ($(this).attr('name') === 'quantity') {
values.count = Number($(this).val());
}
});
if (values.count > 0) {
result.push(values);
}
});
console.log(result)
//ajaxTransfer(result)
});
}
});
}