import wixData from 'wix-data'; import wixWindow from 'wix-window'; // 假設 Table 綁定到 Lessons Collection // 每列的按鈕 ID:startBtn, endBtn, leaveBtn, rescheduleBtn $w.onReady(function () { // 綁定按鈕事件 $w("#lessonTable").onItemReady(($item, itemData, index) => { // 開始上課 $item("#startBtn").onClick(() => { itemData.actualStart = new Date(); itemData.status = "出席"; updateLesson(itemData); }); // 結束上課 $item("#endBtn").onClick(() => { itemData.actualEnd = new Date(); updateLesson(itemData); }); // 請假(檢查每月請假次數) $item("#leaveBtn").onClick(() => { checkLeaveLimit(itemData.studentName).then((canLeave) => { if (canLeave) { itemData.status = "請假"; } else { itemData.status = "缺席"; itemData.notes = "已超過本月可請假次數"; } updateLesson(itemData); }); }); // 改課 $item("#rescheduleBtn").onClick(() => { wixWindow.prompt("輸入新日期 (YYYY-MM-DD):").then((dateRes) => { if (dateRes) { wixWindow.prompt("輸入新時間 (HH:MM):").then((timeRes) => { if (timeRes) { itemData.status = "改課"; itemData.rescheduleDate = new Date(dateRes); itemData.rescheduleTime = timeRes; updateLesson(itemData); } }); } }); }); }); }); // 更新課堂紀錄 function updateLesson(item) { wixData.update("Lessons", item) .then(() => { wixWindow.openLightbox("成功", { message: "課堂紀錄已更新 ✅" }); $w("#lessonTable").refresh(); }) .catch((err) => { console.error("更新失敗", err); }); } // 檢查學生本月請假次數 async function checkLeaveLimit(studentName) { let startOfMonth = new Date(); startOfMonth.setDate(1); let endOfMonth = new Date(startOfMonth); endOfMonth.setMonth(endOfMonth.getMonth() + 1); let result = await wixData.query("Lessons") .eq("studentName", studentName) .between("lessonDate", startOfMonth, endOfMonth) .eq("status", "請假") .find(); return result.totalCount < 1; // 每月只允許 1 次請假 } import wixData from 'wix-data'; import wixWindow from 'wix-window'; // 假設 Table 綁定到 Lessons Collection // 每列的按鈕 ID:startBtn, endBtn, leaveBtn, rescheduleBtn $w.onReady(function () { // 綁定按鈕事件 $w("#lessonTable").onItemReady(($item, itemData, index) => { // 開始上課 $item("#startBtn").onClick(() => { itemData.actualStart = new Date(); itemData.status = "出席"; updateLesson(itemData); }); // 結束上課 $item("#endBtn").onClick(() => { itemData.actualEnd = new Date(); updateLesson(itemData); }); // 請假(檢查每月請假次數) $item("#leaveBtn").onClick(() => { checkLeaveLimit(itemData.studentName).then((canLeave) => { if (canLeave) { itemData.status = "請假"; } else { itemData.status = "缺席"; itemData.notes = "已超過本月可請假次數"; } updateLesson(itemData); }); }); // 改課 $item("#rescheduleBtn").onClick(() => { wixWindow.prompt("輸入新日期 (YYYY-MM-DD):").then((dateRes) => { if (dateRes) { wixWindow.prompt("輸入新時間 (HH:MM):").then((timeRes) => { if (timeRes) { itemData.status = "改課"; itemData.rescheduleDate = new Date(dateRes); itemData.rescheduleTime = timeRes; updateLesson(itemData); } }); } }); }); }); }); // 更新課堂紀錄 function updateLesson(item) { wixData.update("Lessons", item) .then(() => { wixWindow.openLightbox("成功", { message: "課堂紀錄已更新 ✅" }); $w("#lessonTable").refresh(); }) .catch((err) => { console.error("更新失敗", err); }); } // 檢查學生本月請假次數 async function checkLeaveLimit(studentName) { let startOfMonth = new Date(); startOfMonth.setDate(1); let endOfMonth = new Date(startOfMonth); endOfMonth.setMonth(endOfMonth.getMonth() + 1); let result = await wixData.query("Lessons") .eq("studentName", studentName) .between("lessonDate", startOfMonth, endOfMonth) .eq("status", "請假") .find(); return result.totalCount < 1; // 每月只允許 1 次請假 }
top of page
bottom of page