mbui.define(['tool','layer','userPicker','loadData'], function (exports) {
const layer = mbui.layer, tool = mbui.tool,userPicker = mbui.userPicker,loadData = mbui.loadData;
const obj = {
comment_box:'comment_box',
module:'module',
topic_id:'topic_id',
load: function (comment_box,module,topic_id) {
let that = this;
that.comment_box=comment_box;
that.module=module;
that.topic_id=topic_id;
loadData({
url:'/api/comment/datalist',
elem:'#'+comment_box,
where: {topic_id: topic_id, module: module},
limit:100,
template:function(data){
let to_names = '', ops = '' ,ptext='';
if (data.to_names !='') {
to_names = `@${data.to_names}`;
}
if (data.admin_id == login_admin) {
ops = `编辑删除`;
}
else{
ops = `回复`;
}
if(data.pid>0){
ptext=`
`;
}
let listItem = `
`;
return listItem;
}
});
},
add: function (topic_id, module,content,to_uids,pid) {
let that = this;
let callback = function (res) {
layer.closeAll();
that.load(that.comment_box,that.module,that.topic_id);
}
if (content == '') {
layer.msg('请完善评论内容');
return false;
}
let postData = { module: module,topic_id: topic_id, content: content, to_uids: to_uids, pid: pid};
tool.post("/api/comment/add", postData, callback);
},
edit: function (id,content) {
let that = this;
let callback = function (res) {
layer.closeAll();
that.load(that.comment_box,that.module,that.topic_id);
}
if (content == '') {
layer.msg('请完善评论内容');
return false;
}
let postData = {id: id, content: content};
tool.post("/api/comment/add", postData, callback);
},
del: function (id) {
let that = this;
layer.confirm('确定删除该评论吗?', function (index) {
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
that.load(that.comment_box,that.module,that.topic_id);
}
}
tool.delete("/api/comment/del", { id: id }, callback);
layer.close(index);
});
},
//文本
textarea: function (id, topic_id, module, content, to_uids, to_unames, pid) {
let that = this;
let usersInput='';
if(id==0){
usersInput='';
}
layer.open({
type:5,
title: '请输入评论内容',
content: ''+usersInput+'
',
btn:['确定','取消'],
yes:function(index){
let content = $("#editTextarea").val();
if (content != '') {
if(id>0){
that.edit(id, content);
}
else{
let to_uids = $("#to_uids").val();
that.add(topic_id, module, content, to_uids, pid);
}
} else {
layer.msg('请输入评论内容');
}
}
});
}
};
exports('oaComment', obj);
});