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 = '@' + item.to_names + ''; } if (item.admin_id == login_admin) { ops = `编辑删除`; } else{ ops = `回复`; } if(item.pid>0){ ptext=`
回复『${item.padmin}』${item.ptimes}的评论${item.pcontent}
`; } itemComment += `
${item.name}${item.create_times}${item.update_times}
${to_names} ${item.content}
${ptext}
${ops}
`; }); if(res.data.length>19){ page++; itemComment+='
'; } $('#'+me.sets.box).html(itemComment).data('page',page); } else{ if(page ==1){ $('#'+me.sets.box).html('
暂无记录
'); } } }, 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='
'; height='320px'; } $(parent.$('.express-close')).addClass('parent-colse'); layer.open({ type: 1, title: '请输入评论内容', area: ['600px', height], content: '
'+usersInput+'
', 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); });