layui.define(['tool'], function (exports) {
const layer = layui.layer, tool = layui.tool;
const obj = {
addLink: function (id, topic_id, module, url, desc) {
let that = this;
layer.open({
title: '添加链接',
type: 1,
area: ['580px', '240px'],
content: '
',
btnAlign: 'c',
btn: ['提交发布'],
yes: function () {
let callback = function (e) {
if(e.code==0){
layer.closeAll();
layer.msg(e.msg);
if(module == 'project'){
setTimeout(function(){
location.reload();
},2000)
}
else{
tool.load('/' + module + '/index/view/id/' + topic_id);
}
}
else{
layer.msg(e.msg);
}
}
let url = $('#box_url').val();
let desc = $('#box_desc').val();
if (url == '') {
layer.msg('请输入URL');
return false;
}
if (desc == '') {
layer.msg('请输入链接说明');
return false;
}
let postData = { id: id, topic_id: topic_id, module: module, url: url, desc: desc };
tool.post("/project/api/add_link", postData, callback);
}
})
},
log: function (topic_id, module) {
let callback = function (res) {
if (res.code == 0 && res.data.length > 0) {
let itemLog = '';
$.each(res.data, function (index, item) {
if (item.field == 'content') {
itemLog += `
${item.name}
${item.action}了${item.title} ${item.times}
`;
}
else if (item.field == 'file' || item.field == 'link' || item.field == 'user') {
itemLog += `
${item.name}
${item.action}了${item.title}${item.new_content}${item.times}
`;
} else if (item.field == 'new' || item.field == 'delete') {
itemLog += `
${item.name}
${item.action}了${item.title}${item.times}
`;
}
else if (item.field == 'document') {
if (item.action == '修改') {
itemLog += `
${item.name}
${item.action}了${item.title}${item.remark} ${item.times}
`;
}
else {
itemLog += `
${item.name}
${item.action}了${item.title}${item.remark}${item.times}
`;
}
}
else {
itemLog += `
${item.name}
将${item.title}从 ${item.old_content} ${item.action}为${item.new_content}${item.times}
`;
}
});
$("#log_" + module + "_" + topic_id).html(itemLog);
}
}
tool.get("/project/api/task_log", { tid: topic_id, m: module }, callback);
},
load: function (topic_id, module) {
let callback = function (res) {
if (res.code == 0 && res.data.length > 0) {
let itemComment = '';
$.each(res.data, function (index, item) {
let pAdmin = '', ops = '';
if (item.padmin_id > 0) {
pAdmin = '@' + item.pname + '';
}
if (item.admin_id == login_admin) {
ops = '编辑删除';
}
itemComment += `
`;
});
$("#comment_" + module + "_" + topic_id).html(itemComment);
layer.closeAll();
}
}
tool.get("/project/api/project_comment", { tid: topic_id, m: module }, callback);
},
add: function (id, topic_id, pid, padmin_id, module, content, md_content) {
let that = this;
let callback = function (res) {
that.load(topic_id, module);
}
if (content == '') {
layer.msg('请完善评论内容');
return false;
}
let postData = { id: id, topic_id: topic_id, pid: pid, padmin_id: padmin_id, module: module, content: content, md_content: md_content };
tool.post("/project/api/add_comment", postData, callback);
},
del: function (id, topic_id, module) {
let that = this;
layer.confirm('确定删除该评论吗?', {
icon: 3,
title: '提示'
}, function (index) {
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
that.load(topic_id, module);
}
}
tool.delete("/project/api/delete_comment", { id: id }, callback);
layer.close(index);
});
},
//文本
textarea: function (id, topic_id, pid, padmin_id, module, txt) {
let that = this;
layer.open({
type: 1,
title: '请输入内容',
area: ['800px', '360px'],
content: '',
btnAlign: 'c',
btn: ['提交保存'],
yes: function () {
let newval = $("#editTextarea").val();
if (newval != '') {
that.add(id, topic_id, pid, padmin_id, module, newval);
} else {
layer.msg('请输入内容');
}
}
})
}
};
exports('oaComment', obj);
});