市北人才赋能平台 --小程序端
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.
 

241 lines
5.7 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:[],
unStar: '/images/common/star.png',
star: '/images/common/star_light.png',
isStar:false,
topicId:String,
collectionId:String,
isCollect:Number,
currPage: 1,
commentList: [],
praise: '/images/common/zan.png',
hiddenmodalput:true,
currentComment:'',
},
/**
* 生命周期函数--监听页面加载
*/
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 => {
let data = res.result
this.setData({
topicId: data.id,
collectionId: data.collectionId,
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)
})
})
},
fetchDetailComment(){
let topicId = this.data.topicId
let page = this.data.currPage
topicModel.getTopicDetailComment(topicId,page,res => {
console.log('议题评论')
const datas = res.result.list
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
id:item.id,
commentAvator: 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('收藏')
if(res.code === 200){
this.fetchDetail()
wx.showToast({
title: '收藏成功',
icon: 'none'
})
}
})
},
fetchTopicUnCollect(){
let collectionId = this.data.collectionId
topicModel.topicUnCollect(collectionId, res => {
console.log('取消收藏')
if (res.code === 200) {
this.fetchDetail()
wx.showToast({
title: '取消收藏',
icon: 'none'
})
}
})
},
fetchTopicCommentPraise(commentId){
topicModel.topicCommentPraise(commentId,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){
this.fetchTopicCommentPraise(selectItem.id)
}
// tempList.push(item)
})
// this.setData({
// commentList:tempList,
// })
// this.fetchTopicCommentPraise(selectItem.id)
// 评论点赞
},
// 点击查看图片
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) { },
})
},
// 点击评论
onTapComment(){
this.setData({
hiddenmodalput: !this.data.hiddenmodalput
})
},
// 弹出框 取消
cancel: function () {
this.setData({
hiddenmodalput: true,
currentComment: ''
});
},
// 弹出框 确认
confirm: function () {
if (!this.data.currentComment){
wx.showToast({
title: '请输入评论',
icon: 'none'
})
return
}
topicModel.topicAddComment(this.data.currentComment, this.data.topicId,res=>{
if(res.code === 200){
this.setData({
hiddenmodalput: true,
currentComment: ''
})
this.fetchDetailComment()
}
})
},
// 评论输入框
bingTextAreaInput(e){
console.log(e.detail.value)
this.setData({
currentComment: e.detail.value
})
}
})