161 lines
3.1 KiB
JavaScript
161 lines
3.1 KiB
JavaScript
// pages/article/detail.js
|
|
import request from '../../utils/request'
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
detailInfo:{},
|
|
userInfo:{},
|
|
list:[],
|
|
pageNum:1,
|
|
pageSize:10,
|
|
articleId:'',
|
|
content:'',
|
|
isLike:false,
|
|
listList:[]
|
|
},
|
|
msgWord: function (e) {
|
|
this.setData({msgWord: e.detail.value}) // 把值给keyWord
|
|
},
|
|
setLike(){
|
|
let data = {
|
|
category: this.data.detailInfo.categoryId,
|
|
refereceId: this.data.articleId,
|
|
action: this.data.isLike?2:1
|
|
}
|
|
request._post('/firefly/account-like/like/do', data,
|
|
res=>{
|
|
if(res.retCode ==0){
|
|
setTimeout(() => {
|
|
wx.showToast({
|
|
title: '积分'+res.body.points,
|
|
icon: 'none',
|
|
duration:2000
|
|
})
|
|
}, 100);
|
|
this.getData()
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
userInfo: wx.getStorageSync("userInfo"),
|
|
articleId:options.id
|
|
})
|
|
this.getData()
|
|
this.getList()
|
|
},
|
|
add(){
|
|
request._post('/firefly/article/comment/add/new',{articleId:this.data.articleId,content:this.data.content,isReply:2,replyId:0},
|
|
res=>{
|
|
if(res.retCode ==0){
|
|
setTimeout(() => {
|
|
wx.showToast({
|
|
title: '发布成功,获得'+res.body.points+'积分!',
|
|
icon: 'none',
|
|
duration:2000
|
|
})
|
|
}, 100);
|
|
this.getList()
|
|
}
|
|
}
|
|
)
|
|
},
|
|
getList(id){
|
|
request._post('/firefly/article/comment/list',{articleId:this.data.articleId,pageNum:this.data.pageNum,pageSize:this.data.pageSize},
|
|
res=>{
|
|
if(res.retCode ==0){
|
|
this.setData({
|
|
list:res.body
|
|
})
|
|
}
|
|
}
|
|
)
|
|
},
|
|
subEvent(){
|
|
const data = {
|
|
articleId: this.data.detailInfo.id,
|
|
content: this.data.msgWord,
|
|
isReply: 2,
|
|
replyId: ''
|
|
}
|
|
request._post('/firefly/article/comment/add/new', data,
|
|
res=>{
|
|
|
|
})
|
|
},
|
|
getData(id){
|
|
request._post('/firefly/article/detail',{articleId:this.data.articleId},
|
|
res=>{
|
|
if(res.retCode ==0){
|
|
let userInfo = wx.getStorageSync("userInfo")
|
|
let a = res.body.accountLike.filter(item=>item.accountId==userInfo.id)
|
|
console.log(a.length)
|
|
this.setData({
|
|
detailInfo:res.body,
|
|
listList:res.body.accountLike,
|
|
isLike:a.length>0?true:false
|
|
})
|
|
}
|
|
}
|
|
)
|
|
},
|
|
getInputContent(e){
|
|
this.setData({
|
|
content: e.detail.value
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |