From 75bd75639097125e5958993b3bbfc17a3eb1ae38 Mon Sep 17 00:00:00 2001 From: Mlxa0324 Date: Tue, 18 Oct 2022 14:59:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jlw/resourcesApplicationCourse/index.js | 100 ++++++++---------- .../jlw/resourcesApplicationCourse/index.html | 25 +++-- 2 files changed, 65 insertions(+), 60 deletions(-) diff --git a/web/src/main/resources/static/js/jlw/resourcesApplicationCourse/index.js b/web/src/main/resources/static/js/jlw/resourcesApplicationCourse/index.js index 4821f0f3..8929faa7 100644 --- a/web/src/main/resources/static/js/jlw/resourcesApplicationCourse/index.js +++ b/web/src/main/resources/static/js/jlw/resourcesApplicationCourse/index.js @@ -4,8 +4,8 @@ layui.define(['form', 'laydate', 'table'], function (exports) { var table = layui.table; var resourcesApplicationCourseTable = null; // 查询去重的标签列表 - var selectList = Common.postAjax('/jlw/courseLabel/disLabelType.json').data; - var courseLabelList = Common.getAjax('/jlw/courseLabel/getValues.json?courseLabelStatus=1').data; + window.disLabelTypeSelectList = Common.postAjax('/jlw/courseLabel/disLabelType.json').data; + window.courseLabelList = Common.getAjax('/jlw/courseLabel/getValues.json?courseLabelStatus=1').data; var view = { init: function () { @@ -47,47 +47,13 @@ layui.define(['form', 'laydate', 'table'], function (exports) { field: 'courseLabelType', title: '绑定模块', align: "center", - templet: function (d) { - var prefix = '\n' + - ''; - - $.each(selectList, function (key, value) { - var selected = value == d.courseLabelType ? "selected" : ""; - content += ''; - }); - - return prefix + content + suffix; - } + templet: '#select_courseLabelTypeSelect', }, { field: 'courseLabelId', title: '课程类别', align: "center", - templet: function (d) { - - var prefix = '\n' + - ''; - - 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 += ''; - }); - - return prefix + content + suffix; - } + templet: '#select_courseLabelIdSelect' }, { field: 'resourcesApplicationIds', @@ -95,7 +61,7 @@ layui.define(['form', 'laydate', 'table'], function (exports) { align: "center", templet: function (d) { // html字符串转对象,深拷贝操作,相当于每行copy一个下拉框进行回显选中操作 - var copyHtml = $($('#selectGxmc').html()) + var copyHtml = $($('#select_resourcesApplicationIds').html()) copyHtml.find("option[value="+d.resourcesApplicationIds+"]").attr("selected", true); return copyHtml.html(); } @@ -105,8 +71,10 @@ layui.define(['form', 'laydate', 'table'], function (exports) { title: '操作', align: "center", templet: function (d) { - var htm = '绑定'; - htm += '编辑'; + var htm = ''; + // htm += '绑定'; + htm += ''; + htm += '编辑'; return htm; } } @@ -196,6 +164,14 @@ 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)){ @@ -207,6 +183,7 @@ layui.define(['form', 'laydate', 'table'], function (exports) { } $(this).parents("td").siblings('td').eq(1).find('select').empty(); $(this).parents("td").siblings('td').eq(1).find('select').append(htm); + updateBindingBtnStatus(this); form.render(); } }else { @@ -215,23 +192,38 @@ layui.define(['form', 'laydate', 'table'], function (exports) { } }); - 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); + // 下拉框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('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: 1000 //2秒关闭(如果不配置,默认是3秒) + time: 1500 //2秒关闭(如果不配置,默认是3秒) + }, function () { + if (ret.code == 0) { + Lib.tableRefresh(); + } }); - } - }); + }); + }) exports('index', view); diff --git a/web/src/main/resources/templates/jlw/resourcesApplicationCourse/index.html b/web/src/main/resources/templates/jlw/resourcesApplicationCourse/index.html index 69f9a14e..4aa56459 100644 --- a/web/src/main/resources/templates/jlw/resourcesApplicationCourse/index.html +++ b/web/src/main/resources/templates/jlw/resourcesApplicationCourse/index.html @@ -24,17 +24,30 @@ - - + + +