lyg
2025-03-04 72bbec1590f85974d369ce7aeaa05be8905672a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
layui.define(['tool','oaPicker'], function (exports) {
    const layer = layui.layer, tool = layui.tool;
    const opts={
        "box":'commentBox',//容器id
        "input": 'commentInput',
        "topic_id":0,
        "module": '',
        "callback":function(e){
            layer.msg(e.msg);
            if(e.code==0){
                setTimeout(function(){
                    obj.load();
                },1000)
            }            
        }
    };
    const obj = {
        load: function () {
            let me = this;
            let topic_id = me.sets.topic_id, module = me.sets.module;
            let page=1;
            let callback = function (res) {
                layer.closeAll();
                me.template(res,page);
            }
            tool.get("/api/comment/datalist", {topic_id: topic_id,module: module,page:page}, callback);
        },
        template:function(res,page){
            let me = this;
            if (res.code == 0 && res.data.length > 0) {
                let itemComment = '';
                $.each(res.data, function (index, item) {
                    let to_names = '', ops = '' ,ptext='';
                    if (item.to_names !='' && item.to_names !='-') {
                        to_names = '<span class="blue">@' + item.to_names + '</span>';
                    }
                    if (item.admin_id == login_admin) {
                        ops = `<a class="mr-4" data-event="edit" data-id="${item.id}">编辑</a><a class="mr-4" data-event="del" data-id="${item.id}">删除</a>`;
                    }
                    else{
                        ops = `<a class="mr-4" data-event="replay" data-id="${item.id}" data-uid="${item.admin_id}" data-unames="${item.name}">回复</a>`;
                    }
                    if(item.pid>0){
                        ptext=`<div style="padding-bottom:8px;"><fieldset style="border:1px solid #eeeeee; background-color:#f9f9f9;"><legend>回复『${item.padmin}』${item.ptimes}的评论</legend>${item.pcontent}</fieldset></div>`;
                    }
                    itemComment += `
                        <div id="comment_${item.id}" class="comment-item py-3 border-t" data-content="${item.content}">
                        <div class="comment-avatar" title="${item.name}">
                            <img class="comment-image" src="${item.thumb}">
                        </div>
                        <div class="comment-body">
                            <div class="comment-meta">
                                <strong class="comment-name">${item.name}</strong><span class="ml-2 gray" title="${item.create_time}">${item.create_times}${item.update_times}</span>
                            </div>
                            <div class="comment-content py-2">${to_names} ${item.content}</div>
                            ${ptext}
                            <div class="comment-actions">${ops}</div>
                        </div>
                    </div>
                    `;
                });
                if(res.data.length>19){
                    page++;
                    itemComment+='<div class="py-3 log-more"><button class="layui-btn layui-btn-normal layui-btn-sm" type="button">查看更多</button></div>';
                }
                $('#'+me.sets.box).html(itemComment).data('page',page);
            }
            else{
                if(page ==1){
                    $('#'+me.sets.box).html('<div class="layui-data-none">暂无记录</div>');
                }
            }
        },
        add: function (id,content,pid,to_uids) {
            let me = this;
            if (content == '') {
                layer.msg('请完善评论内容');
                return false;
            }
            let postData = { id: id, topic_id: me.sets.topic_id, pid: pid, to_uids: to_uids, module: me.sets.module, content: content};
            tool.post("/api/comment/add", postData, me.sets.callback);
        },
        del: function (id) {
            let me = this;
            layer.confirm('确定删除该评论吗?', {
                icon: 3,
                title: '提示'
            }, function (index) {
                tool.delete("/api/comment/del", { id: id }, me.sets.callback);
                layer.close(index);
            });
        },
        //文本
        textarea: function (id,txt, pid, to_uid, to_uname) {
            let that = this;
            let display='',usersInput='',height='286px';
            if(id==0){
                usersInput='<div class="layui-input-wrap" style="margin-bottom:5px;"><div class="layui-input-prefix"><i class="layui-icon layui-icon-at"></i></div><input type="text" placeholder="要提醒的员工" value="'+to_uname+'" readonly class="layui-input picker-admin" data-type="2" /><input type="hidden" id="to_uids" value="'+to_uid+'" /></div>';
                height='320px';
            }
            $(parent.$('.express-close')).addClass('parent-colse');
            layer.open({
                type: 1,
                title: '请输入评论内容',
                area: ['600px', height],
                content: '<div style="padding:5px;">'+usersInput+'<textarea class="layui-textarea" id="editTextarea" style="width: 100%; height: 160px;">'+txt+'</textarea></div>',
                end: function(){
                    $(parent.$('.express-close')).removeClass('parent-colse');
                },
                btnAlign: 'c',
                btn: ['提交保存'],
                yes: function () {
                    let to_uids = $("#to_uids").val();
                    let newval = $("#editTextarea").val();
                    if (newval != '') {
                        that.add(id,newval,pid,to_uids);
                    } else {
                        layer.msg('请输入评论内容');
                    }
                }
            })
        },
        init: function (options) {
            this.sets = $.extend({}, opts, options);
            let me = this;
            let commentBox = $('#'+me.sets.box);
            me.load();
            $('#'+me.sets.input).on('click', function () {
                me.textarea(0,'',0,0,'');
            })
            //回复
            commentBox.on('click', '[data-event="replay"]', function () {
                let pid = $(this).data('id');
                let to_uid = $(this).data('uid');
                let to_unames = $(this).data('unames');
                me.textarea(0,'',pid,to_uid,to_unames);
            })
            //编辑
            commentBox.on('click', '[data-event="edit"]', function () {
                let id = $(this).data('id');
                let content = commentBox.find('#comment_' + id).data('content');
                me.textarea(id,content,0,0,'');
            })
            //删除
            commentBox.on('click', '[data-event="del"]', function () {
                let id = $(this).data('id');
                me.del(id);
            })
            //加载更多
            commentBox.on('click','.log-more',function(){
                let page = commentBox.data(page);
                let callback = function (res) {
                    me.template(res,page);
                }
                tool.get("/api/comment/datalist", {topic_id: me.sets.topic_id,module: me.sets.module,page:page}, callback);
            });
        }
    };
    exports('oaComment', obj);
});