var type = 0; //默认是发表评论
// 点击评论
$(document).on("click", ".content_title", function () {
$(".commented").css("display", "none");
$(".commitment").css("display", "block");
$(".mask").css("display", "block");
$(".content").trigger("click").focus()
});
//点击遮罩层
$(document).on("click", ".mask", function () {
$(".commented").css("display", "block");
$(".commitment").css("display", "none");
$(".mask").css("display", "none");
$(".content").attr("placeholder", "在此处输入评论内容...");
});
// 回复话题评论
$(document).on("click", ".content_user", function () {
ruserid = $(this).data("id");//用户id
commentsid = $(this).data("commentsid");//评论id
user_name = $(this).find(".store_name").html();
$(".content").attr("placeholder", "回复 @" + user_name);
type = 1;
$(".commented").css("display", "none");
$(".commitment").css("display", "block");
$(".mask").css("display", "block");
$(".content").trigger("click").focus();
});
$(document).on("click", ".comments", function () {
var content = $(".content").val();//评论内容
if (type == 0) {
$.Ajax({
url: baseUrl + "PCommunity/client/users/commentTopic",
is_login: true,
data: {
topic_id: topic_id,
content: content
},
success: function (res) {
console.log(res)
if (res.code == 1) {
$(".good ").find("span").html(res.result.comments_count);//评论数
$(".commented").css("display", "block");
$(".commitment").css("display", "none");
$(".mask").css("display", "none");
$(".content").val(''); //清空评论内容
var html = '<div class="new_user_comment">\n' +
' <div class="go_back"><span class="withdraw" data-id="' + res.result.comment_id + '">删除</span> </div>\n' +
' <div class="user_info">\n' +
' <div class="user_info1">\n' +
' <div class="info_img"><img src="' + res.result.user_avatar + '" alt=""></div>\n' +
' <div class="content_user">\n' +
' <div class="store_name">' + res.result.user_nickname + '</div>\n' +
' <div class="time">' + res.result.created_at + '</div>\n' +
' <div class="content_comment">' + res.result.content + '</div>\n' +
' </div>\n' +
' </div>\n' +
' <span> <i class="iconfont icon-dianzan2" ></i> 0</span>\n' +
' </div>\n' +
' </div>';
$(".comment_list").prepend(html);
} else {
$.toast(res.result, "text");
}
}
})
} else {
$.Ajax({
url: baseUrl + "PCommunity/client/users/commentTopic",
is_login: true,
data: {
topic_id: topic_id,//话题id
content: content,
ruserid: ruserid,//用户id
commentsid: commentsid,//评论id
},
success: function (res) {
console.log(res);
if (res.code == 1) {
$(".good ").find("span").html(res.result.comments_count);//评论数
$(".commented").css("display", "block");
$(".commitment").css("display", "none");
$(".mask").css("display", "none");
$(".content").val(''); //清空评论内容
$(".content").attr("placeholder", "在此处输入评论内容...");
var user_name1 = user_name;
var html = '<div class="new_user_comment">\n' +
'<div class="go_back"><span class="withdraw" data-id="' + res.result.id + '">删除</span></div>\n' +
' <div class="user_info">\n' +
' <div class="user_info1">\n' +
' <div class="info_img"><img src="' + res.result.user_avatar + '" alt=""></div>\n' +
' <div class="content_user">\n' +
' <div class="store_name">' + res.result.user_nickname + '</div>\n' +
' <div class="time">' + res.result.created_at + '</div>\n' +
' <div class="content_comment">回复 <span style="color: #007aff">@' + user_name1 + '</span>: <span style="white-space: pre-wrap;\n' +
' word-break: break-all;">' + res.result.content + '</span></div>\n' +
' </div>\n' +
' </div>\n' +
' <span class="comment">\n' +
' <i class="iconfont icon-dianzan2"></i>\n' +
' <span>0</span>\n' +
' </span>\n' +
' </div>\n' +
' </div>\n' +
' </div>';
type = 0;
$(".comment_list").prepend(html);
} else {
$.toast(res.result, "text");
}
}
})
}
});