CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Payment.cshtml
Илья Федотов a8ccf282e3 bug fixes
2024-06-09 20:35:36 +04:00

104 lines
2.3 KiB
Plaintext

@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">
<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>
<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>
<div class="row">
<div class="col-4"></div>
<div class="col-8">
<a class="btn btn-primary btn-sm" style="background-color:red;" asp-action="Index">Отменить - вернуться на главную страницу</a>
</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>