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

423 lines
9.9 KiB

// pages/topics/activity/activityDetail/index.js
import dayjs from '../../../../utils/dayjs/index.js'
import relativeTime from '../../../../utils/dayjs/relativeTime.js'
dayjs.extend(relativeTime);
import {
store
} from '../../../../utils/store.js'
var WxParse = require('../../../../components/wxParse/wxParse.js');
import {
TopicModel
} from '../../../../models/topic.js'
let topicModel = new TopicModel()
Page({
/**
* 页面的初始数据
*/
data: {
isStar: true, // 是否
showBtn: false,
image: '',
activityId: '',
title: '',
date: '',
origin: '',
unStar: '/images/common/star.png',
star: '/images/common/star_light.png',
collectNum: 0,
isStar: false,
collectionId: String,
isCollect: Number,
currPage: 1,
commentList: [],
unPraise: '/images/topic/un_zan.png',
praise: '/images/topic/zan.png',
hiddenmodalput: true,
currentComment: '',
flag:5,
startX: 0, //开始坐标
startY: 0,
total: 0,
confirmTag: true
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
activityId: options.activityId
})
this.fetchDetail()
this.fetchDetailMessage()
},
//活动详情
fetchDetail() {
let activityId = this.data.activityId
// console.log('来活动详情' + activityId)
topicModel.getActivityDetail(activityId, res => {
console.log('来活动详情', res)
let data = res.result
const date = dayjs(data.createTime).format('MM月DD日')
if(data.flag == 0 || data.flag == 1){
var disable = false;
}else{
var disable = true;
}
this.setData({
nodes: data.content,
title: data.title,
date: date,
image: data.titlePic,
origin: data.source,
isStar: data.isCollect==1 ? true : false,// 0-未收藏 1-收藏
// showBtn: data.typeFlag >= 2 ? true : false,
collectNum: data.collectNum,
disable: disable,
flag:data.flag
}, () => {
// wx.hideLoading()
})
if (data.content) {
WxParse.wxParse('activity', 'html', this.data.nodes, this, 5);
}
})
},
//活动留言列表
fetchDetailMessage(flag = false) {
if (flag) {
this.setData({
currPage: 1
})
}
let activityId = this.data.activityId
let page = this.data.currPage
topicModel.getTopicDetailComment(activityId, page, res => {
console.log('留言列表---', res)
const datas = res.result.list
this.setData({
total: res.result.total
})
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
id: item.id,
commentAvator: item.commentAvator,
userName: item.username,
isGoldenIdea: item.isGoldenIdea,
detail: item.comment,
time: item.createTime,
praiseNum: item.supportNum,
isSupport: item.isSupport,
isTouchMove: false,
})
})
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'
})
}
}
wx.stopPullDownRefresh()
})
},
//活动收藏
onClickCollect() {
// 收藏功能
if (store.hasBindUserInfo()) {
this.addOrRemoveCollectionApi()
} else {
wx.redirectTo({
url: '/pages/weChatAuth/index',
})
}
},
addOrRemoveCollectionApi() {
topicModel.addOrRemoveCollect(this.data.activityId, res => {
//console.log(res)
if (res.code == 200) {
this.setData({
isStar: !this.data.isStar
})
wx.showToast({
title: this.data.isStar ? '收藏成功' : '取消收藏成功',
icon: 'none'
})
}
})
},
//留言点赞
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)
}
})
},
//留言点赞
fetchTopicCommentPraise(commentId){
wx.showLoading()
topicModel.topicCommentPraise(commentId,res =>{
if (res.code === 200) {
wx.hideLoading();
var list = this.data.commentList;
for(var index in list){
if(list[index]['id'] == res.result.id){
list[index]['praiseNum'] = res.result.supportNum;
list[index]['isSupport'] = res.result.isSupport;
break;
}
}
this.setData({
commentList:list
})
}
})
},
// 点击留言
onTapComment() {
this.setData({
hiddenmodalput: !this.data.hiddenmodalput
})
},
// 弹出框 取消
cancel: function () {
this.setData({
hiddenmodalput: true,
currentComment: ''
});
},
// 弹出框 确认
confirm: function () {
if (this.data.confirmTag) {
if (!this.data.currentComment) {
wx.showToast({
title: '请输入留言',
icon: 'none'
})
this.setData({
confirmTag: true,
currentComment: ''
})
return
}
this.setData({
confirmTag: false,
hiddenmodalput: true,
})
topicModel.topicAddComment(this.data.currentComment, this.data.activityId, res => {
if (res.code === 200) {
this.setData({
hiddenmodalput: true,
confirmTag: true,
currentComment: ''
})
this.fetchDetailMessage(true)
}
})
}
},
// 评论输入框
bingTextAreaInput(e) {
//console.log(e.detail.value)
this.setData({
currentComment: e.detail.value
})
},
touchstart: function (e) {
let {
nickName
} = store.readUserInfo()
if (e.currentTarget.dataset.name === nickName) {
//开始触摸时 重置所有删除
this.data.commentList.forEach(item => {
if (item.isTouchMove) {
item.isTouchMove = false
}
})
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
commentList: this.data.commentList
})
}
},
touchmove: function (e) {
let {
nickName
} = store.readUserInfo()
if (e.currentTarget.dataset.name === nickName) {
var that = this
const currentIndex = e.currentTarget.dataset.index //当前索引
const startX = that.data.startX //开始X坐标
const startY = that.data.startY //开始Y坐标
const touchMoveX = e.changedTouches[0].clientX //滑动变化坐标
const touchMoveY = e.changedTouches[0].clientY //滑动变化坐标
//获取滑动角度
const angle = that.angle({
X: startX,
Y: startY
}, {
X: touchMoveX,
Y: touchMoveY
})
if (Math.abs(angle) > 30) return;
this.data.commentList.forEach((item, index) => {
item.isTouchMove = false
if (currentIndex == index) {
if (touchMoveX > startX) //右滑
item.isTouchMove = false
else //左滑
item.isTouchMove = true
}
})
that.setData({
commentList: that.data.commentList
})
}
},
angle: function (start, end) {
var _X = end.X - start.X,
_Y = end.Y - start.Y
//返回角度 /Math.atan()返回数字的反正切值
return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
},
del: function (e) {
let that = this
let id = e.currentTarget.dataset.id
topicModel.deleteComment(id, res => {
if (res.code === 200) {
wx.showToast({
title: '删除成功',
icon: 'none',
success() {
that.setData({
currPage: 1,
})
that.fetchDetailMessage()
}
})
}
})
},
//活动报名
onlineSubmit () {
// console.log('在线报名')
// this.setData({
// disable: true
// })
if (store.hasBindUserInfo()) {
console.log(store.hasBindUserInfo())
// this.onlineSignApi() // 在线报名
wx.navigateTo({
url: `/pages/topics/activity/activitySign/index?activityId=${this.data.activityId}`,
})
} else {
wx.redirectTo({
url: '/pages/weChatAuth/index',
})
}
},
cancelSignApi () {
this.setData({
disable: true
})
if (store.hasBindUserInfo()) {
topicModel.cancelOnlineSign(this.data.activityId, res => {
if(res.code == 200){
wx.showToast({
title: res.message,
icon: 'none'
})
}else{
this.setData({
disable: false
})
wx.showToast({
title: res.message,
icon: 'none'
})
}
this.fetchDetail()
})
} else {
wx.redirectTo({
url: '/pages/weChatAuth/index',
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})