對於名單頁面增加 新增成員、刪除成員等功能

This commit is contained in:
威勝 張 2024-05-22 09:42:01 +08:00
parent 68d7119856
commit 31b25bb5c8

View File

@ -1,12 +1,76 @@

@{
@{
ViewData["Title"] = "Engineering_parking_user_list_index";
Layout = "~/Views/Shared/_Layout_Engineering.cshtml";
}
<h1>校內停車場使用者名單</h1>
<div class="size2">
<button class="btn btn-primary" onclick="create_user()">新增成員</button>
<table class="table">
<thead>
<tr>
<th>
成員
</th>
<th>
車牌號碼
</th>
<!--
<th>
狀態確認
</th>-->
<th></th>
</tr>
</thead>
<tbody id="demo">
</tbody>
</table>
</div>
<!--新增使用者-->
<div>
<dialog id="add_user_view" style="width:80%">
<div class="container form-container">
<div class="row">
<div class="col-12 text-right">
<button class="btn btn-danger" onclick="add_user_view.close();">關閉</button>
</div>
</div>
<div class="row mt-3">
<div class="col-12">
<div class="form-group">
<label for="add_user_name_text_id">成員名稱:</label>
<input type="text" class="form-control" id="add_user_name_text_id" />
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="form-group">
<label for="add_user_license_plate_number_text_id">車牌號碼:</label>
<input type="text" class="form-control" placeholder="請輸入車牌 ex:ABC4321" id="add_user_license_plate_number_text_id" />
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-12 text-right">
<button class="btn btn-success" onclick="post_user()">上傳</button>
</div>
</div>
</div>
</dialog>
</div>
@ -14,27 +78,101 @@
<!--新增成員-->
<script>
function set_data(Model) {
console.log(Model)
function create_user() {
document.getElementById("add_user_name_text_id").value="";
document.getElementById("add_user_license_plate_number_text_id").value="";
add_user_view.showModal()
}
function post_user() {
var user_name = document.getElementById("add_user_name_text_id").value;
var license_plate_number = document.getElementById("add_user_license_plate_number_text_id").value;
var user_state_check = 'True'
var obj = { user_license_plate_number: license_plate_number, user_name: user_name, user_state_check: user_state_check }
var stringify_obj = JSON.stringify(obj);
$.ajax({
type: "POST",
url: "http://140.125.20.183:7700/api/Yuntech_parking_user_list",
data: stringify_obj,
contentType: "application/json",
headers: {
'Authorization': token
},
success: function (msg) {
console.log(msg)
if (msg == 'ok') {
add_user_view.close()
alert("上傳完成");
get_data()
}
if (msg == '車牌重複') {
alert("車牌重複");
}
//test_upload_bt_2()
//wait_view()
}
});
}
</script>
<!--Get_data-->
<!--設置資料-->
<script>
function set_data(Model) {
console.log(Model)
table = "<tr>";
//console.log(Model.length)
if (Model.length > 0) {
for (var i = 0; i < Model.length; i++) {
table += "<td>" + Model[i].user_name + "</td>"
table += "<td id='" + Model[i].user_license_plate_number + "_total'>" + Model[i].user_license_plate_number + "</td>"
/*
if (Model[i].user_state_check == "True") {
table += "<td>" + "ok" + "</td>"
}
else {
table += "<td>" + "Not ok" + "</td>"
}*/
table += "<td>" + '<button class="btn btn-outline-success" onclick="detail_data(' + "'" + Model[i].user_license_plate_number + "'" + ')">詳細</button>'
table += '<button class="btn btn-danger " onclick="delet_data(' + "'" + Model[i].user_license_plate_number +"'"+ ')">刪除</button>' + "</td>"
table += "</tr>"
table += "<tr>"
}
}
document.getElementById("demo").innerHTML = table
}
</script>
<!--刪除資料-->
<script>
function delet_data(license_plate_number) {
$.ajax({
type: "DELETE",
url: "http://140.125.20.183:7700/api/Yuntech_parking_user_list/" + license_plate_number,
data: {},
contentType: "application/json",
headers: {
'Authorization': token
},
success: function (msg) {
console.log(msg)
get_data()
}
});
}
</script>
<!--獲取資料-->
<script>
function get_data() {
$.ajax({
@ -56,6 +194,9 @@
}
</script>
<!--檢查token-->
<script>
var token