209 lines
5.9 KiB
JavaScript
209 lines
5.9 KiB
JavaScript
layui.define(['tool'], function (exports) {
|
|
const layer = layui.layer;
|
|
const form = layui.form;
|
|
const tool = layui.tool;
|
|
const laydate = layui.laydate;
|
|
const obj = {
|
|
load: function (tid) {
|
|
let callback = function (res) {
|
|
if (res.code == 0 && res.data.length > 0) {
|
|
let itemSchedule = '';
|
|
$.each(res.data, function (index, item) {
|
|
let createTime = new Date(item.create_time * 1000).toLocaleString();
|
|
let lineClass = item.is_new == 1 ? 'unread' : 'isread';
|
|
let readStatus = item.is_new == 1 ? '未读' : '已读';
|
|
itemSchedule +=
|
|
`
|
|
<div class="work-record py-1">
|
|
<div>
|
|
<p><strong>阅读状态:</strong><button class="${lineClass}" data-id="${item.id}" data-status="${item.is_new}">${readStatus}</button></p>
|
|
</div>
|
|
<p class="font-gray" style="margin-top:10px;">
|
|
<strong>${item.name}</strong> 在 <strong>${createTime}</strong> 发布
|
|
</p>
|
|
<p><strong>内容为:</strong>${item.title}</p>
|
|
<p><strong>补充描述:</strong>${item.remark}</p>
|
|
<span class="line"></span>
|
|
</div>
|
|
`;
|
|
});
|
|
$("#schedule_" + tid).html(itemSchedule);
|
|
layer.closeAll();
|
|
|
|
// 添加点击事件以更改读取状态
|
|
$(".unread, .isread").on("click", function () {
|
|
let id = $(this).data("id");
|
|
let status = $(this).data("status");
|
|
let newStatus = status == 1 ? 0 : 1;
|
|
let newClass = newStatus == 1 ? 'unread' : 'isread';
|
|
let newStatusText = newStatus == 1 ? '未读' : '已读';
|
|
|
|
$(this).removeClass().addClass(newClass).text(newStatusText);
|
|
|
|
$.ajax({
|
|
url: "/api/schedule/update_status",
|
|
method: "POST",
|
|
data: {
|
|
id: id,
|
|
is_new: newStatus
|
|
},
|
|
success: function (res) {
|
|
if (res.code == 0) {
|
|
layer.msg("更新成功");
|
|
location.reload();
|
|
} else {
|
|
layer.msg(res.msg);
|
|
}
|
|
},
|
|
error: function () {
|
|
layer.msg("更新失败");
|
|
}
|
|
});
|
|
});
|
|
}
|
|
};
|
|
tool.post("/api/schedule/get_list", { tid: tid }, callback);
|
|
},
|
|
|
|
//保存
|
|
save: function (postData) {
|
|
let callback = function (e) {
|
|
if (e.code == 0) {
|
|
layer.closeAll();
|
|
layer.msg(e.msg);
|
|
if (postData.id > 0) {
|
|
layui.pageTable.reload();
|
|
}
|
|
else {
|
|
tool.load('/task/index/view?id=' + postData.tid);
|
|
}
|
|
} else {
|
|
layer.msg(e.msg);
|
|
}
|
|
}
|
|
tool.post("/schedule/index/add", postData, callback);
|
|
},
|
|
//查看
|
|
view: function (detail) {
|
|
var content = `<div style="width:776px">
|
|
<table class="layui-table" style="margin:12px 12px 0;">
|
|
<tr>
|
|
<td class="layui-td-gray">执行员工</td>
|
|
<td>${detail.name}</td>
|
|
<td class="layui-td-gray">所在部门</td>
|
|
<td>${detail.department}</td>
|
|
<td class="layui-td-gray">工作类型</td>\
|
|
<td>${detail.work_cate}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="layui-td-gray">工作内容</td>
|
|
<td colspan="5">${detail.title}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="layui-td-gray">补充描述</td>
|
|
<td colspan="5">${detail.remark}</td>
|
|
</tr>
|
|
</table>
|
|
<table class="layui-table" style="margin:12px 12px 0;">
|
|
<tr>
|
|
<td class="layui-td-gray">关联项目</td>
|
|
<td>${detail.project}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="layui-td-gray">关联任务</td>
|
|
<td>${detail.task}</td>
|
|
</tr>
|
|
</table>
|
|
</div>`;
|
|
layer.open({
|
|
type: 1,
|
|
title: '工作记录详情',
|
|
area: ['800px', '432px'],
|
|
content: content,
|
|
success: function () {
|
|
|
|
},
|
|
btn: ['关闭'],
|
|
btnAlign: 'c',
|
|
yes: function (idx) {
|
|
layer.close(idx);
|
|
}
|
|
})
|
|
},
|
|
//新增
|
|
add: function (tid, schedule) {
|
|
let that = this, detail = {}, title = '添加工作记录';
|
|
if (tid == 0) {
|
|
if(schedule['admin_id'] != GOUGU_DEV.uid){
|
|
layer.msg('不能编辑他人的工作记录');
|
|
return false;
|
|
}
|
|
title = '编辑工作记录';
|
|
detail['id'] = schedule['id'];
|
|
detail['tid'] = schedule['tid'];
|
|
detail['title'] = schedule['title'];
|
|
detail['remark'] = schedule['remark'];
|
|
} else {
|
|
detail['id'] = 0;
|
|
detail['tid'] = tid;
|
|
detail['title'] = '';
|
|
detail['remark'] = '';
|
|
}
|
|
var content = `<form class="layui-form" style="width:700px">
|
|
<table class="layui-table" style="margin:12px 12px 0;">
|
|
<tr>
|
|
<td class="layui-td-gray">工作内容 <span style="color: red">*</span></td>
|
|
<td><input name="title" class="layui-input" value="${detail.title}" lay-verify="required" lay-reqText="请完成工作内容"></td>
|
|
</tr>
|
|
<tr>
|
|
<td class="layui-td-gray">补充描述</td>
|
|
<td>
|
|
<textarea name="remark" form-input="remark" class="layui-textarea" style="min-height:120px;">${detail.remark}</textarea>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</form>`;
|
|
layer.open({
|
|
type: 1,
|
|
title: title,
|
|
area: ['724px', '396px'],
|
|
content: content,
|
|
success: function () {
|
|
form.render();
|
|
$('[name="title"]').on('input', function () {
|
|
var _val = $(this).val();
|
|
detail.title = _val;
|
|
});
|
|
$('[form-input="remark"]').on('input', function () {
|
|
var _val = $(this).val();
|
|
detail.remark = _val;
|
|
});
|
|
},
|
|
btn: ['确定提交'],
|
|
btnAlign: 'c',
|
|
yes: function (idx) {
|
|
if (detail.title == '') {
|
|
layer.msg('请填写工作内容');
|
|
return;
|
|
}
|
|
that.save(detail);
|
|
// 发送数据到钉钉机器人
|
|
$.ajax({
|
|
url: "/api/dingdingrobot/sendto",
|
|
method: "POST",
|
|
data: {
|
|
message: "工作记录添加成功!"
|
|
},
|
|
success: function (res) {
|
|
console.log(res);
|
|
},
|
|
error: function () {
|
|
console.log("工作记录添加失败!");
|
|
}
|
|
});
|
|
}
|
|
})
|
|
}
|
|
};
|
|
exports('gouguSchedule', obj);
|
|
}); |