const { get } = require('../../../utils/http'); Page({ data: { homeworkList: [], // 作业列表数据 pageIndex: 1, // 当前页码 pageSize: 10, // 每页数量 isLoading: false, // 加载状态 hasMore: true, // 是否有更多数据 totalCount: 0, // 总数据量 }, onLoad(options) { this.loadHomeworkData(true); }, onShow(){ }, // 加载作业数据 loadHomeworkData(showLoading = false) { if (this.data.isLoading || !this.data.hasMore) return; this.setData({ isLoading: true }); if (showLoading) { wx.showLoading({ title: '加载中...' }); } let params = { PageIndex: this.data.pageIndex, PageSize: this.data.pageSize, IsHistory :true }; // 使用get方法调用接口 get('Patriarch/HomeWorkRecordByTeacher', params) .then(res => { wx.hideLoading(); if (res.success) { const newList = this.processHomeworkData(res.data.datas || []); this.setData({ homeworkList: this.data.pageIndex === 1 ? newList : [...this.data.homeworkList, ...newList], pageIndex: this.data.pageIndex + 1, hasMore: (this.data.homeworkList.length + newList.length) < (res.data.total || 0), totalCount: res.data.total || 0 }); } else { wx.showToast({ title: res.message || "加载失败", icon: "none" }); } }) .catch(err => { wx.hideLoading(); console.error("加载作业失败:", err); wx.showToast({ title: "网络错误", icon: "none" }); }) .finally(() => { this.setData({ isLoading: false }); if (showLoading) { wx.hideLoading() wx.stopPullDownRefresh(); } }); }, // 处理作业数据 processHomeworkData(list) { return list.map(item => { // 根据实际返回字段调整 const status = item.workStatus || 0; // 默认未开始 return { id: item.id, name: item.workName +'-'+ item.workTypeName, startTime: this.formatTime(item.startTime), endTime: this.formatTime(item.endTime), statusText: this.getStatusText(status), statusClass: this.getStatusClass(status) }; }); }, // 格式化时间(简单示例) formatTime(timeStr) { if (!timeStr) return '--'; // 简单处理,实际应根据接口返回格式调整 return timeStr.length > 10 ? timeStr.substring(0, 10) : timeStr; }, // 获取状态文本 getStatusText(status) { const statusMap = { 1: '未开始', 2: '进行中', 3: '已结束' }; return statusMap[status] || ''; }, // 获取状态class getStatusClass(status) { const classMap = { 1: 'not-started', 2: 'in-progress', 3: 'ended' }; return classMap[status] || ''; }, // wxb15c952e563a9517 // // 下拉刷新 onPullDownRefresh() { this.setData({ homeworkList: [], pageIndex: 1, hasMore: true }); this.loadHomeworkData(true); }, // 上拉加载更多 onReachBottom() { this.loadHomeworkData(); }, // 点击作业项 onHomeworkItemTap(e) { const { id } = e.currentTarget.dataset; wx.navigateTo({ url: `/subpackage/teacher/homework-detail/home-detail?id=${id}` }); }, // goDetail(e){ // const {item} = e.currentTarget.dataset // }, newWork(){ wx.navigateTo({ url: '/subpackage/teacher/new-work/new-work', }) }, historyWork(){ wx.navigateTo({ url: '', }) } });