CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/OrderView.cshtml
Илья Федотов 979625ebae Беда...
2024-05-31 16:05:43 +04:00

89 lines
1.9 KiB
Plaintext

@using ElectronicsShopContracts.ViewModels
@using ElectronicsShopDataModels.Models
@model Dictionary<int, (IProductModel, int)>
@{
ViewData["Title"] = "OrderView";
}
<div class="text-center">
<h1 class="display-4">Создание корзины</h1>
</div>
<form method="post">
<div class=" text-center">
<div class="row">
<div class="col-4">Сумма:</div>
<div class="col-8">
<input id="sum" type="text" name="sum" readonly />
</div>
</div>
<p>
<a asp-action="AddProduct">Добавить товар</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Продукт
</th>
<th>
Количество
</th>
<th>
Сумма
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr class="element">
<th>
@Html.DisplayFor(modelItem => item.Value.Item1.ProductName)
</th>
<th class="count">
@Html.DisplayFor(modelItem => item.Value.Item2)
</th>
<th class="countsum">
@Html.DisplayFor(modelItem => item.Value.Item1.Price)
</th>
<td>
<a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" asp->Удалить</a>
</td>
</tr>
}
</tbody>
</table>
<div class="row">
<div class="col-4"></div>
<div class="col-8">
<input type="submit" value="Заказ готова, вернуться!" class="btn btn-primary" />
</div>
</div>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
</form>
<script>
$('btn').on('click', function () {
calc();
});
let sum = 0;
const elementRows = document.querySelectorAll('.element');
calc();
function calc() {
elementRows.forEach(row => {
const count = parseInt(row.querySelector('.count').innerHTML, 10);
const countsum = parseInt(row.querySelector('.countsum').innerHTML, 10);
const rowTotal = count * countsum;
sum += rowTotal;
});
$('#sum').val(sum);
}
</script>