123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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 = options.title;
- let type = options.type;
- this.data.type = type;
- if (type == communityDetailTypes.COMMUNITY) {
- await this.handleCommunity(options.id, options.trainType)
- } else if (type == communityDetailTypes.CLASS) {
- let isPre = options.isPre;
- let newData = JSON.parse(options.detail)
- let item = JSON.parse(options.item)
- this.setData({
- id: newData.id, title, type,
- newData, isPre, item
- })
- }
- wx.setNavigationBarTitle({title: options.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);
- }
- 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) {
- const id = getEventParam(e, "id");
- if (id) {
- let videoId = id.replace('myVideo', '');
- for (let i = 0; i < this.data.rows.length; i++) {
- if (videoId != i) {
- this.selectComponent(`#list${i}`).pauseVideo(i)
- }
- }
- wx.createVideoContext("myVideo").pause()
- } else {
- for (let i = 0; i < this.data.rows.length; i++) {
- this.selectComponent(`#list${i}`).pauseVideo(i)
- }
- }
- },
- 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
- })
- },
- })
|