// packageCourse/pages/course/detail/index.js const app = getApp() import moment from 'moment' Page({ data: { detail: null, bookData: null, courseId: null, classCount: 0, tabVal: 'base', visible: false, visibleStart: false, visibleEnd: false, startTime: '', endTime: '', className: '', count: null, classList: [], searchKey: '', defaultCmsPath: '', pageClass: { page: 1, limit: 10, total: 0 }, courseLoading: true, classLoading: false, // 加载参数 bottomLoading: false, isMoreData: false, // 返回顶部 isBackTop: false, setScrollValue: 0, skeletonLoding: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options.courseId) { this.setData({ courseId: options.courseId, defaultCmsPath: options.bookRefCode != '' ? 'jsek_digitalTextbooks' : 'defaultGoodsStore3' }) } wx.setNavigationBarTitle({ title: '基本信息', }) this.getData() }, // 获取课程信息 getData() { app.MG.edu .getCourseById({ courseId: this.data.courseId }) .then((res) => { setTimeout(() => { this.setData({ detail: res, courseLoading: false }) const shopId = res.linkProduct?.id this.getBookDetail(shopId) this.getClassTotal() }, 1000); }) }, // 获取班级数量 getClassTotal() { app.MG.edu .getCourseClassList({ courseId: this.data.courseId, }) .then((res) => { this.setData({ classCount: res.totalSize }) }) }, // 获取教材详情 getBookDetail(shopId) { let query = { path: this.data.defaultCmsPath, queryType: '*', productId: String(shopId), storeInfo: this.data.defaultCmsPath, coverSize: { height: 300, width: 210 }, fields: { seriesName: [], author: [], isbn: [], publicationDate: [] } } app.MG.store.getProductDetail(query).then(async (res) => { if (res?.datas) { if (!res.datas.author) { res.datas.author = '-' } this.setData({ bookData: res.datas }) } }) }, // tab切换 tabActive(e) { const { str } = e.currentTarget.dataset this.setData({ tabVal: str, courseLoading: true, classLoading: true }) if (str == 'base') { wx.setNavigationBarTitle({ title: '基本信息', }) this.getData() } if (str == 'class') { wx.setNavigationBarTitle({ title: '班级管理', }) this.getClassList() } }, // 打开新建班级 newClass() { this.setData({ visible: true, }) }, onCourseNameInput(e) { this.setData({ className: e.detail.value }) }, onCourseDescInput(e) { this.setData({ count: e.detail.value }) }, // 打开选择日期 openDateStart() { this.setData({ visibleStart: true }) }, openDateEnd() { this.setData({ visibleEnd: true }) }, // 选择日期 handleConfirmStart(e) { const { value } = e.detail; const dateStr = moment(value).format('YYYY-MM-DD') this.setData({ startTime: dateStr, }); }, handleConfirmEnd(e) { const { value } = e.detail; const dateStr = moment(value).format('YYYY-MM-DD') this.setData({ endTime: dateStr, }); }, // 关闭申请 cancle() { this.setData({ visible: false }) }, // 申请提交班级 submitClass() { if (!this.data.className) { wx.showToast({ title: '请填写课程名称', duration: 1000, icon: 'none', }) return false } if (!this.data.count) { wx.showToast({ title: '请选择关联教材', duration: 1000, icon: 'none', }) return false } if (!this.data.startTime || !this.data.endTime) { wx.showToast({ title: '请选择班级有效期', duration: 1000, icon: 'none', }) return false } app.MG.edu .newCourseClass({ courseId: this.data.courseId, name: this.data.className, description: '', icon: '', type: 'class', beginDate: this.data.startTime, endDate: this.data.endTime, config: '', price: 0, maxUserCount: this.data.count }) .then((res) => { if (res) { wx.showToast({ title: '已申请开班', duration: 1000, icon: 'success', }) this.setData({ visible: false }) this.getClassList() } }) .catch((err) => { wx.showToast({ title: '申请开班出错', duration: 1000, icon: 'err', }) this.setData({ visible: false }) }) }, // 搜索班级 changeHandle(e) { const { value } = e.detail; this.setData({ searchKey: value, 'pageClass.page': 1 }); this.getClassList() }, // 获取班级列表 getClassList(isReachBottom) { app.MG.edu .getCourseClassList({ courseId: this.data.courseId, start: (this.data.pageClass.page - 1) * this.data.pageClass.limit, size: this.data.pageClass.limit, sort: { type: 'Desc', field: 'CreateDate' }, filterList: [], searchList: this.data.searchKey ? [{ keywords: this.data.searchKey, field: 'Name', compareType: 'Contains' }] : [] }) .then((res) => { let list = res.datas.map((item) => { return { ...item, name: item.name, id: item.id, icon: item.icon ? getPublicImage(item.icon, 80) : '', introduction: item.description, reason: item.applyReturnMsg ? JSON.parse(item.applyReturnMsg).reason : '', beginDate: moment(item.beginDate).format('YYYY-MM-DD') ?? '-', endDate: moment(item.endDate).format('YYYY-MM-DD') ?? '-' } }) //触底加载新数据并保留老数据 if (isReachBottom) { list = [...this.data.classList, ...list] //将新数据加入老数据中 } this.setData({ classList: list, 'pageClass.total': res.totalSize, skeletonLoding: false, classLoading: false, bottomLoading: false }) }) }, // 删除课程 delClass(e) { const { delId } = e.currentTarget.dataset const data = { ids: [delId] } app.MG.edu .delCourseClass(data) .then((res) => { if (res) { wx.showToast({ title: '已删除', duration: 1000, icon: 'success', }) this.getClassList() } }) .catch((err) => { wx.showToast({ title: '删除失败', duration: 1000, icon: 'error', }) console.log(err) }) }, // 班级详情 todetail(e) { const { classId, item } = e.currentTarget.dataset if (item.applyState == 'WaitAudit' || item.applyState == 'Reject') { wx.showToast({ title: item.applyState == 'WaitAudit' ? '审核中' : '未通过', duration: 1000, icon: 'none', }) return false } wx.navigateTo({ url: '/packageCourse/pages/teachClass/index?classId=' + classId + '&courseId=' + this.data.courseId + '&author=' + this.data.bookData.author + '&isbn=' + this.data.bookData.isbn + '&bookId=' + this.data.bookData.id + '&rootCmsItemId=' + this.data.bookData.rootCmsItemId + "&bookRefCode=" + this.data.defaultCmsPath, }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (this._freshing) return this.setData({ 'pageClass.page': 1, bottomLoading: false, isMoreData: false }) setTimeout(() => { this._freshing = true; this.setData({ triggered: false, }) this.getClassList(); this._freshing = false }, 500); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { if (this.data.pageClass.total > this.data.classList.length) { this.setData({ 'pageClass.page': this.data.pageClass.page + 1, bottomLoading: true, isMoreData: false }) } else { this.setData({ bottomLoading: false, isMoreData: true }) return false; } this.getClassList(true); }, // 监听滚动距离 onPageScroll(e) { if (e && e.scrollTop >= 1000) { this.setData({ isBackTop: true }) } else { this.setData({ isBackTop: false }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })