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

104 lines
2.3 KiB
Plaintext
Raw Normal View History

2024-06-01 03:18:46 +04:00
@using ElectronicsShopContracts.ViewModels
@using ElectronicsShopDataModels.Models
@model (int, Dictionary<int, (IProductModel, int)>)
@{
ViewData["Title"] = "Payment";
}
<div class="text-center">
<h1 class="display-4">Оплата корзины</h1>
</div>
<form method="post">
<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>
<div class=" text-center">
2024-06-01 05:00:05 +04:00
<div class="row">
<div class="col-4">Сумма платежа:</div>
<div class="col-8">
<input type="text" name="paysum" id="paysum" />
</div>
</div>
<div class="row">
<div class="col-4">Сумма к оплате:</div>
<div class="col-8">
<input type="text" name="sum" id="sum" readonly />
</divЫ>
<input type="submit" value="Оплатить!" class="btn btn-primary" />
</div>
2024-06-01 03:18:46 +04:00
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Продукт
</th>
<th>
Количество
</th>
<th>
Сумма
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Item2)
{
<tr class="element">
<th>
@Html.DisplayFor(modelItem => item.Key)
</th>
<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>
</tr>
}
</tbody>
</table>
2024-06-01 03:39:57 +04:00
2024-06-01 03:18:46 +04:00
<div class="row">
<div class="col-4"></div>
<div class="col-8">
2024-06-01 05:00:05 +04:00
<a class="btn btn-primary btn-sm" asp-action="Index">Отменить - вернуться на главную страницу</a>
2024-06-01 03:18:46 +04:00
</div>
</div>
</div>
2024-06-01 05:00:05 +04:00
<script src="~/lib/jquery/dist/jquery.min.js"></script>
2024-06-01 03:39:57 +04:00
</form>
<script>
2024-06-01 05:00:05 +04:00
$('#btn').on('click', function () {
calc();
2024-06-01 03:39:57 +04:00
});
2024-06-01 05:00:05 +04:00
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);
2024-06-01 03:39:57 +04:00
}
</script>