CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/OrderView.cshtml

105 lines
2.4 KiB
Plaintext
Raw Normal View History

@using ElectronicsShopContracts.ViewModels
2024-05-31 16:05:43 +04:00
@using ElectronicsShopDataModels.Models
2024-06-01 00:42:46 +04:00
@model (int, Dictionary<int, (IProductModel, int)>)
@{
2024-05-30 23:49:53 +04:00
ViewData["Title"] = "OrderView";
}
<div class="text-center">
<h1 class="display-4">Создание корзины</h1>
</div>
2024-06-01 00:42:46 +04:00
2024-05-31 16:05:43 +04:00
<form method="post">
2024-06-01 00:42:46 +04:00
<div class="row">
<div class="col-4"></div>
<div class="col-8">
<input id="id" type="hidden" name="id" readonly value="@Model.Item1" />
</div>
</div>
2024-05-31 16:05:43 +04:00
<div class=" text-center">
2024-05-30 23:49:53 +04:00
<div class="row">
2024-05-31 16:05:43 +04:00
<div class="col-4">Сумма:</div>
2024-05-30 23:49:53 +04:00
<div class="col-8">
2024-05-31 16:05:43 +04:00
<input id="sum" type="text" name="sum" readonly />
2024-05-30 23:49:53 +04:00
</div>
</div>
<p>
<a asp-action="AddProduct">Добавить товар</a>
</p>
<table class="table">
<thead>
<tr>
2024-06-01 00:42:46 +04:00
<th>
Номер
</th>
<th>
Продукт
</th>
<th>
Количество
</th>
<th>
Сумма
</th>
</tr>
</thead>
<tbody>
2024-06-01 00:42:46 +04:00
@foreach (var item in Model.Item2) {
2024-05-31 16:05:43 +04:00
<tr class="element">
2024-06-01 00:42:46 +04:00
<th>
@Html.DisplayFor(modelItem => item.Key)
</th>
<th>
@Html.DisplayFor(modelItem => item.Value.Item1.ProductName)
</th>
2024-05-31 16:05:43 +04:00
<th class="count">
@Html.DisplayFor(modelItem => item.Value.Item2)
</th>
<th class="countsum">
@Html.DisplayFor(modelItem => item.Value.Item1.Price)
</th>
2024-06-01 00:42:46 +04:00
<td>
<a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" asp-route-ID="@item.Key">Удалить</a>
</td>
</tr>
}
2024-06-01 02:45:59 +04:00
</tbody>
</table>
2024-05-31 16:05:43 +04:00
<div class="row">
<div class="col-4"></div>
<div class="col-8">
<input type="submit" value="Заказ готова, вернуться!" class="btn btn-primary" />
2024-06-01 02:45:59 +04:00
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" asp-route-ID="@Model.Item1">Отменить создание корзины</a>
2024-05-31 16:05:43 +04:00
</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>