// === 1. 初始化 Firebase ===
const firebaseConfig = {
apiKey: "AIzaSyCeHnTHI6tSUIxbZPPE_E1tKG1fARxJQDk",
authDomain: "cutcourse-c8e40.firebaseapp.com",
databaseURL: "https://cutcourse-c8e40-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "cutcourse-c8e40",
storageBucket: "cutcourse-c8e40.firebasestorage.app",
messagingSenderId: "545043504119",
appId: "1:545043504119:web:7059fd0b7ab7f8e841acf2"
};
// 確保 Firebase 只初始化一次
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
const database = firebase.database();
// === 2. 報名表單送出功能 ===
function submitForm() {
const name = document.getElementById('name').value;
const phone = document.getElementById('phone').value;
const email = document.getElementById('email').value;
const message = document.getElementById('msgInput').value;
if (!name || !phone) { alert("請填寫姓名與手機號碼!"); return; }
const postData = {
name: name,
phone: phone,
email: email,
message: message,
status: "審核中",
teacherReply: "老師正在閱讀您的訊息,請稍候...",
timestamp: Date.now()
};
// 使用手機號碼作為唯一 Key 值
database.ref('registrations/' + phone).set(postData)
.then(() => {
alert("報名成功!請記住您的手機號碼,可用於下方查詢進度。");
document.getElementById('regForm').reset();
})
.catch(err => alert("報名失敗:" + err.message));
}
// === 3. 進度查詢功能 (修正關鍵) ===
function checkStatus() {
const sPhone = document.getElementById('searchPhone').value;
const resultDiv = document.getElementById('statusResult');
if (!sPhone) { alert("請輸入手機號碼!"); return; }
// 即時監聽 registrations 節點
database.ref('registrations/' + sPhone).on('value', (snapshot) => {
const data = snapshot.val();
if (data) {
// 顯示隱藏的查詢結果區(包含補充提問區)
resultDiv.style.display = 'block';
document.getElementById('statusLabel').innerText = data.status || "審核中";
document.getElementById('replyContent').innerText = data.teacherReply || "等待導師回覆中...";
// 根據狀態改變顏色
const statusLabel = document.getElementById('statusLabel');
if(data.status === "已核可" || data.status === "老師已回覆") {
statusLabel.style.color = "#a28900"; // 活力金/紫色系
}
} else {
alert("查無此號碼的報名紀錄。");
resultDiv.style.display = 'none';
}
});
}
// === 4. 補充提問功能 (這就是你在截圖中沒看到的邏輯) ===
function submitExtraMessage() {
const sPhone = document.getElementById('searchPhone').value;
const extraMsg = document.getElementById('extraMsgInput').value;
if (!extraMsg) { alert("請輸入訊息內容!"); return; }
// 更新到資料庫,並將狀態跳回「審核中」提醒老師
database.ref('registrations/' + sPhone).update({
message: extraMsg,
status: "審核中"
}).then(() => {
alert("補充訊息已送出,老師會盡快回覆您!");
document.getElementById('extraMsgInput').value = ""; // 清空輸入框
}).catch(err => alert("送出失敗:" + err.message));
}
報名進度查詢
輸入手機號碼獲取審核結果:
當前進度:
您的提問紀錄:
載入中...
Academy Coach 的回覆:
等待導師回覆中...