hku-class/miniprogram/pages/schedule-detail/index.js
2026-05-13 00:36:39 +08:00

46 lines
1.1 KiB
JavaScript

const { get } = require("../../utils/api");
const { showError } = require("../../utils/page-helpers");
function formatDateTime(value) {
if (!value) return "";
return String(value).replace("T", " ").slice(0, 16);
}
function scheduleTypeText(type) {
return {
course: "课程",
deadline: "截止日",
activity: "活动"
}[type] || type || "排期";
}
Page({
data: { item: null, loading: false },
onLoad(options) {
wx.setNavigationBarTitle({ title: "排期详情" });
this.load(options.id);
},
async load(id) {
if (!id) return;
this.setData({ loading: true });
try {
const item = await get(`/api/schedule/${id}`);
this.setData({
item: {
...item,
start_time_text: formatDateTime(item.start_time),
end_time_text: formatDateTime(item.end_time),
type_text: scheduleTypeText(item.type),
start_label: item.type === "deadline" ? "截止时间" : "开始时间"
}
});
} catch (error) {
showError(error, "加载排期失败");
} finally {
this.setData({ loading: false });
}
}
});