144 lines
3.0 KiB
Plaintext
Raw Normal View History

2024-08-22 20:40:32 +04:00
@using ServiceStationContracts.ViewModels
@{
ViewData["Title"] = "CreateWork";
2024-04-30 21:22:23 +03:00
}
2024-08-22 20:40:32 +04:00
@model List<ClientViewModel>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
2024-04-30 21:22:23 +03:00
<div class="text-center">
2024-08-22 20:40:32 +04:00
<h2 class="display-4">Создать работу</h2>
2024-04-30 21:22:23 +03:00
</div>
2024-08-22 20:40:32 +04:00
2024-04-30 21:22:23 +03:00
<form method="post">
<div class="row">
2024-08-22 20:40:32 +04:00
<div class="col-4">Задача:</div>
2024-04-30 21:22:23 +03:00
<div class="col-8">
2024-08-22 20:40:32 +04:00
<select id="task" name="task" class="form-control" asp-items="@(new SelectList(ViewBag.Tasks, "Id", "Name"))"></select>
2024-04-30 21:22:23 +03:00
</div>
</div>
<div class="row">
2024-08-22 20:40:32 +04:00
<div class="col-4">Стоимость:</div>
<div class="col-8">
<input id="price" type="text" name="price" readonly />
</div>
2024-04-30 21:22:23 +03:00
</div>
2024-08-22 20:40:32 +04:00
</form>
<div class="text-center">
<h2 class="display-5">Выбрать клиентов в работу</h2>
</div>
<div class="text-center">
@{
if (Model == null) {
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<div class="text-end">
<button class="btn btn-outline-primary" id="btnCreate">Создать</button>
</div>
<table class="table">
<thead>
<tr>
<th>
Номер клиента
</th>
<th>
ФИО клиента
</th>
<th>
<input type="checkbox" class="form-check-input" id="Select_all" name="Select_all" /> Выбрать все
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<th>
@Html.DisplayFor(modelItem => item.Id)
</th>
<th>
@Html.DisplayFor(modelItem => item.FIO)
</th>
<th>
<input type="checkbox" class="form-check-input" id="Select_rec" name="Select_rec" value="@item.Id" />
</th>
</tr>
}
</tbody>
</table>
}
</div>
<script>
$('#task').on('change', function () {
check();
});
$('.form-check-input').on('change', function () {
check();
});
check();
function check() {
var task = $('#task').val();
let checkboxes = document.getElementsByTagName('input');
var count = 0;
$("input[name='Select_rec']:checked").each(function () {
count++;
});
if (task && count >= 0) {
$.ajax({
method: 'POST',
url: '/Home/Calc',
data: {task: task, count: count},
success: function (result) {
$('#price').val(result)
},
error: function () {
}
})
};
}
$('#Select_all').on('click', function () {
let checkboxes = document.getElementsByTagName('input');
let val = null;
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type === 'checkbox') {
if (val == null) {
val = checkboxes[i].checked;
}
else {
checkboxes[i].checked = val;
}
}
}
check();
});
$('#btnCreate').on('click', function () {
let val = [];
var task = $('#task').val();
$("input[name='Select_rec']:checked").each(function () {
val.push($(this).val());
});
$.ajax({
type: 'POST',
url: '/Home/CreateWork',
data: {'ids':val, 'task': task},
success: function () {
2024-08-23 19:44:26 +04:00
window.location.href = "Index";
2024-08-22 20:40:32 +04:00
},
error: function () {
2024-08-23 19:44:26 +04:00
window.location.href = "Index";
2024-08-22 20:40:32 +04:00
}
})
});
</script>