import Api from "../../model/api"; import {formatTime, getEventParam, throttle, toast} from "../../utils/utils"; import {communityDetailTypes, logicStatus, uploadResTypes} from "../../model/enum"; const app = getApp(); app.Base({ data: { newData: {}, item: {}, uploadResTypesEnum: uploadResTypes, logicStatusEnum: logicStatus, trainType: '', type: '', id: '', title: '', isPre: 0, }, async onLoad(options) { let {title, type, id, trainType, isPre, detail, item} = options; this.data.type = type; if (type == communityDetailTypes.COMMUNITY) { await this.handleCommunity(id, trainType) } else if (type == communityDetailTypes.CLASS) { let newData = JSON.parse(detail) item = JSON.parse(item) this.setData({ id: newData.id, title, type, newData, isPre, item }) } wx.setNavigationBarTitle({title}) }, reply: throttle(async function (e) { const messagDes = getEventParam(e, "msg"); if (!messagDes.trim()) { toast("请输入评论") return } if (this.data.type == communityDetailTypes.COMMUNITY) { await Api.ReleaseComment({ content: messagDes, trainType: this.data.trainType, parentId: this.data.id }, true) } else if (this.data.type == communityDetailTypes.CLASS) { await Api.addInteractionComment({ parentId: this.data.id, content: messagDes, stuId: this.data.item.eduStuId, stuName: this.data.item.eduStuName, }, true); } const eventChannel = this.getOpenerEventChannel() eventChannel.emit('comment'); this.selectComponent('.bottom-reply').clear(); await this.resetData(this); // this.pageScrollToBottom(); }), async requestData() { let res; if (this.data.type == communityDetailTypes.COMMUNITY) { res = await Api.getMyComment({ trainType: this.data.trainType, parentId: this.data.id, pageNum: this.pageNum, pageSize: this.pageSize }); } else if (this.data.type == communityDetailTypes.CLASS) { res = await Api.getinteractionCommentList({ parentId: this.data.id, pageNum: this.pageNum, pageSize: this.pageSize }); } res.data.rows = res.data.rows.map(item => { if (item.cAttachmentUrlList && item.cAttachmentType == uploadResTypes.IMAGE) { item.cAttachmentUrlList = item.cAttachmentUrlList || []; item.cAttachmentUrlList = item.cAttachmentUrlList.map(item => { return { url: item, isImage: true } }); } return { coverImg: item.stuPic || item.picUrl || item.managePic, messageName: item.stuName || item.manageName, time: formatTime(item.createTime), messagDes: item.content, cAttachmentUrlList: item.cAttachmentUrlList, cAttachmentType: item.cAttachmentType } }) return res; }, play(e) { wx.createVideoContext("myVideo").pause() }, pageScrollToBottom() { wx.createSelectorQuery().select('.content').boundingClientRect(function (rect) { wx.pageScrollTo({ scrollTop: rect.bottom }) }).exec() }, async handleCommunity(id, trainType) { const res = await Api.getTrainListDetail({ id, trainType }, true); if (res.data.attachmentUrlList && res.data.attachmentType == uploadResTypes.IMAGE) { res.data.attachmentUrlList = res.data.attachmentUrlList || []; res.data.attachmentUrlList = res.data.attachmentUrlList.map(item => { return { url: item, isImage: true } }); } this.data.trainType = trainType; this.data.id = id; this.setData({ trainType: trainType, id: id, newData: res.data }) }, })