// packageCourse/components/teaching/index.js const app = getApp() import moment from 'moment' Component({ /** * 组件的属性列表 */ properties: { classId: { type: Number, default: 0 }, bookId: { type: Number, default: 0 }, rootCmsItemId: { type: Number, default: 0 }, }, /** * 组件的初始数据 */ data: { searchKey: '', cmsDataList: [], teachInteractionInfo: null, dataList: [], loading: true }, ready() { this.getData() }, /** * 组件的方法列表 */ methods: { // 搜索 changeHandle(e) { const { value } = e.detail; let cmsList = this.data.cmsDataList this.setData({ cmsDataList: [] }) if (value) { const data = cmsList.filter(item => item.name.indexOf(value) > -1); this.setData({ cmsDataList: data }) } if (value == '') { this.setData({ cmsDataList: [], loading: true }) this.getCmsList() } }, // 获取班级 getData() { app.MG.edu .getCourseClass({ ClassIdOrRefCode: String(this.properties.classId) }) .then((res) => { if (res) { this.setData({ currentClass: res }) } this.getTopicInfo() }) }, // 获取教学互动 getCmsList() { app.MG.store .getProductDetail({ path: '*', queryType: '*', productId: this.properties.bookId, cmsPath: this.properties.rootCmsItemId }) .then((res) => { try { const data = res.datas.cmsDatas[0]?.datas.find((item) => item.refCode == 'questionBank') app.MG.store .getProductDetail({ path: '*', queryType: '*', productId: this.properties.bookId, cmsPath: data.productLinkPath }) .then((res) => { const dataTeach = res.datas.cmsDatas[0]?.datas.find( (item) => item.refCode == 'jsek_interaction' ) app.MG.store .getProductDetail({ path: '*', queryType: '*', productId: this.properties.bookId, cmsPath: dataTeach.productLinkPath }) .then((res) => { let datas = res.datas.cmsDatas[0] ? res.datas.cmsDatas[0].datas : [] const dataRes = [] if (datas?.length > 0) { datas.forEach(async (item) => { const cmsRes = await app.MG.store .getProductDetail({ path: '*', queryType: '*', productId: this.properties.bookId, cmsPath: item.productLinkPath }) if ( cmsRes.datas.cmsDatas[0].datas && cmsRes.datas.cmsDatas[0].datas.length > 0 ) { cmsRes.datas.cmsDatas[0].datas.forEach((item, i) => { item.subList = [] item.updateDate = '-' if (this.data.dataList.length > 0) { this.data.dataList.forEach((mitem) => { if (mitem.name == item.name) { item.updateDate = moment(mitem.updateDate).format( 'YYYY-MM-DD HH:mm:ss' ) item.subList.push(mitem) } }) } dataRes.push(item) }) } const resList = dataRes.sort((a, b) => b.subList.length - a.subList.length) this.setData({ cmsDataList: resList, loading: false }) }) } }) }) } catch (error) { this.setData({ cmsDataList: [], loading: false }) } }) }, // 获取Messsagetopic getTopicInfo() { const pramas = { classId: this.properties.classId, refCodes: [app.config.refCodes.teachInteraction] } app.MG.edu.getClassTopic(pramas).then((res) => { const list = res const data = list.find( (item) => item.refCode == app.config.refCodes.teachInteraction ) if (data.id) { this.setData({ teachInteractionInfo: data }) this.getMessage() } }) }, // 获取当前MessageList getMessage() { const data = { start: 0, size: 999, appRefCode: app.config.appRefCode, topicIdOrRefCode: String(this.data.teachInteractionInfo.id), sort: { type: 'Desc', field: 'CreateDate' }, } app.MG.ugc.getTopicMessageList(data).then((res) => { const data = res.datas.map((item) => { item.question = [] item.bookId = null item.path = '' try { const obj = JSON.parse(item.content) if (obj.bookId) { item.question = obj.content item.bookId = obj.bookId item.path = obj.path item.userName = obj.userName } } catch (error) { console.log(item) } return { ...item } }) this.setData({ dataList: data }) this.getCmsList() }) }, // 处理数据结构 chageData(arr, zrr) { // 题库题目类型 const questionTypeList = [{ name: '单选题', value: 'singleChoice', data: [] }, { name: '多选题', value: 'multipleChoice', data: [] }, { name: '判断题', value: 'judge', data: [] }, { name: '简答题', value: 'shortAnswer', data: [] }, { name: '论述题', value: 'discuss', data: [] }, { name: '填空题', value: 'completion', data: [] }, { name: '连线题', value: 'matching', data: [] }, { name: '分类题', value: 'classification', data: [] } ] for (let i = 0; i < arr.length; i++) { const item = arr[i] item.questionTypeList = JSON.parse(JSON.stringify(questionTypeList)); item.other = [] for (let j = 0; j < item.question.length; j++) { const ele = item.question[j] const data = zrr.find((sitem) => sitem.id == ele.cmsItemId) const index = findIndexById(zrr, ele.cmsItemId) if (index > -1) { item.other[index] = { ...data, userAnswer: ele.answer } } } if (item.other.length > 0) { item.other.forEach((aitem) => { const index = findIndexByValue(item.questionTypeList, aitem.questionType) if (index > -1) { item.questionTypeList[index].data.push(aitem) } }) } item.questionTypeList = item.questionTypeList.filter((xitem) => xitem.data.length > 0) } return arr }, findIndexByValue(res, type) { for (let i = 0; i < res.length; i++) { if (res[i].value == type) { return i } } return -1 // 如果未找到,则返回 -1 }, findIndexById(res, id) { for (let i = 0; i < res.length; i++) { if (res[i].id == id) { return i } } return -1 // 如果未找到,则返回 -1 }, toDetail(e) { const { item } = e.currentTarget.dataset wx.navigateTo({ url: '/packageCourse/pages/teachClass/detail/index?questionName=' + item.name + '&teachInteractionId=' + this.data.teachInteractionInfo.id + '&bookId=' + this.properties.bookId + '&questionId=' + item.id, }) } } })