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

6 years ago
// 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()
6 years ago
Page({
/**
* 页面的初始数据
*/
data: {
6 years ago
title:String,
time: String,
groupAvator: String,
author:String,
company:String,
position:String,
detail: String,
imgArr:[],
comments:[],
6 years ago
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'
6 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options.topicId)
this.setData({
topicId: options.topicId
})
this.fetchDetail()
this.fetchDetailComment()
6 years ago
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
const page = this.data.currPage + 1
this.setData({
currPage: page
})
this.fetchDetailComment()
6 years ago
},
fetchDetail(){
let topicId = this.data.topicId
console.log('议题详情' + topicId)
topicModel.getTopicDetail(topicId,res => {
console.log(res)
let data = res.result
this.setData({
6 years ago
topicId: data.id,
isCollect: data.isCollect,
title:data.title,
time: data.createTime,
6 years ago
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(){
6 years ago
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()
}
})
6 years ago
},
onClickCollect() {
this.setData({
isCollect: !this.data.isCollect
6 years ago
})
this.data.isCollect === true ? this.fetchTopicCollect() : this.fetchTopicUnCollect()
6 years ago
// 收藏功能
},
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)
// 评论点赞
6 years ago
},
onTapComment(){
},
6 years ago
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) { },
})
}
})