reserve/public/admin.js
2023-09-24 14:31:12 +08:00

128 lines
2.9 KiB
JavaScript

function flush_reserve_info() {
$.get('/get_reserve_info', (data, status)=> {
let json = JSON.parse(data)
console.log(json)
let day = $('#select-day').val()
if(day != '...') {
for(let time=1; time<=6; time++) {
let info = json[`${day}-${time}`]
let text = $(`#reserve-${time}`).text()
if(info.name != '') {
if(!text.includes('[')) {
$(`#reserve-${time}`).text(text + " [已预约]")
// $(`#radio-${time}`).prop("disabled", true);
$(`#radio-${time}`).prop("checked", false);
}
} else {
if(text.includes(']')) {
$(`#reserve-${time}`).text(text.replace(" [已预约]", ""))
$(`#radio-${time}`).prop("disabled", false);
}
}
}
}
})
}
flush_reserve_info()
const intervalId = setInterval(flush_reserve_info, 1000);
$(document).ready(function() {
$("#clear-btn").click(()=>{
$("#main").hide()
$("#pending").show();
let password = $("#password").val();
// 创建表单数据对象
let formData = {
password: password,
};
// 发送POST请求
$.ajax({
url: "/clear",
type: "POST",
data: formData,
timeout: 2000, // 设置超时时间
success: function(response) {
// 请求成功的处理逻辑
console.log(response);
$('#server-message').text(response.message)
},
error: function(xhr, status, error) {
// 请求失败的处理逻辑
console.log(error);
},
complete: function(xhr, status) {
// 请求完成的处理逻辑(无论成功或失败)
console.log(status);
}
});
});
$("#back-btn").click(()=>{
$("#main").show()
$("#pending").hide();
})
$("#submit-btn").click(function() {
$("#main").hide()
$("#pending").show();
let day = $("#select-day").val();
let time = -1;
for(let i=1; i<=6; i++) {
if($(`#radio-${i}`).prop('checked')) {
time = i
}
}
let password = $("#password").val();
// 创建表单数据对象
let formData = {
day: day,
time: time,
password: password,
};
// 发送POST请求
$.ajax({
url: "/unreserve",
type: "POST",
data: formData,
timeout: 2000, // 设置超时时间
success: function(response) {
// 请求成功的处理逻辑
console.log(response);
$('#server-message').text(response.message)
},
error: function(xhr, status, error) {
// 请求失败的处理逻辑
console.log(error);
},
complete: function(xhr, status) {
// 请求完成的处理逻辑(无论成功或失败)
console.log(status);
}
});
});
});