// packageCourse/components/teaching/detail/index.js.js const app = getApp() import moment from 'moment' Page({ /** * 页面的初始数据 */ data: { teachInteractionId: null, dialogLLoading: false, dialogList: [], visible: false, bookId: null, questionId: null, dataList: [], searchKey: '' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options) { this.setData({ teachInteractionId: options.teachInteractionId, questionName: options.questionName, bookId: options.bookId, questionId: options.questionId }) } wx.setNavigationBarTitle({ title: '互动学生列表', }) this.getMessage() }, openLook(e) { const { item } = e.currentTarget.dataset this.setData({ visible: true }) this.getQuestions(item) }, close() { this.setData({ visible: false }) }, // 搜索 changeHandle(e) { const { value } = e.detail; let cmsList = this.data.dataList this.setData({ dataList: [] }) if (value) { const data = cmsList.filter(item => item.userName.indexOf(value) > -1); this.setData({ dataList: data }) } if (value == '') { this.setData({ dataList: [], loading: true }) this.getMessage() } }, // 获取当前话题 getMessage() { const data = { start: 0, size: 999, appRefCode: app.config.appRefCode, topicIdOrRefCode: String(this.data.teachInteractionId), sort: { type: 'Desc', field: 'CreateDate' }, searchList: [{ keywords: this.data.questionName, field: 'Name', compareType: 'Contains' }] } app.MG.ugc.getTopicMessageList(data).then((res) => { const list = res.datas.map((item, i) => { item.question = [] item.bookId = null item.path = '' item.index = i + 1 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, questionTime: moment(item.updateDate).format('YYYY-MM-DD HH:mm:ss') } }) this.setData({ dataList: list, loading: false }) }) }, // 获取题目列表 getQuestions(item) { app.MG.store .getProductDetail({ path: '*', queryType: '*', productId: this.data.bookId, cmsPath: item.path, itemFields: { Embedded_QuestionBank_AnalysisCon: [], Embedded_QuestionBank_Answer: [], Embedded_QuestionBank_Difficulty: [], Embedded_QuestionBank_KnowledgePoint: [], Embedded_QuestionBank_Option: [], Embedded_QuestionBank_OptionStyle: [], Embedded_QuestionBank_QuestionType: [], Embedded_QuestionBank_Score: [], Embedded_QuestionBank_Stem: [], Embedded_QuestionBank_StemStyle: [] } }) .then((res) => { try { let list = [] list = res.datas.cmsDatas[0]?.datas.map((item) => { try { if (item.Embedded_QuestionBank_Stem) { item.questionStem = JSON.parse(item.Embedded_QuestionBank_Stem) } if ( item.Embedded_QuestionBank_Option && item.Embedded_QuestionBank_Option.indexOf('[') > -1 ) { item.questionOption = JSON.parse(item.Embedded_QuestionBank_Option) } if ( item.Embedded_QuestionBank_Answer && item.Embedded_QuestionBank_Answer.indexOf('[') > -1 ) { item.Embedded_QuestionBank_Answer = JSON.parse(item.Embedded_QuestionBank_Answer) } return { ...item, questionType: item.Embedded_QuestionBank_QuestionType, questionAnalysisCon: item.Embedded_QuestionBank_AnalysisCon, questionAnswer: item.Embedded_QuestionBank_Answer, customAnswer: null } } catch (error) { console.log(item) } }) const data = this.chageData([item], list) this.setData({ dialogList: data }) } catch (error) { this.setData({ dialogList: [] }) } }) }, // 处理数据结构 chageData(arr, zrr) { let newData = [] // 题库题目类型 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)) for (let j = 0; j < zrr.length; j++) { const ele = zrr[j] const qusObj = item.question.find((citem) => citem.cmsItemId == ele.id) if (qusObj?.cmsItemId) { ele.userAnswer = qusObj.answer const index = this.findIndexByValue(questionTypeList, ele.questionType) if (index > -1) { item.questionTypeList[index].data.push(ele) } } } item.questionTypeList = item.questionTypeList.filter((item) => item.data.length > 0) if (!item.userName) { item.userName = '-' } newData.push(item) } return newData.filter((item) => item.questionTypeList.length > 0) }, findIndexByValue(res, type) { for (let i = 0; i < res.length; i++) { if (res[i].value == type) { return i } } return -1 // 如果未找到,则返回 -1 }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })