layui.define([ 'form', 'laydate', 'table' ], function(exports) { var form = layui.form, laydate = layui.laydate, table = layui.table, resourcesInfoTable = null, courseInfoMap = {},//课程map zjMap = {},//章节map selectMap = {},//已经生成过select的map selectList = ""; var view ={ init:function(){ this.initTable(); this.initSearchForm(); this.initToolBar(); window.dataReload = function(){ Lib.doSearchForm($("#searchForm"),resourcesInfoTable); } }, initTable:function(){ resourcesInfoTable = table.render({ elem : '#resourcesInfoTable', height : Lib.getTableHeight(), cellMinWidth: 100, method : 'post', even:true, size:"lg", url : Common.ctxPath + '/jlw/resourcesInfo/list.json' // 数据接口 ,page : Lib.tablePage // 开启分页 ,limit : 10, cols : [ [ // 表头 { type : 'checkbox' }, { field : 'resourcesInfoName', title : '资源名称',align:"center",style:"text-align: left;" }, { field : 'courseInfoParentParentName', title : '归属课程',align:"center",width:200, templet: function (d) { return selectList; //一级 } }, { field : 'courseInfoParentName', title : '归属章节',align:"center",width:200, templet: function (d) { var htm = ""; return h; }else { return selectMap[d.courseInfoParentId]; } }else { return htm + ""; //二级 } } }, { field : 'courseInfoName', title : '归属小节',align:"center",width:200, templet: function (d) { var htm = ""; return h; }else { return selectMap[d.courseInfoId]; } }else { return htm + ""; //三级 } } }, { field : 'resourcesInfoType', width:150,title : '资源类型',align:"center",templet:function (d){//(1视频 2课件 3附件) return d.resourcesInfoType == 1?"视频":d.resourcesInfoType == 2?"课件":d.resourcesInfoType == 3?"附件":'-'; } }, { field : 'userId',title : '操作', width:180,align:"center", templet: function (d) { var htm = ''; htm += ''; htm += ''; return htm; } } ] ],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); }); } }); table.on('checkbox(resourcesInfoTable)', function(obj){ var resourcesInfo = obj.data; if(obj.checked){ //按钮逻辑Lib.buttonEnable() }else{ } }) }, initSearchForm:function(){ Lib.initSearchForm( $("#searchForm"),resourcesInfoTable,form); }, initToolBar:function(){ toolbar = { add : function() { // 获取选中数据 var url = "/jlw/resourcesInfo/add.do"; Common.openDlg(url,"资源管理/新增资源"); }, refresh: function () {//刷新 searchForm.reset(); Lib.doSearchForm($("#searchForm"), resourcesInfoTable, 1); }, search:function () { Lib.doSearchForm($("#searchForm"), resourcesInfoTable, 1); }, allDel:function () {//批量删除 var checkStatus = table.checkStatus('resourcesInfoTable') ,data = checkStatus.data,ids=""; for(var i = 0;i请选择"); this_1.empty(); this_1.append(""); if(!$.isEmpty(obj.value)){ $.each(courseInfoMap[obj.value].children,function (key,v){ this_.append(""); }); } form.render(); }); //选择归属课程 并且根据选择的课程查询章节 form.on('select(select_chapterId)', function (obj) { var this_ = $("#bindingCourseInfo_dialog select[name='courseInfoId']"); this_.empty(); this_.append(""); if(!$.isEmpty(obj.value)){ $.each(zjMap[obj.value].children,function (key,v){ this_.append(""); }); } form.render(); }); //选择归属课程 并且根据选择的课程查询章节 form.on('select(select_courseInfoIds)', function (obj) { var this_ = $(this).parents("td").next().find("select"); this_.empty(); this_.append(""); $(this).parents("td").next().next().find("select").empty(); $(this).parents("td").next().next().find("select").append(""); if(!$.isEmpty(obj.value)){ $.each(courseInfoMap[obj.value].children,function (key,v){ this_.append(""); }); } form.render(); }); //选择归属课程 并且根据选择的课程查询章节 form.on('select(select_courseInfoIds_1)', function (obj) { var this_ = $(this).parents("td").next().find("select"); this_.empty(); this_.append(""); if(!$.isEmpty(obj.value)){ $.each(zjMap[obj.value].children,function (key,v){ this_.append(""); }); } form.render(); }); //选择归属课程 并且根据选择的课程查询章节 form.on('select(select_courseInfoIds_2)', function (obj) { var r = $(this).parents("td").find("input").context.innerHTML.replace(/ /g,""); $(this).parents("td").find("input").val(r); var resourcesInfoId = table.cache['resourcesInfoTable'][$(this).parents("tr").attr("data-index")].resourcesInfoId; if(!$.isEmpty(resourcesInfoId)){ var ret = Common.postAjax("/jlw/resourcesInfo/edit.json",{resourcesInfoId:resourcesInfoId,courseInfoId:obj.value}); layer.msg(ret.code == 0 ? "绑定成功!" : ret.msg, { offset: ['50%'], icon: ret.code == 0 ? 1 : 2, time: 1000 //2秒关闭(如果不配置,默认是3秒) }); } }); exports('index',view); });