// packageCourse/components/baseClass/index.js const app = getApp() import moment from "moment" import { getPublicImage } from '../../../assets/js/middleGround/tool' Component({ /** * 组件的属性列表 */ properties: { classId: { type: Number, default: 0 }, bookRefCode: { type: String, default: '' } }, /** * 组件的初始数据 */ data: { noticeList: [], detailInfo: null, messageInfo: null, homeworkCount: 0, userData: null, bookData: null, defaultCmsPath: '' }, ready() { const data = wx.getStorageSync('website-front-userInfo') if (data) { this.setData({ userData: JSON.parse(data), defaultCmsPath: this.properties.bookRefCode }) } this.getData() }, /** * 组件的方法列表 */ methods: { // 获取班级 getData() { app.MG.edu .getCourseClass({ ClassIdOrRefCode: String(this.properties.classId) }) .then((res) => { if (res) { res.bookName = res.linkProductDto.product.name res.bookId = res.linkProductDto.product.id res.bookIcon = getPublicImage(res.linkProductDto.product.icon, 100) res.classTime = moment(res.beginDate).format('YYYY.MM.DD') + '--' + moment(res.endDate).format('YYYY.MM.DD') } this.setData({ detailInfo: res }) this.getTopicInfo() this.getBookDetail(res.bookId) }) }, // 获取教材详情 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 }) } }) }, // 获取topic getTopicInfo() { const pramas = { classId: this.properties.classId, refCodes: [app.config.refCodes.message] } app.MG.edu.getClassTopic(pramas).then((res) => { const data = res.find((item) => item.refCode == app.config.refCodes.message) this.setData({ messageInfo: data }) if (data.id) { wx.setStorageSync('messageId', data.id) this.getNotice() } }) }, // 获取班级通知 getNotice() { const data = { start: 0, size: 3, appRefCode: app.config.appRefCode, topicIdOrRefCode: String(this.data.messageInfo.id), sort: { type: 'Desc', field: 'CreateDate', subSorts: [] } } app.MG.ugc.getTopicMessageList(data).then((res) => { const list = res.datas.map((item) => { return { ...item, createDate: moment(item.createDate).format('YYYY-MM-DD') } }) this.setData({ noticeList: list }) }) }, //复制 copyCode() { wx.setClipboardData({ data: this.data.detailInfo.refCode, success(res) { wx.hideToast() wx.showToast({ title: '邀请码已复制', duration: 1000, icon: 'none', }) } }) } } })