|
|
|
@ -4,9 +4,17 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
|
|
|
|
|
var table = layui.table;
|
|
|
|
|
var resourcesApplicationCourseTable = null;
|
|
|
|
|
// 查询去重的标签列表
|
|
|
|
|
window.disLabelTypeSelectList = Common.postAjax('/jlw/courseLabel/disLabelType.json').data;
|
|
|
|
|
window.courseLabelList = Common.getAjax('/jlw/courseLabel/getValues.json?courseLabelStatus=1').data;
|
|
|
|
|
|
|
|
|
|
var selectList = Common.postAjax('/jlw/courseLabel/disLabelType.json').data;
|
|
|
|
|
var courseLabelList = Common.getAjax('/jlw/courseLabel/getValues.json?courseLabelStatus=1').data;
|
|
|
|
|
var tableReload = table.reload;
|
|
|
|
|
table.reload = function () {
|
|
|
|
|
var args = [];
|
|
|
|
|
layui.each('resourcesApplicationCourseTable', function (index, item) {
|
|
|
|
|
args.push(item);
|
|
|
|
|
});
|
|
|
|
|
args[2] === undefined && (args[2] = true);
|
|
|
|
|
return tableReload.apply(null, args);
|
|
|
|
|
};
|
|
|
|
|
var view = {
|
|
|
|
|
init: function () {
|
|
|
|
|
this.initTable();
|
|
|
|
@ -47,13 +55,47 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
|
|
|
|
|
field: 'courseLabelType',
|
|
|
|
|
title: '绑定模块',
|
|
|
|
|
align: "center",
|
|
|
|
|
templet: '#select_courseLabelTypeSelect',
|
|
|
|
|
templet: function (d) {
|
|
|
|
|
var prefix = '<!-- \'应用课程类\',\'考证课程类\',\'理论课程类\';-->\n' +
|
|
|
|
|
'<select lay-filter="select_one" name="courseLabelType">\n' +
|
|
|
|
|
' <option value="">请选择</option>';
|
|
|
|
|
var content = '';
|
|
|
|
|
var suffix = '</select>';
|
|
|
|
|
|
|
|
|
|
$.each(selectList, function (key, value) {
|
|
|
|
|
var selected = value == d.courseLabelType ? "selected" : "";
|
|
|
|
|
content += '<option value="' + value + '" ' + selected + '>' + value + '</option>';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return prefix + content + suffix;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'courseLabelId',
|
|
|
|
|
title: '课程类别',
|
|
|
|
|
align: "center",
|
|
|
|
|
templet: '#select_courseLabelIdSelect'
|
|
|
|
|
templet: function (d) {
|
|
|
|
|
|
|
|
|
|
var prefix = '<!-- \'应用课程类\',\'考证课程类\',\'理论课程类\';-->\n' +
|
|
|
|
|
'<select lay-filter="select_UpdateCache" name="courseLabelId">\n' +
|
|
|
|
|
' <option value="">请选择</option>';
|
|
|
|
|
var content = '';
|
|
|
|
|
var suffix = '</select>';
|
|
|
|
|
|
|
|
|
|
var labelList = [];
|
|
|
|
|
// 一级类型
|
|
|
|
|
for (var courseLabel of courseLabelList) {
|
|
|
|
|
if (courseLabel.courseLabelType == d.courseLabelType) {
|
|
|
|
|
labelList.push(courseLabel)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$.each(labelList, function (key, value) {
|
|
|
|
|
var selected = value.courseLabelId == d.courseLabelId ? "selected" : "";
|
|
|
|
|
content += '<option value="' + value.courseLabelId + '" ' + selected + '>' + value.courseLabelName + '</option>';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return prefix + content + suffix;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'resourcesApplicationIds',
|
|
|
|
@ -61,8 +103,8 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
|
|
|
|
|
align: "center",
|
|
|
|
|
templet: function (d) {
|
|
|
|
|
// html字符串转对象,深拷贝操作,相当于每行copy一个下拉框进行回显选中操作
|
|
|
|
|
var copyHtml = $($('#select_resourcesApplicationIds').html())
|
|
|
|
|
copyHtml.find("option[value="+d.resourcesApplicationIds+"]").attr("selected", true);
|
|
|
|
|
var copyHtml = $($('#selectGxmc').html())
|
|
|
|
|
copyHtml.find("option[value=" + d.resourcesApplicationIds + "]").attr("selected", true);
|
|
|
|
|
return copyHtml.html();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -71,17 +113,30 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
|
|
|
|
|
title: '操作',
|
|
|
|
|
align: "center",
|
|
|
|
|
templet: function (d) {
|
|
|
|
|
var htm = '';
|
|
|
|
|
// htm += '<a class="layui-table-link" lay-event="binding">绑定</a>';
|
|
|
|
|
htm += '<input type="checkbox" name="" lay-filter="binding" checked title="绑定">';
|
|
|
|
|
htm += '<a class="layui-table-link" style="padding-left: 15px" lay-event="edit">编辑</a>';
|
|
|
|
|
var htm = '<a class="layui-table-link" lay-event="binding">绑定</a>';
|
|
|
|
|
htm += '<a class="layui-table-link" lay-event="edit">编辑</a>';
|
|
|
|
|
return htm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]]
|
|
|
|
|
/* ,done: function (res, curr, count) {
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
, done: function (res, curr, count) {
|
|
|
|
|
var divForm = $("#" + 'resourcesApplicationCourseTable').next(); // 获取表格,tableId是表格的id
|
|
|
|
|
var tableCache = table.cache['resourcesApplicationCourseTable']; // 获取表格缓存数据,tableCacheId也是表格的id
|
|
|
|
|
var trJqs = divForm.find(".layui-table-body tr"); // 获取表格body下的所有tr标签
|
|
|
|
|
trJqs.each(function () { // 遍历每个tr标签
|
|
|
|
|
var trJq = $(this); // 获得当前遍历的tr标签
|
|
|
|
|
var dataIndex = trJq.attr("data-index"); // 得到当前数据行的data-index,即为第几行数据
|
|
|
|
|
trJq.find("td").each(function () { // 遍历tr标签下的每一个td标签
|
|
|
|
|
var tdJq = $(this); // 获得当前遍历的td标签
|
|
|
|
|
var fieldName = tdJq.attr("data-field"); // 获得当前td标签的字段名
|
|
|
|
|
var selectJq = tdJq.find("select"); // 获得当前td标签下的select标签
|
|
|
|
|
if (selectJq.length == 1) { // 判断select标签是否存在
|
|
|
|
|
selectJq.eq(0).val(tableCache[dataIndex][fieldName]); // 将表格里的缓存数据赋值给select标签
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
form.render('select'); // 重新加载select表单
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
table.on('checkbox(resourcesApplicationCourseTable)', function (obj) {
|
|
|
|
@ -148,7 +203,12 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
|
|
|
|
|
});
|
|
|
|
|
} else if (obj.event === "binding") {
|
|
|
|
|
layer.confirm('是否确定绑定?', function (index) {
|
|
|
|
|
var param = obj.data;
|
|
|
|
|
var param = {
|
|
|
|
|
courseInfoId: data.courseInfoId,
|
|
|
|
|
courseLabelType:data.courseLabelType,
|
|
|
|
|
courseLabelId:data.courseLabelId,
|
|
|
|
|
resourcesApplicationIds:data.resourcesApplicationIds,
|
|
|
|
|
};
|
|
|
|
|
var ret = Common.postAjax("/jlw/courseInfo/edit.json", param);
|
|
|
|
|
layer.msg(ret.code == 0 ? "绑定成功!" : ret.msg, {
|
|
|
|
|
offset: ['50%'],
|
|
|
|
@ -164,66 +224,49 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改绑定checkbox状态
|
|
|
|
|
*/
|
|
|
|
|
function updateBindingBtnStatus(that) {
|
|
|
|
|
$(that).parents("td").parents("tr").find('input:checkbox[title=绑定]').attr('checked', false);
|
|
|
|
|
form.render('checkbox');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//绑定课程名称选择
|
|
|
|
|
form.on('select(select_courseLabelType)', function (obj) {
|
|
|
|
|
if(!$.isEmpty(obj.value)){
|
|
|
|
|
var ret = Common.getAjax("/jlw/courseLabel/getValues.json",{courseLabelType:obj.value,courseLabelStatus:1});
|
|
|
|
|
if(ret.code == 0){
|
|
|
|
|
form.on('select(select_one)', function (obj) {
|
|
|
|
|
var tableCache = table.cache['resourcesApplicationCourseTable'], // 获得数据表格的缓存数据
|
|
|
|
|
value = obj.value, // 得到下拉列表改变后的value值
|
|
|
|
|
field = obj.othis.parents('td').attr('data-field'), // 获得下拉列表的父级td标签的字段名称
|
|
|
|
|
dataIndex = parseInt(obj.othis.parents('tr').attr('data-index')), // 获得变化的下拉列表所在的行index
|
|
|
|
|
lineDate = tableCache[dataIndex]; // 获得数据表格中该行的缓存数据
|
|
|
|
|
if (tableCache[dataIndex][field] != value) { // 判断数据是否发生了变化
|
|
|
|
|
// 这里可以写ajax实现与后台数据的交互
|
|
|
|
|
tableCache[dataIndex][field] = value; // 将修改后的数据更新到数据表格的缓存数据中
|
|
|
|
|
}
|
|
|
|
|
if (!$.isEmpty(obj.value)) {
|
|
|
|
|
var ret = Common.getAjax("/jlw/courseLabel/getValues.json", {
|
|
|
|
|
courseLabelType: obj.value,
|
|
|
|
|
courseLabelStatus: 1
|
|
|
|
|
});
|
|
|
|
|
if (ret.code == 0) {
|
|
|
|
|
var htm = '<option value="">请选择</option>';
|
|
|
|
|
for (var i = 0;i< ret.data.length;i++){
|
|
|
|
|
htm += '<option value="'+ret.data[i].courseLabelId+'">'+ret.data[i].courseLabelName+'</option>';
|
|
|
|
|
for (var i = 0; i < ret.data.length; i++) {
|
|
|
|
|
htm += '<option value="' + ret.data[i].courseLabelId + '">' + ret.data[i].courseLabelName + '</option>';
|
|
|
|
|
}
|
|
|
|
|
$(this).parents("td").siblings('td').eq(1).find('select').empty();
|
|
|
|
|
$(this).parents("td").siblings('td').eq(1).find('select').append(htm);
|
|
|
|
|
updateBindingBtnStatus(this);
|
|
|
|
|
$(obj.elem).prop('checked', !$(obj.elem).prop('checked'));
|
|
|
|
|
form.render();
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
$(this).parents("td").siblings('td').eq(1).find('select').empty();
|
|
|
|
|
form.render();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 下拉框change事件
|
|
|
|
|
form.on('select(select_courseLabelId)', function (obj) {
|
|
|
|
|
table.cache['resourcesApplicationCourseTable'][$(this).parents("tr").data("index")].courseLabelId = obj.value;
|
|
|
|
|
updateBindingBtnStatus(this);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
form.on('select(select_courseLabelId)', function (obj) {
|
|
|
|
|
table.cache['resourcesApplicationCourseTable'][$(this).parents("tr").data("index")].courseLabelId = obj.value;
|
|
|
|
|
updateBindingBtnStatus(this);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
form.on('select(select_resourcesApplicationIds)', function (obj) {
|
|
|
|
|
table.cache['resourcesApplicationCourseTable'][$(this).parents("tr").data("index")].resourcesApplicationIds = obj.value;
|
|
|
|
|
updateBindingBtnStatus(this);
|
|
|
|
|
form.on('select(select_UpdateCache)', function (obj) {
|
|
|
|
|
var tableCache = table.cache['resourcesApplicationCourseTable'], // 获得数据表格的缓存数据
|
|
|
|
|
value = obj.value, // 得到下拉列表改变后的value值
|
|
|
|
|
field = obj.othis.parents('td').attr('data-field'), // 获得下拉列表的父级td标签的字段名称
|
|
|
|
|
dataIndex = parseInt(obj.othis.parents('tr').attr('data-index')), // 获得变化的下拉列表所在的行index
|
|
|
|
|
lineDate = tableCache[dataIndex]; // 获得数据表格中该行的缓存数据
|
|
|
|
|
if (tableCache[dataIndex][field] != value) { // 判断数据是否发生了变化
|
|
|
|
|
// 这里可以写ajax实现与后台数据的交互
|
|
|
|
|
tableCache[dataIndex][field] = value; // 将修改后的数据更新到数据表格的缓存数据中
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
form.on('checkbox(binding)', function (obj) {
|
|
|
|
|
var index = $(this).parents("tr").data("index")
|
|
|
|
|
layer.confirm('是否确定绑定?', function (i) {
|
|
|
|
|
var param = table.cache['resourcesApplicationCourseTable'][index];
|
|
|
|
|
var ret = Common.postAjax("/jlw/courseInfo/edit.json", param);
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
exports('index', view);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|