课程绑架,绑定提交值

beetlsql3-dev
姚丹ab 2 years ago
parent fada35c143
commit d39d2fa2a3

@ -189,10 +189,10 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
}
}else if(f == "edit"){
if(type == '1'||type == 1){
var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"sign=1";
var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"&sign=1";
Common.openDlg(url,"大赛管理/编辑大赛");
}else {
var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"sign=2";
var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"&sign=2";
Common.openDlg(url,"大赛管理/编辑大赛");
}
}

@ -6,7 +6,15 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
// 查询去重的标签列表
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();
@ -49,14 +57,14 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
align: "center",
templet: function (d) {
var prefix = '<!-- \'应用课程类\',\'考证课程类\',\'理论课程类\';-->\n' +
'<select lay-filter="select_courseLabelType" name="courseLabelType">\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>';
content += '<option value="' + value + '" ' + selected + '>' + value + '</option>';
});
return prefix + content + suffix;
@ -69,7 +77,7 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
templet: function (d) {
var prefix = '<!-- \'应用课程类\',\'考证课程类\',\'理论课程类\';-->\n' +
'<select lay-filter="select_courseLabelId" name="courseLabelId">\n' +
'<select lay-filter="select_UpdateCache" name="courseLabelId">\n' +
' <option value="">请选择</option>';
var content = '';
var suffix = '</select>';
@ -77,13 +85,13 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
var labelList = [];
// 一级类型
for (var courseLabel of courseLabelList) {
if(courseLabel.courseLabelType == d.courseLabelType) {
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>';
content += '<option value="' + value.courseLabelId + '" ' + selected + '>' + value.courseLabelName + '</option>';
});
return prefix + content + suffix;
@ -96,7 +104,7 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
templet: function (d) {
// html字符串转对象深拷贝操作相当于每行copy一个下拉框进行回显选中操作
var copyHtml = $($('#selectGxmc').html())
copyHtml.find("option[value="+d.resourcesApplicationIds+"]").attr("selected", true);
copyHtml.find("option[value=" + d.resourcesApplicationIds + "]").attr("selected", true);
return copyHtml.html();
}
},
@ -111,9 +119,24 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
}
}
]]
/* ,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) {
@ -162,6 +185,7 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
});
}, initTableTool: table.on('tool(resourcesApplicationCourseTable)', function (obj) {
var data = obj.data;
//form.render('select'); // 重新加载select表单
if (obj.event === 'edit') {
var url = "/jlw/resourcesApplicationCourse/add.do?courseInfoId=" + data.courseInfoId;
Common.openDlg(url, "");
@ -180,7 +204,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%'],
@ -197,39 +226,46 @@ layui.define(['form', 'laydate', 'table'], function (exports) {
};
//绑定课程名称选择
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);
$(obj.elem).prop('checked', !$(obj.elem).prop('checked'));
form.render();
}
}else {
} else {
$(this).parents("td").siblings('td').eq(1).find('select').empty();
form.render();
}
});
form.on('select(select_)', function (obj) {
var id = obj.value;
return;
var resourcesApplicationCourseId = table.cache['resourcesApplicationCourseTable'][$(this).parents("tr").attr("data-index")].resourcesApplicationCourseId;
if (!$.isEmpty(resourcesApplicationCourseId)) {
var param = {
resourcesApplicationCourseId: resourcesApplicationCourseId,
id: id,
};
var ret = Common.postAjax("/jlw/resourcesApplicationCourse/edit.json", param);
layer.msg(ret.code == 0 ? "绑定成功!" : ret.msg, {
offset: ['50%'],
icon: ret.code == 0 ? 1 : 2,
time: 1000 //2秒关闭如果不配置默认是3秒
});
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; // 将修改后的数据更新到数据表格的缓存数据中
}
});
exports('index', view);

@ -27,7 +27,7 @@
<script type="text/html" id="selectGxmc" >
<layui:simpleDictSelect style='layui-input-inline'
type="resources_application.application_name.1=1"
id="resourcesApplicationIds" name="resourcesApplicationIds"/>
id="resourcesApplicationIds" name="resourcesApplicationIds" lay-filter="select_UpdateCache"/>
</script>
<!--<div class="layui-btn-group">

Loading…
Cancel
Save