// packageCourse/pages/studentClass/index.js import { getPublicImage } from '../../../assets/js/middleGround/tool' import moment from 'moment' const app = getApp() Page({ /** * 页面的初始数据 */ data: { searchKey: '', visible: false, refCode: '', classDetail: null, classList: [], page: 1, pageSize: 10, totalSize: 0, // 加载参数 bottomLoading: false, isMoreData: false, // 返回顶部 isBackTop: false, setScrollValue: 0, skeletonLoding: true }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getCurrentClassList() }, onCourseNameInput(e) { this.setData({ refCode: e.detail.value }) }, // 通过code查询班级 getClassDetail() { if (!this.data.refCode) { wx.showToast({ title: '请输入邀请码', duration: 1000, icon: "none", }) this.setData({ classDetail: null }) return false } const data = { classIdOrRefCode: this.data.refCode } app.MG.edu .getCourseClass(data) .then(res => { if (res.linkProductDto) { res.classTime = moment(res.beginDate).format('YYYY-MM-DD') + '--' + moment(res.endDate).format('YYYY-MM-DD') this.setData({ classDetail: res }) } else { this.setData({ classDetail: null }) wx.showToast({ title: '邀请码无效', icon: "none" }) } }) .catch(err => { wx.showToast({ title: '邀请码无效', icon: "none" }) this.setData({ classDetail: null }) console.log(err) }) }, // 打开新建班级 newClass() { this.setData({ visible: true, }) }, // 关闭申请 cancle() { this.setData({ visible: false, classDetail: null, refCode: '' }) }, // 申请提交班级 submitClass() { if (!this.data.refCode) { wx.showToast({ title: '请输入邀请码', duration: 1000, icon: "none", }) return false } const data = { refCode: this.data.refCode } app.MG.identity.joinGroupByRefCode(data).then(res => { if (res == '组不存在') { wx.showToast({ title: '班级不存在', duration: 1000, icon: "none", }) } if (res == '组成员数量已最大,不能加入') { wx.showToast({ title: '已满员', duration: 1000, icon: "none", }) } if (res == '已经申请过加入此组') { wx.showToast({ title: '已申请', duration: 1000, icon: "none", }) } this.getCurrentClassList() }) }, // 获取当前班级列表 getCurrentClassList(isReachBottom) { const data = { start: (this.data.page - 1) * this.data.pageSize, size: this.data.pageSize, sort: { type: 'Desc', field: 'CreateDate', subSorts: [] }, filterList: [], searchList: this.data.searchKey ? [{ keywords: this.data.searchKey, field: 'Name', compareType: 'Contains' }] : [] } app.MG.identity.joinedGroupByList(data).then(res => { const { datas, totalSize } = res if (datas) { let list = res.datas.map(item => { return { ...item, classTime: moment(item.beginDate).format('YYYY.MM.DD') + '--' + moment(item.endDate).format('YYYY.MM.DD'), bookName: item.linkProductDto.product.name, bookIcon: getPublicImage(item.linkProductDto.product.icon, 100) } }) //触底加载新数据并保留老数据 if (isReachBottom) { list = [...this.data.classList, ...list] //将新数据加入老数据中 } this.setData({ classList: list, totalSize: totalSize, visible: false, classDetail: null, refCode: '', skeletonLoding: false, bottomLoading: false }) } }) }, // 获取教材详情 async getBookDetail(shopId, path) { let query = { path, queryType: '*', productId: String(shopId), storeInfo: path, coverSize: { height: 300, width: 210 }, fields: { author: [], isbn: [] } } const res = await app.MG.store.getProductDetail(query) return res.datas ?? null }, // 班级详情 async todetail(e) { const { classId, item } = e.currentTarget.dataset const bookRefCode = item.linkProductDto?.product?.refCode const path = bookRefCode ? 'jsek_digitalTextbooks' : 'defaultGoodsStore3' const bookData = await this.getBookDetail(item.linkProductDto?.product?.id, path) if (item.userState == 'WaitValid' || item.userState == 'Reject') { wx.showToast({ title: item.userState == 'WaitValid' ? '审核中' : '未通过', duration: 1000, icon: 'none', }) return false } wx.navigateTo({ url: '/packageCourse/pages/teachClass/index?classId=' + classId + '&bookId=' + bookData.id + '&author=' + bookData.author + '&isbn=' + bookData.isbn + '&rootCmsItemId=' + bookData.rootCmsItemId + '&bookRefCode=' + bookRefCode, }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (this._freshing) return this.setData({ page: 1, bottomLoading: false, isMoreData: false }) setTimeout(() => { this._freshing = true; this.setData({ triggered: false, }) this.getCurrentClassList(); this._freshing = false }, 500); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { if (this.data.totalSize > this.data.classList.length) { this.setData({ page: this.data.page + 1, bottomLoading: true, isMoreData: false }) } else { this.setData({ bottomLoading: false, isMoreData: true }) return false; } this.getCurrentClassList(true); }, // 监听滚动距离 onPageScroll(e) { if (e && e.scrollTop >= 1000) { this.setData({ isBackTop: true }) } else { this.setData({ isBackTop: false }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })