You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
5.0 KiB
205 lines
5.0 KiB
// pages/topics/interactive/article/index.js
|
|
import dayjs from '../../../../utils/dayjs/index.js'
|
|
import relativeTime from '../../../../utils/dayjs/relativeTime.js'
|
|
dayjs.extend(relativeTime);
|
|
import { TopicModel } from '../../../../models/topic.js'
|
|
let topicModel = new TopicModel()
|
|
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
title:String,
|
|
time: String,
|
|
groupAvator: String,
|
|
author:String,
|
|
company:String,
|
|
position:String,
|
|
detail: String,
|
|
imgArr:[],
|
|
comments:[],
|
|
unStar: '/images/common/star.png',
|
|
star: '/images/common/star_light.png',
|
|
isStar:false,
|
|
topicId:String,
|
|
isCollect:Number,
|
|
currPage: 1,
|
|
commentList: [],
|
|
unPraise: '/images/common/zan.png',
|
|
praise: '/images/common/star_light.png'
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
console.log(options.topicId)
|
|
this.setData({
|
|
topicId: options.topicId
|
|
})
|
|
this.fetchDetail()
|
|
this.fetchDetailComment()
|
|
},
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
const page = this.data.currPage + 1
|
|
this.setData({
|
|
currPage: page
|
|
})
|
|
this.fetchDetailComment()
|
|
},
|
|
fetchDetail(){
|
|
let topicId = this.data.topicId
|
|
console.log('议题详情' + topicId)
|
|
topicModel.getTopicDetail(topicId,res => {
|
|
console.log(res)
|
|
let data = res.result
|
|
this.setData({
|
|
topicId: data.id,
|
|
isCollect: data.isCollect,
|
|
title:data.title,
|
|
time: data.createTime,
|
|
groupAvator: data.groupAvator,
|
|
author: data.author,
|
|
company: data.company,
|
|
position: data.position,
|
|
detail:data.content,
|
|
imgArr: data.images.split(";").slice(0, -1)
|
|
})
|
|
console.log(this.data.imgArr)
|
|
})
|
|
},
|
|
fetchDetailComment(){
|
|
let topicId = this.data.topicId
|
|
let page = this.data.currPage
|
|
topicModel.getTopicDetailComment(topicId,page,res => {
|
|
console.log('议题评论')
|
|
console.log(res)
|
|
|
|
const datas = res.result.list
|
|
let tempDatas = []
|
|
datas.forEach(item => {
|
|
tempDatas.push({
|
|
isPraise: false,
|
|
id:item.id,
|
|
userIcon: item.commentAvator,
|
|
userName: item.username,
|
|
detail: item.comment,
|
|
time: item.createTime,
|
|
praiseNum: item.supportNum
|
|
})
|
|
})
|
|
if (page == 1) {
|
|
this.setData({
|
|
commentList: tempDatas
|
|
})
|
|
} else {
|
|
if (tempDatas.length > 0) {
|
|
const list = [...this.data.commentList, ...tempDatas]
|
|
this.setData({
|
|
commentList: list
|
|
})
|
|
} else {
|
|
const page = this.data.currPage - 1
|
|
this.setData({
|
|
currPage: page
|
|
})
|
|
wx.showToast({
|
|
title: '已加载全部',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}
|
|
console.log(this.data.commentList)
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
fetchTopicCollect(){
|
|
let topicId = this.data.topicId
|
|
topicModel.topicCollect(topicId,res =>{
|
|
console.log('收藏')
|
|
console.log(res)
|
|
if(res.code === 200){
|
|
this.fetchDetail()
|
|
wx.showToast({
|
|
title: '收藏成功',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
fetchTopicUnCollect(){
|
|
let topicId = this.data.topicId
|
|
topicModel.topicUnCollect(topicId, res => {
|
|
console.log('取消收藏')
|
|
console.log(res)
|
|
if (res.code === 200) {
|
|
this.fetchDetail()
|
|
wx.showToast({
|
|
title: '取消收藏',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
fetchTopicCommentPraise(commentId){
|
|
topicModel.topicCommentPraise(commentId,res =>{
|
|
console.log(res)
|
|
if (res.code === 200) {
|
|
wx.showToast({
|
|
title: res.message,
|
|
icon: 'none'
|
|
})
|
|
this.fetchDetailComment()
|
|
}
|
|
})
|
|
},
|
|
onClickCollect() {
|
|
this.setData({
|
|
isCollect: !this.data.isCollect
|
|
})
|
|
this.data.isCollect === true ? this.fetchTopicCollect() : this.fetchTopicUnCollect()
|
|
// 收藏功能
|
|
},
|
|
|
|
onClickPraise(e){
|
|
console.log(e)
|
|
const sIndex = e.currentTarget.dataset.index
|
|
var selectItem = e.currentTarget.dataset.item
|
|
const commentList = this.data.commentList
|
|
const tempList = []
|
|
commentList.forEach( (item,index)=>{
|
|
if (sIndex === index){
|
|
item.isPraise = !item.isPraise
|
|
}
|
|
tempList.push(item)
|
|
})
|
|
this.setData({
|
|
commentList:tempList,
|
|
})
|
|
this.fetchTopicCommentPraise(selectItem.id)
|
|
// 评论点赞
|
|
},
|
|
onTapComment(){
|
|
|
|
},
|
|
previewImg: function (e) {
|
|
console.log(e.currentTarget.dataset.index);
|
|
var index = e.currentTarget.dataset.index;
|
|
var imgArr = this.data.imgArr;
|
|
wx.previewImage({
|
|
current: imgArr[index], //当前图片地址
|
|
urls: imgArr, //所有要预览的图片的地址集合 数组形式
|
|
success: function (res) { },
|
|
fail: function (res) { },
|
|
complete: function (res) { },
|
|
})
|
|
}
|
|
})
|