You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

474 lines
22 KiB
JavaScript

2 years ago
layui.define(['form', 'laydate', 'table'], function (exports) {
3 years ago
var form = layui.form,
2 years ago
laydate = layui.laydate,
table = layui.table,
resourcesInfoTable = null,
courseInfoMap = {},//课程map
zjMap = {},//章节map
selectMap = {},//已经生成过select的map
2 years ago
htmY = '<optgroup label="应用课程类">',
htmL = '<optgroup label="理论课程类">',
htmK = '<optgroup label="考证课程类">',
htmO = '<optgroup label="开课课程类">',
currentAuthCourseInfoDetails = Common.getAjax("/jlw/universitiesCollegesJurisdictionCurriculumResources/getCourseSystemOAndUniversities.json").data;
/*// 应用课程类
2 years ago
var applicationCourseList = currentAuthCourseInfoDetails.applicationCourseList || [];
// 理论课程类
var theoryCourseList = currentAuthCourseInfoDetails.theoryCourseList || [];
// 考证课程类
var textualResearchCourseList = currentAuthCourseInfoDetails.textualResearchCourseList || [];*/
// 应用课程类
var applicationCourseList = [];
// 理论课程类
var theoryCourseList = [];
// 考证课程类
var textualResearchCourseList = [];
// 理论课程类+开课课程
var openCourseList = [];
function childCourseList(courseInfoId,courseInfoType,sourceType){
var data = Common.getAjax("/jlw/courseInfo/getChapterSystemOAndUniversities.json", {
courseInfoParentId: courseInfoId,
courseInfoType:courseInfoType,
sourceType:sourceType
}).data;//获取课程数据
return data
}
currentAuthCourseInfoDetails.forEach(function(e,i){
if(e.sourceType == 2){
if(e.courseLabelType == '考证课程类'){
textualResearchCourseList.push(e);
}else if(e.courseLabelType == '理论课程类'){
theoryCourseList.push(e);
}else if(e.courseLabelType == '应用课程类'){
applicationCourseList.push(e);
}
}else if(e.sourceType == 1){
openCourseList.push(e)
}
});
var selectList ="<select lay-filter='select_courseInfoIds_'><option value=''>请选择</option>";
for (let currentAuthCourseInfoDetail of applicationCourseList) {
htmY += '<option value="' + (currentAuthCourseInfoDetail.courseInfoId || '-1')+'" status="'+currentAuthCourseInfoDetail.sourceType+'">' + (currentAuthCourseInfoDetail.courseInfoName || '未查询到数据') + '</option>';
}
for (let currentAuthCourseInfoDetail of theoryCourseList) {
htmL += '<option value="'+ (currentAuthCourseInfoDetail.courseInfoId || '-1')+'" status="'+currentAuthCourseInfoDetail.sourceType+'">'+ (currentAuthCourseInfoDetail.courseInfoName || '未查询到数据') +'</option>';
}
for (let currentAuthCourseInfoDetail of textualResearchCourseList) {
htmK += '<option value="'+ (currentAuthCourseInfoDetail.courseInfoId || '-1') + '" status="'+currentAuthCourseInfoDetail.sourceType+'">'+ (currentAuthCourseInfoDetail.courseInfoName || '未查询到数据') +'</option>';
}
for (let currentAuthCourseInfoDetail of openCourseList) {
htmO += '<option value="'+ (currentAuthCourseInfoDetail.courseInfoId || '-1') +'" status="'+currentAuthCourseInfoDetail.sourceType+'">'+ (currentAuthCourseInfoDetail.courseInfoName || '未查询到数据') +'</option>';
}
if($("#isUser").val() === "true"){
selectList += htmY + '</optgroup>' + htmK + '</optgroup>' + htmL + '</optgroup>' + htmO + '</optgroup>' + "</select>";
//console.log($("#isUser").val())
}else {
selectList+= htmL + '</optgroup>' + htmO + '</optgroup>' + "</select>";
}
function selectedHandler(val,val1) {
return val == val1 ? 'selected = "selected"' : '';
}
/*$.each(courseLabelTypes, function (key, value) {
2 years ago
courseInfoMap[value.courseInfoId] = {courseInfoName: value.courseInfoName, children: value.children};
$.each(value.children, function (k, v) {
zjMap[v.courseInfoId] = {courseInfoName: v.courseInfoName, children: v.children};
3 years ago
});
});*/
2 years ago
2 years ago
var view = {
init: function () {
3 years ago
this.initTable();
this.initSearchForm();
this.initToolBar();
2 years ago
window.dataReload = function () {
Lib.doSearchForm($("#searchForm"), resourcesInfoTable);
3 years ago
}
},
2 years ago
initTable: function () {
3 years ago
resourcesInfoTable = table.render({
2 years ago
elem: '#resourcesInfoTable',
height: Lib.getTableHeight(),
3 years ago
cellMinWidth: 100,
2 years ago
method: 'post',
even: true,
size: "lg",
url: Common.ctxPath + '/jlw/resourcesInfo/list.json' // 数据接口
2 years ago
, page: Lib.tablePage // 开启分页
, limit: 10,
cols: [[ // 表头
3 years ago
{
2 years ago
type: 'checkbox'
3 years ago
},
2 years ago
{
field: 'resourcesInfoName', title: '资源名称', align: "center", style: "text-align: left;"
},
{
field: 'courseInfoParentParentName',
title: '归属课程',
templet: function (d) {
return selectList; //一级
}
},
{
field: 'courseInfoParentName',
title: '归属章节',
align: "center",
templet: function (d) {
var htm = "<select lay-filter='select_courseInfoIds_1'><option value=''>请选择</option>";
if (!$.isEmpty(d.courseInfoParentId)) {
if ($.isEmpty(selectMap[d.courseInfoParentParentId])) {
2 years ago
var h = htm;
var courseInfoChildtList = childCourseList(d.courseInfoParentParentId,2,d.sourceType);
if (!$.isEmpty(courseInfoChildtList)) {
courseInfoMap[d.courseInfoParentParentId] = courseInfoChildtList;
$.each(courseInfoChildtList, function (key, v) {
2 years ago
h += "<option value='" + v.courseInfoId + "'>" + v.courseInfoName + "</option>";
});
}
selectMap[d.courseInfoParentParentId] = h + "</select>";
2 years ago
return h;
} else {
return selectMap[d.courseInfoParentParentId];
3 years ago
}
2 years ago
} else {
return htm + "</select>"; //二级
3 years ago
}
3 years ago
}
2 years ago
},
{
field: 'courseInfoName', title: '归属小节', align: "center", width: 200, templet: function (d) {
var htm = "<select lay-filter='select_courseInfoIds_2'><option value=''>请选择</option>";
if (!$.isEmpty(d.courseInfoId)) {
if ($.isEmpty(selectMap[d.courseInfoParentId])) {
2 years ago
var h = htm;
var courseInfoChildtChildList = childCourseList(d.courseInfoParentId,3,d.sourceType);
if (!$.isEmpty(courseInfoChildtChildList)) {
zjMap[d.courseInfoParentId] = courseInfoChildtChildList;
$.each(courseInfoChildtChildList, function (key, v) {
2 years ago
h += "<option value='" + v.courseInfoId + "'>" + v.courseInfoName + "</option>";
});
}
selectMap[d.courseInfoParentId] = h + "</select>";
2 years ago
return h;
} else {
return selectMap[d.courseInfoParentId];
3 years ago
}
2 years ago
} else {
return htm + "</select>"; //三级
3 years ago
}
3 years ago
}
2 years ago
},
{
2 years ago
field: 'addTypeText', title: '来源', align: "center"
2 years ago
},
/*{
2 years ago
field: 'orgIdText', title: '上传院校', align: "center"
},*/
2 years ago
{
2 years ago
field: 'resourcesInfoType', title: '资源类型', align: "center", templet: function (d) {//(1视频 2PPT 3PDF)
var text = d.resourcesInfoType == 1 ? "视频" : d.resourcesInfoType == 2 ? "PPT" : d.resourcesInfoType == 3 ? "PDF" : d.resourcesInfoType == 4 ? "链接" : d.resourcesInfoType == 5 ? "图文" : '-';
2 years ago
return '<span class="textType">' + text + '</span>';
}
},
{
2 years ago
field: 'userId', title: '操作', align: "center", field: 'right', templet: function (d) {
2 years ago
var htm = '<a class="layui-table-link" lay-event="edit">编辑</a>';
2 years ago
// htm += '<a class="layui-table-link" lay-event="previewPage" >' + (d.resourcesInfoType == 3 ? '下载' : '预览') + '</a>';
2 years ago
if(d.resourcesInfoType == 4){
2 years ago
htm += '<a class="layui-table-link" href="'+d.resourcesInfoContent+'" target="_blank" >预览</a>';
2 years ago
}else {
2 years ago
htm += '<a class="layui-table-link" lay-event="previewPage" >预览</a>';
2 years ago
}
2 years ago
htm += '<a class="layui-table-link" lay-event="del">删除</a>';
return htm;
}
3 years ago
}
2 years ago
]], done: function (res, curr, count) {
$.each(res.data, function (k, v) {
$("div[lay-id='resourcesInfoTable'] tbody tr:eq(" + k + ")").find("select:eq(0)").val(v.courseInfoParentParentId);
$("div[lay-id='resourcesInfoTable'] tbody tr:eq(" + k + ")").find("select:eq(1)").val(v.courseInfoParentId);
$("div[lay-id='resourcesInfoTable'] tbody tr:eq(" + k + ")").find("select:eq(2)").val(v.courseInfoId);
});
form.render();
$.each($("td[data-field='courseInfoName']"), function (k, v) {
$(this).find("input").val($(this).find("input").context.dataset.content);
});
3 years ago
}
});
2 years ago
table.on('checkbox(resourcesInfoTable)', function (obj) {
3 years ago
var resourcesInfo = obj.data;
2 years ago
if (obj.checked) {
3 years ago
//按钮逻辑Lib.buttonEnable()
2 years ago
} else {
3 years ago
}
})
},
2 years ago
initSearchForm: function () {
Lib.initSearchForm($("#searchForm"), resourcesInfoTable, form);
3 years ago
},
2 years ago
initToolBar: function () {
3 years ago
toolbar = {
2 years ago
add: function () { // 获取选中数据
3 years ago
var url = "/jlw/resourcesInfo/add.do";
2 years ago
Common.openDlg(url, "资源管理/新增资源");
3 years ago
},
refresh: function () {//刷新
searchForm.reset();
Lib.doSearchForm($("#searchForm"), resourcesInfoTable, 1);
},
2 years ago
search: function () {
3 years ago
Lib.doSearchForm($("#searchForm"), resourcesInfoTable, 1);
},
2 years ago
allDel: function () {//批量删除
3 years ago
var checkStatus = table.checkStatus('resourcesInfoTable')
2 years ago
, data = checkStatus.data, ids = "";
for (var i = 0; i < data.length; i++) {
3 years ago
ids += data[i].resourcesInfoId;
2 years ago
if (i < data.length - 1) {
3 years ago
ids += ",";
}
}
2 years ago
if ($.isEmpty(ids)) {
3 years ago
layer.msg("请选择需要删除的数据!", {
offset: ['50%'],
icon: 2,
time: 1500 //2秒关闭如果不配置默认是3秒
});
return;
}
deleteInfo(ids);
},
2 years ago
bindingCourseInfo: function () {//批量绑定课程
3 years ago
var checkStatus = table.checkStatus('resourcesInfoTable')
2 years ago
, data = checkStatus.data, ids = "";
for (var i = 0; i < data.length; i++) {
3 years ago
ids += data[i].resourcesInfoId;
2 years ago
if (i < data.length - 1) {
3 years ago
ids += ",";
}
}
2 years ago
if ($.isEmpty(ids)) {
3 years ago
layer.msg("请选择需要绑定章节的数据!", {
offset: ['50%'],
icon: 2,
time: 1500 //2秒关闭如果不配置默认是3秒
});
return;
}
bindingCourseInfo(ids);
}
2 years ago
};
$('.ext-toolbar').on('click', function () {
3 years ago
var type = $(this).data('type');
toolbar[type] ? toolbar[type].call(this) : '';
});
}, initTableTool: table.on('tool(resourcesInfoTable)', function (obj) {
var data = obj.data;
if (obj.event === 'edit') {
2 years ago
var url = "/jlw/resourcesInfo/add.do?resourcesInfoId=" + data.resourcesInfoId;
Common.openDlg(url, "资源管理/编辑资源");
} else if (obj.event === "del") {
3 years ago
deleteInfo(data.resourcesInfoId);
2 years ago
} else if (obj.event === "previewPage") {
3 years ago
Lib.downloadFile(data);
2 years ago
}else if(obj.event === "look"){
var url = data.resourcesInfoContent;
var name = data.resourcesInfoName;
Lib.downloadFile2(url,name);
3 years ago
}
})
}
2 years ago
function deleteInfo(ids) {
3 years ago
layer.confirm('是否确定删除数据?', function (index) {
var ret = Common.postAjax("/jlw/resourcesInfo/deleteCourseSystemOAndUniversities.json", {ids: ids});
3 years ago
layer.msg(ret.code == 0 ? "删除成功!" : ret.msg, {
offset: ['50%'],
icon: ret.code == 0 ? 1 : 2,
time: 1500 //2秒关闭如果不配置默认是3秒
}, function () {
if (ret.code == 0) {
Lib.tableRefresh();
}
});
});
}
//批量绑定章节
2 years ago
function bindingCourseInfo(ids) {
3 years ago
layer.open({
type: 1,
title: "批量绑定章节",
shadeClose: true,
btn: ['确定', '关闭'],
btnAlign: 'c',
area: ['620px', '360px'],
content: $("#bindingCourseInfo_dialog"),
success: function (layero, index) {
$("#bindingCourseInfo_dialog select").val("");
2 years ago
$("#bindingCourseInfo_dialog .layui-input-inline").css("width", "400px");
3 years ago
form.render();
}, yes: function (index) {
var courseInfoId = $("#bindingCourseInfo_dialog select[name='courseInfoId']").val();
2 years ago
if ($.isEmpty(courseInfoId)) {
3 years ago
layer.msg("请选择归属小结!");
2 years ago
return;
3 years ago
}
2 years ago
var ret = Common.postAjax("/jlw/resourcesInfo/setCourseInfoId.json", {
courseInfoId: courseInfoId,
resourcesInfoIds: ids
});
3 years ago
layer.msg(ret.code == 0 ? "绑定成功!" : ret.msg, {
offset: ['50%'],
icon: ret.code == 0 ? 1 : 2,
time: 1500 //2秒关闭如果不配置默认是3秒
}, function () {
if (ret.code == 0) {
Lib.tableRefresh();
layer.close(index);
}
});
}, btn2: function (index, layero) {
layer.close(index);
}
});
}
2 years ago
//选择归属课程 并且根据选择的课程查询章节 resourcesQuestionIdsIsNotNull:查询题目不为空的章节
2 years ago
form.on('select(select_courseInfoIds)', function (obj) {
let sourceType = $("select[name='courseInfoId_0']").find('option:selected').attr("status");
let courseInfoType = 2;//courseInfoType2 章节3 节)
Lib.getCourseInfo($("select[name='courseInfoId_1']"), obj.value,courseInfoType,sourceType, 1);
$("select[name='courseInfoId_2']").empty();
layui.form.render();
2 years ago
});
//选择归属课程 并且根据选择的课程查询章节
form.on('select(select_courseInfoIds_Node)', function (obj) {
let sourceType = $("select[name='courseInfoId_0']").find('option:selected').attr("status");
let courseInfoType = 3;//courseInfoType2 章节3 节)
Lib.getCourseInfo($("select[name='courseInfoId_2']"), obj.value,courseInfoType,sourceType);
2 years ago
});
3 years ago
//选择归属课程 并且根据选择的课程查询章节
form.on('select(select_courseId)', function (obj) {
var this_ = $("#bindingCourseInfo_dialog select[name='chapterId']");
var this_1 = $("#bindingCourseInfo_dialog select[name='courseInfoId']");
this_.empty();
this_.append("<option value=''>请选择</option>");
this_1.empty();
this_1.append("<option value=''>请选择</option>");
2 years ago
if (!$.isEmpty(obj.value)) {
$.each(courseInfoMap[obj.value].children, function (key, v) {
3 years ago
this_.append("<option value='" + v.courseInfoId + "'>" + v.courseInfoName + "</option>");
});
}
form.render();
});
//选择归属课程 并且根据选择的课程查询章节
form.on('select(select_chapterId)', function (obj) {
var this_ = $("#bindingCourseInfo_dialog select[name='courseInfoId']");
this_.empty();
this_.append("<option value=''>请选择</option>");
2 years ago
if (!$.isEmpty(obj.value)) {
$.each(zjMap[obj.value].children, function (key, v) {
3 years ago
this_.append("<option value='" + v.courseInfoId + "'>" + v.courseInfoName + "</option>");
});
}
form.render();
});
//选择归属课程 并且根据选择的课程查询章节
2 years ago
form.on('select(select_courseInfoIds_)', function (obj) {
3 years ago
var this_ = $(this).parents("td").next().find("select");
this_.empty();
this_.append("<option value=''>请选择</option>");
$(this).parents("td").next().next().find("select").empty();
$(this).parents("td").next().next().find("select").append("<option value=''>请选择</option>");
2 years ago
if (!$.isEmpty(obj.value)) {
if(!$.isEmpty(courseInfoMap[obj.value])){
$.each(courseInfoMap[obj.value], function (key, v) {
this_.append("<option value='" + v.courseInfoId + "'>" + v.courseInfoName + "</option>");
});
}else {
let sourceType = $(obj.elem).find("option:selected").attr("status");
var courseInfoChildtList = childCourseList(obj.value,2,sourceType);
if (!$.isEmpty(courseInfoChildtList)) {
courseInfoMap[obj.value] = courseInfoChildtList;
$.each(courseInfoChildtList, function (key, v) {
this_.append("<option value='" + v.courseInfoId + "'>" + v.courseInfoName + "</option>");
});
}
selectMap[obj.value] = this_.html();
}
3 years ago
}
form.render();
});
//选择归属课程 并且根据选择的课程查询章节
form.on('select(select_courseInfoIds_1)', function (obj) {
var this_ = $(this).parents("td").next().find("select");
this_.empty();
this_.append("<option value=''>请选择</option>");
2 years ago
if (!$.isEmpty(obj.value)) {
if(!$.isEmpty(zjMap[obj.value])){
$.each(zjMap[obj.value], function (key, v) {
this_.append("<option value='" + v.courseInfoId + "'>" + v.courseInfoName + "</option>");
});
}else{
let sourceType = $(obj.elem).parents("td").prevAll('td').find("option:selected").attr("status");;
var courseInfoChildtChildList = childCourseList(obj.value,3,sourceType);
if (!$.isEmpty(courseInfoChildtChildList)) {
zjMap[obj.value] = courseInfoChildtChildList;
$.each(courseInfoChildtChildList, function (key, v) {
this_.append("<option value='" + v.courseInfoId + "'>" + v.courseInfoName + "</option>");
});
}
selectMap[obj.value] = this_.html();
}
3 years ago
}
form.render();
});
//选择归属课程 并且根据选择的课程查询章节
form.on('select(select_courseInfoIds_2)', function (obj) {
2 years ago
var r = $(this).parents("td").find("input").context.innerHTML.replace(/&nbsp;/g, "");
3 years ago
$(this).parents("td").find("input").val(r);
var resourcesInfoId = table.cache['resourcesInfoTable'][$(this).parents("tr").attr("data-index")].resourcesInfoId;
2 years ago
if (!$.isEmpty(resourcesInfoId)) {
var ret = Common.postAjax("/jlw/resourcesInfo/edit.json", {
resourcesInfoId: resourcesInfoId,
courseInfoId: obj.value
});
3 years ago
layer.msg(ret.code == 0 ? "绑定成功!" : ret.msg, {
offset: ['50%'],
icon: ret.code == 0 ? 1 : 2,
time: 1000 //2秒关闭如果不配置默认是3秒
});
}
});
2 years ago
exports('index', view);
3 years ago
});