This commit is contained in:
Николай 2023-05-19 20:00:42 +04:00
parent 85f38e9539
commit d5438a4090
2 changed files with 26 additions and 20 deletions

View File

@ -21,8 +21,9 @@
<thead> <thead>
<tr> <tr>
<th scope="col">Товар</th> <th scope="col">Товар</th>
<th scope="col">Количество</th>
<th scope="col">Цена</th> <th scope="col">Цена</th>
<th scope="col">Количество</th>
<th scope="col">Сумма</th>
<th scope="col">Действие</th> <th scope="col">Действие</th>
</tr> </tr>
</thead> </thead>
@ -70,6 +71,7 @@
console.log('try to add good') console.log('try to add good')
var count = $('#count').val(); var count = $('#count').val();
var good = $('#good').val(); var good = $('#good').val();
if (count > 0 && good > 0){
$.ajax({ $.ajax({
method: "GET", method: "GET",
url: `/Home/GetGood`, url: `/Home/GetGood`,
@ -89,6 +91,7 @@
countElem.value = '1' countElem.value = '1'
} }
}); });
}
}) })
saveBtn.addEventListener("click", () => { saveBtn.addEventListener("click", () => {
@ -126,7 +129,8 @@
let price = 0; let price = 0;
let count = 0; let count = 0;
list.forEach((elem) => { list.forEach((elem) => {
resultTable.innerHTML += `<tr><td>${elem.good.goodName}</td><td>${elem.count}</td><td>${Math.round(elem.good.price * elem.count * 100) / 100}</td><td> \ console.log(elem);
resultTable.innerHTML += `<tr><td>${elem.good.goodName}</td><td>${elem.good.price}</td><td>${elem.count}</td><td>${Math.round(elem.good.price * elem.count * 100) / 100}</td><td> \
<div> \ <div> \
<button onclick="deleteGood(${count})" type="button" class="btn btn-danger"> \ <button onclick="deleteGood(${count})" type="button" class="btn btn-danger"> \
<i class="fa fa-trash" aria-hidden="true"></i> \ <i class="fa fa-trash" aria-hidden="true"></i> \

View File

@ -72,25 +72,27 @@
console.log('try to add good') console.log('try to add good')
var count = $('#count').val(); var count = $('#count').val();
var good = $('#good').val(); var good = $('#good').val();
$.ajax({ if (count > 0 && good > 0) {
method: "GET", $.ajax({
url: `/Home/GetGood`, method: "GET",
data: { Id: good }, url: `/Home/GetGood`,
success: function (result) { data: { Id: good },
let flag = false success: function (result) {
if (list.length > 0) { let flag = false
list.forEach((elem) => { if (list.length > 0) {
if (elem.good.id === parseInt(result.id)) { list.forEach((elem) => {
console.log('good already added') if (elem.good.id === parseInt(result.id)) {
flag = true console.log('good already added')
} flag = true
}) }
})
}
if (!flag) list.push({ good: result, count: count })
reloadTable()
countElem.value = '1'
} }
if (!flag) list.push({ good: result, count: count }) });
reloadTable() }
countElem.value = '1'
}
});
}) })
saveBtn.addEventListener("click", () => { saveBtn.addEventListener("click", () => {