社区-发表评论和回复评论

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");
                        }
                    }
                })
            }

        });

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值