|
|
|
@ -1,271 +1,195 @@
|
|
|
|
|
const db = wx.cloud.database().collection("comment")
|
|
|
|
|
// pages/Detailed/detailed.js
|
|
|
|
|
let id=''
|
|
|
|
|
let speak=''
|
|
|
|
|
let db = wx.cloud.database();
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
//评论数据
|
|
|
|
|
comment_list: [
|
|
|
|
|
{
|
|
|
|
|
comment_id: 1, //评论id
|
|
|
|
|
comment_pr_id: 1,//评论文章所属id
|
|
|
|
|
comment_user_avatar: 'cloud://cloud1-7gyjwcyfbdf819da.636c-cloud1-7gyjwcyfbdf819da-1321167991/1678762683308.png', //评论用户头像(路径替换为你的图片路径)
|
|
|
|
|
comment_user_name: '高同学', //评论人昵称
|
|
|
|
|
comment_text: '您觉得这位老师的讲课方式是什么样的呢', //评论内容
|
|
|
|
|
comment_time: '2020年8月18日', //评论时间
|
|
|
|
|
reply_id: 0, //回复谁的评论,默认为0
|
|
|
|
|
parent_id: 0, //评论所属评论id,默认为0
|
|
|
|
|
reply_name: '' //回复评论用户的昵称 默认为''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
comment_id: 2,
|
|
|
|
|
comment_pr_id: 1,
|
|
|
|
|
comment_user_avatar: 'cloud://cloud1-7gyjwcyfbdf819da.636c-cloud1-7gyjwcyfbdf819da-1321167991/photo/70eb920703ebdb368681f011c75aef3.jpg',
|
|
|
|
|
comment_user_name: '王同学',
|
|
|
|
|
comment_text: '强烈推荐这位老师,讲课幽默生动,容易接受',
|
|
|
|
|
comment_time: '2020年8月18日',
|
|
|
|
|
reply_id: 0,
|
|
|
|
|
parent_id: 0,
|
|
|
|
|
reply_name: ''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
comment_id: 3,
|
|
|
|
|
comment_pr_id: 1,
|
|
|
|
|
comment_user_avatar: 'cloud://cloud1-7gyjwcyfbdf819da.636c-cloud1-7gyjwcyfbdf819da-1321167991/photo/4494c78cc34e0567b59bd6431df61f6.jpg',
|
|
|
|
|
comment_user_name: '张剑锋',
|
|
|
|
|
comment_text: '老师讲的比较仔细,但好像不太适合我',
|
|
|
|
|
comment_time: '2020年8月18日',
|
|
|
|
|
reply_id: 0,
|
|
|
|
|
parent_id: 0,
|
|
|
|
|
reply_name: ''
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
//回复数据
|
|
|
|
|
comment_list2: [
|
|
|
|
|
{
|
|
|
|
|
comment_id: 4,
|
|
|
|
|
comment_pr_id: 1,
|
|
|
|
|
comment_user_name: '张同学',
|
|
|
|
|
comment_user_avatar: '/images/assemblyNumber/discoveryDetails/per3.png',
|
|
|
|
|
comment_text: "为什么呢?",
|
|
|
|
|
comment_time: '2020年8月18日',
|
|
|
|
|
reply_id: 3,
|
|
|
|
|
parent_id: 3,
|
|
|
|
|
reply_name: ''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
comment_id: 5,
|
|
|
|
|
comment_pr_id: 1,
|
|
|
|
|
comment_user_name: '沈非隆',
|
|
|
|
|
comment_user_avatar: '/images/assemblyNumber/discoveryDetails/per4.png',
|
|
|
|
|
comment_text: "办理优待证大概需要多长时间呢会不会需要特别长时间",
|
|
|
|
|
comment_time: '2020年8月18日',
|
|
|
|
|
reply_id: 3,
|
|
|
|
|
parent_id: 3,
|
|
|
|
|
reply_name: '张剑锋'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
/*定义一些数据*/
|
|
|
|
|
focus: false, //输入框是否聚焦
|
|
|
|
|
placeholder: '说点什么...', //底部输入框占字符
|
|
|
|
|
placeholder2: '说点什么,让ta也认识看笔记的你', //顶部输入框占字符
|
|
|
|
|
value: null, //顶部输入框内容
|
|
|
|
|
comment_text: null, //底部评论框内容
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*以下初始化数据是用户点击任意一条评论或回复时需要设置的数据
|
|
|
|
|
*然后将设置好的数据传递给评论时新创建的评论数据对象
|
|
|
|
|
*/
|
|
|
|
|
now_reply_name: null, //当前点击的评论或回复评论的用户昵称
|
|
|
|
|
now_reply_type: 0, //当前回复类型 默认为0 1为回复评论 2为回复回复
|
|
|
|
|
now_parent_id: 0, //当前点击的评论或回复评论的所属评论id
|
|
|
|
|
now_reply: 0, //当前点击的评论或回复评论的id
|
|
|
|
|
|
|
|
|
|
//模拟用户信息
|
|
|
|
|
userinfo: {
|
|
|
|
|
nickName: '马飞', //用户昵称
|
|
|
|
|
avatarUrl: '/images/assemblyNumber/discoveryDetails/per5.png' //用户头像
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//顶部评论框提交内容时触发
|
|
|
|
|
bindconfirm(e) {
|
|
|
|
|
var comment_text = e.detail.value //判断用户是否输入内容为空
|
|
|
|
|
if (comment_text == '') { //用户评论输入内容为空时弹出
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入内容', //提示内容
|
|
|
|
|
icon: 'none' })
|
|
|
|
|
} else {
|
|
|
|
|
var date = new Date(); //创建时间对象
|
|
|
|
|
var year = date.getFullYear(); //获取年
|
|
|
|
|
var month = date.getMonth() + 1; //获取月
|
|
|
|
|
var day = date.getDate(); //获取日
|
|
|
|
|
var hour = date.getHours(); //获取时
|
|
|
|
|
var minute = date.getMinutes(); //获取分
|
|
|
|
|
var second = date.getSeconds(); //获取秒
|
|
|
|
|
var time = `${year}年${month}月${day}日${hour}时${minute}分${second}秒`; //当前时间
|
|
|
|
|
var comment_list = this.data.comment_list; //获取data中的评论列表
|
|
|
|
|
var comment_list2 = this.data.comment_list2; //获取data中的回复列表
|
|
|
|
|
var userinfo = this.data.userinfo; //获取当前的用户信息
|
|
|
|
|
var comment_user_name = userinfo.nickName //用户昵称
|
|
|
|
|
var comment_user_avatar = userinfo.avatarUrl //用户头像 //
|
|
|
|
|
var reply_id = this.data.reply_id //获取当前输入评论的id
|
|
|
|
|
var comment_list_length = comment_list.length; //获取当前评论数组的长度
|
|
|
|
|
var last_id = comment_list[comment_list_length - 1].comment_id; //获取最后一个评论的id
|
|
|
|
|
var comment_list2_length = comment_list2.length; //获取回复数组的长度
|
|
|
|
|
var last_id2 = comment_list2[comment_list2_length - 1].comment_id; //获取最后回复id
|
|
|
|
|
var new_id = last_id > last_id2 ? last_id + 1 : last_id2 + 1; //赋值当前评论的id
|
|
|
|
|
var reply_name = null;
|
|
|
|
|
var parent_id = 0;
|
|
|
|
|
var reply_id = this.data.now_reply; //获取当前输入评论的id
|
|
|
|
|
var comment_detail = {} //声明一个评论/回复对象
|
|
|
|
|
comment_detail.comment_id = new_id; //评论Id
|
|
|
|
|
comment_detail.comment_user_name = comment_user_name; //用户昵称
|
|
|
|
|
comment_detail.comment_user_avatar = comment_user_avatar; //用户头像
|
|
|
|
|
comment_detail.comment_text = comment_text; //评论内容
|
|
|
|
|
comment_detail.comment_time = time; //评论时间
|
|
|
|
|
comment_detail.reply_id = reply_id; //回复谁的评论的id
|
|
|
|
|
comment_detail.parent_id = parent_id; //评论所属哪个评论id
|
|
|
|
|
comment_detail.reply_name = reply_name; //回复评论人的昵称
|
|
|
|
|
comment_list.unshift(comment_detail);
|
|
|
|
|
this.setData({
|
|
|
|
|
value: null, //评论内容
|
|
|
|
|
now_reply: 0, //当前点击的评论id
|
|
|
|
|
now_reply_name: null, //当前点击的评论的用户昵称
|
|
|
|
|
now_reply_type: 0, //评论类型
|
|
|
|
|
now_parent_id: 0, //当前点击的评论所属哪个评论id
|
|
|
|
|
placeholder2: "说点什么,让ta也认识看笔记的你", //输入框占字符
|
|
|
|
|
comment_list //评论列表
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
good:[],
|
|
|
|
|
plcaceHolder:'',
|
|
|
|
|
speak:'',
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取id 根据id获取数据
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
console.log(options)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
id=options.id
|
|
|
|
|
this.getgood()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//点击用户评论或回复时触发
|
|
|
|
|
replyComment(e) {
|
|
|
|
|
var cid = e.currentTarget.dataset.cid; //当前点击的评论id
|
|
|
|
|
var name = e.currentTarget.dataset.name; //当前点击的评论昵称
|
|
|
|
|
var pid = e.currentTarget.dataset.pid; //当前点击的评论所属评论id
|
|
|
|
|
var type = e.currentTarget.dataset.type; //当前回复类型
|
|
|
|
|
this.setData({
|
|
|
|
|
focus: true, //输入框获取焦点
|
|
|
|
|
placeholder: '回复' + name + ':', //更改底部输入框占字符
|
|
|
|
|
now_reply: cid, //当前点击的评论或回复评论id
|
|
|
|
|
now_reply_name: name, //当前点击的评论或回复评论的用户名
|
|
|
|
|
now_parent_id: pid, //当前点击的评论或回复评论所属id
|
|
|
|
|
now_reply_type: type, //获取类型(1回复评论/2回复-回复评论)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getgood(){
|
|
|
|
|
let that=this
|
|
|
|
|
wx.cloud.database().collection('teacher_Data').doc(id).get()
|
|
|
|
|
.then(res=>{
|
|
|
|
|
that.setData({
|
|
|
|
|
good:res.data
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//底部输入框提交内容时触发
|
|
|
|
|
confirm(e){
|
|
|
|
|
//获取输入框输入的内容
|
|
|
|
|
var comment_text = e.detail.value;
|
|
|
|
|
//判断用户是否输入内容为空
|
|
|
|
|
if (comment_text == '') {
|
|
|
|
|
//用户评论输入内容为空时弹出
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入内容', //提示内容
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
var date = new Date(); //创建时间对象
|
|
|
|
|
var year = date.getFullYear(); //获取年
|
|
|
|
|
var month = date.getMonth() + 1; //获取月
|
|
|
|
|
var day = date.getDate(); //获取日
|
|
|
|
|
var hour = date.getHours(); //获取时
|
|
|
|
|
var minute = date.getMinutes(); //获取分
|
|
|
|
|
var second = date.getSeconds(); //获取秒
|
|
|
|
|
var time = `${year}年${month}月${day}日${hour}时${minute}分${second}秒`; //当前时间
|
|
|
|
|
var userinfo = this.data.userinfo; //获取当前的用户信息
|
|
|
|
|
var comment_user_name = userinfo.nickName //用户昵称
|
|
|
|
|
var comment_user_avatar = userinfo.avatarUrl //用户头像
|
|
|
|
|
var reply_name = null; //回复评论用户的昵称
|
|
|
|
|
var parent_id = 0; //评论所属哪个评论的id
|
|
|
|
|
var reply_id = this.data.now_reply; //回复谁的评论id
|
|
|
|
|
|
|
|
|
|
var comment_list = this.data.comment_list; //获评论数据
|
|
|
|
|
var comment_list2 = this.data.comment_list2; //获取回复数据
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取评价信息
|
|
|
|
|
getInputValue(event){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
speak=this.data.plcaceHolder + event.detail.value
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 发送评价信息
|
|
|
|
|
publishComment(){
|
|
|
|
|
let that=this
|
|
|
|
|
if(!that.data.good.speaklist){
|
|
|
|
|
let speaklist=[{
|
|
|
|
|
|
|
|
|
|
nickname:wx.getStorageSync('user').nickname,
|
|
|
|
|
|
|
|
|
|
speak:speak,
|
|
|
|
|
|
|
|
|
|
var comment_list_length = comment_list.length; //获取当前评论数组的长度
|
|
|
|
|
var last_id = comment_list[comment_list_length - 1].comment_id; //获取最后一个评论的id
|
|
|
|
|
var comment_list2_length = comment_list2.length; //获取回复数组的长度
|
|
|
|
|
var last_id2 = comment_list2[comment_list2_length - 1].comment_id; //获取最后回复的id
|
|
|
|
|
var new_id = last_id > last_id2 ? last_id + 1 : last_id2 + 1; //当前将要发表的评论的id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//通过回复谁的评论id判断现在是评论还是回复
|
|
|
|
|
if(reply_id != 0) {
|
|
|
|
|
//现在是回复
|
|
|
|
|
var reply_type = this.data.now_reply_type; //回复类型
|
|
|
|
|
//通过回复类型判断是回复评论还是回复回复
|
|
|
|
|
if (reply_type == 1) {
|
|
|
|
|
//回复评论
|
|
|
|
|
parent_id = this.data.now_reply; //回复评论所属评论id
|
|
|
|
|
reply_name = this.data.now_reply_name; //回复评论用户昵称
|
|
|
|
|
} else {
|
|
|
|
|
parent_id = this.data.now_parent_id; //回复评论所属评论id
|
|
|
|
|
reply_name = this.data.now_reply_name; //回复评论用户昵称
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//现在是评论
|
|
|
|
|
}]
|
|
|
|
|
db.collection('teacher_Data').doc(id).update({
|
|
|
|
|
data:{
|
|
|
|
|
speaklist:speaklist
|
|
|
|
|
}
|
|
|
|
|
var comment_detail = {} //评论/回复对象
|
|
|
|
|
comment_detail.comment_id = new_id; //评论Id
|
|
|
|
|
comment_detail.comment_user_name = comment_user_name; //用户昵称
|
|
|
|
|
comment_detail.comment_user_avatar = comment_user_avatar; //用户头像
|
|
|
|
|
comment_detail.comment_text = comment_text; //评论内容
|
|
|
|
|
comment_detail.comment_time = time; //评论时间
|
|
|
|
|
comment_detail.reply_id = reply_id; //回复谁的评论的id
|
|
|
|
|
comment_detail.parent_id = parent_id; //评论所属哪个评论id
|
|
|
|
|
comment_detail.reply_name = reply_name; //回复评论人的昵称
|
|
|
|
|
|
|
|
|
|
//判断parent_id是否为0 为0就是评论 不为0就是回复
|
|
|
|
|
if(comment_detail.parent_id != 0) {
|
|
|
|
|
//回复
|
|
|
|
|
comment_list2.unshift(comment_detail);
|
|
|
|
|
} else {
|
|
|
|
|
//评论
|
|
|
|
|
comment_list.unshift(comment_detail);
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
.then(res=>{
|
|
|
|
|
that.setData({
|
|
|
|
|
speak:''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
that.getgood()
|
|
|
|
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title:'已评价',
|
|
|
|
|
icon:'none'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
|
|
let newspeaklist=that.data.good.speaklist
|
|
|
|
|
newspeaklist.push({
|
|
|
|
|
|
|
|
|
|
nickname:wx.getStorageSync('user').nickname,
|
|
|
|
|
speak:speak,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
console.log(newspeaklist)
|
|
|
|
|
|
|
|
|
|
db.collection('teacher_Data').doc(id).update({
|
|
|
|
|
data:{
|
|
|
|
|
speaklist:newspeaklist
|
|
|
|
|
}
|
|
|
|
|
//动态渲染
|
|
|
|
|
ths.setData({
|
|
|
|
|
//发表评论后将以下数据初始化 为下次发表评论做准备
|
|
|
|
|
comment_text: null, //评论内容
|
|
|
|
|
now_reply: 0, //当前点击的评论id
|
|
|
|
|
now_reply_name: null, //当前点击的评论的用户昵称
|
|
|
|
|
now_reply_type: 0, //评论类型
|
|
|
|
|
now_parent_id: 0, //当前点击的评论所属哪个评论id
|
|
|
|
|
placeholder: "什么...", //输入框占字符
|
|
|
|
|
//将加入新数据的数组渲染到页面
|
|
|
|
|
comment_list2 //回复列表
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
.then(res=>{
|
|
|
|
|
that.setData({
|
|
|
|
|
speak:''
|
|
|
|
|
})
|
|
|
|
|
that.getgood()
|
|
|
|
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title:'已评价',
|
|
|
|
|
icon:'none'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//下面的方法可以绑定在输入框的bindblur属性上
|
|
|
|
|
blur(e) {
|
|
|
|
|
const text = e.detail.value.trim();
|
|
|
|
|
if (text == '') {
|
|
|
|
|
this.setData({
|
|
|
|
|
now_reply: 0, //当前点击的评论或回复评论的id
|
|
|
|
|
now_reply_name: null, //当前点击的评论或回复评论的用户昵称
|
|
|
|
|
now_reply_type: 0, //当前回复类型
|
|
|
|
|
now_parent_id: 0, //当前点击的评论或回复评论的所属评论id
|
|
|
|
|
placeholder: "说点什么呢,万一火了呢", //占字符
|
|
|
|
|
focus: false //输入框获取焦点
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//获取输入框内容
|
|
|
|
|
getCommentText(e) {
|
|
|
|
|
var val = e.detail.value;
|
|
|
|
|
wx.cloud.callFunction({
|
|
|
|
|
name:"sendComment",
|
|
|
|
|
data:{
|
|
|
|
|
comment :val
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// 回复评价
|
|
|
|
|
huifuComment(event){
|
|
|
|
|
let that=this
|
|
|
|
|
var index = event.currentTarget.dataset.index
|
|
|
|
|
this.setData({
|
|
|
|
|
comment_text: val
|
|
|
|
|
plcaceHolder : '回复' + this.data.good.speaklist[index].nickname+':',
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 获取公司招聘数据
|
|
|
|
|
getList(){
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|