gs-jjsp-web/bns/js/studyExam/studyTask.js

240 lines
7.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let form, layer, table, tableIns, laydate;
let pageNum = 1, limitSize = 10; // 默认第一页分页数量为20
let user = getUser();
layui.use(['form', 'layer', 'table'], function () {
form = layui.form;
layer = layui.layer;
table = layui.table;
pages(1, 10, 1);
})
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
$.ajax({
url: dataUrl + "proteam/pot/studyTask/getStudyTaskList?token=" + token,
data: params,
type: 'POST',
async: false,
success: function (result) {
if (result.code === 200) {
if (result.data) {
initTable(result.data, result.limit, result.curr)
laypages(result.count, result.curr, result.limit)
}
} else if (result.code === 500) {
layer.alert(result.msg, { icon: 2 })
} else if (result.code === 401) {
logout(1);
}
}, error: function () {
}
});
}
function laypages(total, page, limit) {
layui.use(['laypage'], function () {
let laypage = layui.laypage;
laypage.render({
elem: 'voi-page',
count: total,
curr: page,
limit: limit,
limits: [10, 20, 50, 100],
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
groups: 5,
jump: function (obj, first) {
if (!first) {
pageNum = obj.curr, limitSize = obj.limit;
pages(obj.curr, obj.limit, null);
}
}
});
})
}
/*初始化表格*/
function initTable(dataList, limit, page) {
let loadingMsg = layer.msg("数据加载中,请稍候...", { icon: 16, scrollbar: false, time: 0, });
tableIns = table.render({
id: 'todayTaskTable',
elem: "#todayTaskTable",
height: "full-150",
data: dataList,
cols: [
[
{
title: "序号",
width: '5%',
unresize: true,
align: "center",
templet: function (d) {
return (page - 1) * limit + d.LAY_NUM;
}
},
{
field: "studyTaskName",
title: "学习任务名称",
width: '15%',
unresize: false,
align: "center",
templet: function (d) {
if (d.studyTaskName) {
if (d.studyTaskName.length > 60) {
return '<span title="' + d.studyTaskName + '">' + d.studyTaskName.substring(0, 60) + '...</span>'
} else {
return '<span title="' + d.studyTaskName + '">' + d.studyTaskName + '</span>'
}
} else {
return '';
}
}
},
{
field: "fileNum",
title: "学习课件",
width: '10%',
unresize: false,
align: "center",
},
{
field: "studyObject",
title: "学习对象",
width: '15%',
unresize: false,
align: "center",
templet: function (d) {
if (d.studyObject === '2') {
return '值班员'
} else if (d.studyObject === '3') {
return '地市人员'
} else if (d.studyObject === '2,3' || d.studyObject === '3,2') {
return '值班员、地市人员'
}
}
},
{
field: "publishUser",
title: "发布人",
width: '15%',
unresize: false,
align: "center",
},
{
field: "publishTime",
title: "发布时间",
width: '20%',
unresize: false,
align: "center",
},
{
field: "publishStatus",
title: "发布状态",
width: '10%',
unresize: false,
align: "center",
templet: function (d) {
if (d.publishStatus === '0') {
return '<span style="color:#f40">未发布</span>'
} else if (d.publishStatus === '1') {
return '<span style="color:green">已发布</span>'
}
}
},
{
title: "操作",
width: '10%',
unresize: false,
align: "center",
templet: function (d) {
let html = '';
if (d.publishStatus === '0') {
html += "<a onclick='addData(" + JSON.stringify(d) + ",2)'>编辑</a><div>|</div>";
html += "<a onclick='delData(" + JSON.stringify(d) + ")'>删除</a>";
} else if (d.publishStatus === '1') {
html += "<a onclick='viewTrainRecord(" + JSON.stringify(d) + ")'>查看</a>";
}
return html;
}
},
],
],
limit: limit,
done: function (res, curr, count) {
layer.close(loadingMsg);
},
});
}
// 获取参数
function getReqParams(page, limit, type) {
let obj = {};
if (!type) {
obj = {
page: page + "",
limit: limit + "",
studyTaskName: $('#studyTaskName').val(),
roleType: user.isSup,
userId: user.userId
};
} else {
obj = {
page: 1,
limit: limit,
studyTaskName: $('#studyTaskName').val(),
roleType: user.isSup,
userId: user.userId
};
}
return obj;
}
// 查询
function query(type) {
if (type === 2) {
$('#studyTaskName').val('');
}
pages(1, limitSize);
}
// 新增/修改 学习任务
function addData(params, type) {
let title = '', content = '';
if (type === 1) {
title = '新增'
content = 'studyTaskForm.html'
params = {};
} else {
title = '修改';
content = 'studyTaskEditForm.html'
}
openIframeByParamObj7("addOrUpdateStudyTask", title, content, "72%", "90%", params);
}
// 培训记录
function viewTrainRecord(params) {
openIframeByParamObjNoTitle("viewTrainRecord", '培训记录', "trainRecord.html", "100%", "100%", params);
}
// 删除数据
function delData(obj) {
layer.confirm('确定删除吗?', function () {
let loadingMsg = layer.msg('正在删除,请稍等...', { icon: 16, shade: 0.01, time: '0' });
let url = dataUrl + "proteam/pot/studyTask/delStudyTask";
let params = { id: obj.id };
ajaxRequest2(url, "POST", params, true, function (result) {
layer.close(loadingMsg); // 关闭提示层
if (result.code === 200) {
parent.layer.msg(result.msg, { icon: 1 })
query(1);
} else {
layer.msg(result.msg, { icon: 2 })
}
}, function (xhr) {
layer.close(loadingMsg); // 关闭提示层
error(xhr)
}, null, token);
})
}