@ -1,159 +1,174 @@
layui . define ( [ 'form' , 'laydate' , 'table' ] , function ( exports ) {
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 = "<select lay-filter='select_courseInfoIds'><option value=''>请选择</option>" ,
courseLabelTypes = Common . getAjax ( "/jlw/courseInfo/getTreeByCourseLabelTypes.json" , { courseLabelTypes : "实务课程类" , rankLimit : 3 } ) . data ; //获取课程数据
$ . each ( courseLabelTypes , function ( key , value ) {
selectList += '<option value="' + value . courseInfoId + '">' + value . courseInfoName + '</option>' ;
courseInfoMap [ value . courseInfoId ] = { courseInfoName : value . courseInfoName , children : value . children } ;
$ . each ( value . children , function ( k , v ) {
zjMap [ v . courseInfoId ] = { courseInfoName : v . courseInfoName , children : v . children } ;
laydate = layui . laydate ,
table = layui . table ,
resourcesInfoTable = null ,
courseInfoMap = { } , //课程map
zjMap = { } , //章节map
selectMap = { } , //已经生成过select的map
selectList = "<select lay-filter='select_courseInfoIds'><option value=''>请选择</option>" ,
courseLabelTypes = Common . getAjax ( "/jlw/courseInfo/getTreeByCourseLabelTypes.json" , {
courseLabelTypes : "实务课程类" ,
rankLimit : 3
} ) . data ; //获取课程数据
$ . each ( courseLabelTypes , function ( key , value ) {
selectList += '<option value="' + value . courseInfoId + '">' + value . courseInfoName + '</option>' ;
courseInfoMap [ value . courseInfoId ] = { courseInfoName : value . courseInfoName , children : value . children } ;
$ . each ( value . children , function ( k , v ) {
zjMap [ v . courseInfoId ] = { courseInfoName : v . courseInfoName , children : v . children } ;
} ) ;
} ) ;
selectList += "</select>" ;
var view = {
init : function ( ) {
var view = {
init : function ( ) {
this . initTable ( ) ;
this . initSearchForm ( ) ;
this . initToolBar ( ) ;
window . dataReload = function ( ) {
Lib . doSearchForm ( $ ( "#searchForm" ) , resourcesInfoTable ) ;
window . dataReload = function ( ) {
Lib . doSearchForm ( $ ( "#searchForm" ) , resourcesInfoTable ) ;
}
} ,
initTable : function ( ) {
initTable : function ( ) {
resourcesInfoTable = table . render ( {
elem : '#resourcesInfoTable' ,
height : Lib . getTableHeight ( ) ,
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 : [ [ // 表头
method : 'post' ,
even : true ,
size : "lg" ,
url : Common . ctxPath + '/jlw/resourcesInfo/list.json' // 数据接口
, page : Lib . tablePage // 开启分页
, limit : 10 ,
cols : [ [ // 表头
{
type : 'checkbox'
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 = "<select lay-filter='select_courseInfoIds_1'><option value=''>请选择</option>" ;
if ( ! $ . isEmpty ( d . courseInfoParentId ) ) {
if ( $ . isEmpty ( selectMap [ d . courseInfoParentId ] ) ) {
var h = htm ;
if ( ! $ . isEmpty ( courseInfoMap [ d . courseInfoParentParentId ] ) ) {
$ . each ( courseInfoMap [ d . courseInfoParentParentId ] . children , function ( key , v ) {
h += "<option value='" + v . courseInfoId + "'>" + v . courseInfoName + "</option>" ;
} ) ;
{
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 = "<select lay-filter='select_courseInfoIds_1'><option value=''>请选择</option>" ;
if ( ! $ . isEmpty ( d . courseInfoParentId ) ) {
if ( $ . isEmpty ( selectMap [ d . courseInfoParentId ] ) ) {
var h = htm ;
if ( ! $ . isEmpty ( courseInfoMap [ d . courseInfoParentParentId ] ) ) {
$ . each ( courseInfoMap [ d . courseInfoParentParentId ] . children , function ( key , v ) {
h += "<option value='" + v . courseInfoId + "'>" + v . courseInfoName + "</option>" ;
} ) ;
}
selectMap [ d . courseInfoParentId ] = h + "</select>" ;
return h ;
} else {
return selectMap [ d . courseInfoParentId ] ;
}
selectMap [ d . courseInfoParentId ] = h + "</select>" ;
return h ;
} else {
return selectMap [ d . courseInfoParentId ] ;
} else {
return htm + "</select>" ; //二级
}
} else {
return htm + "</select>" ; //二级
}
}
} ,
{
} ,
{
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 . courseInfoId ] ) ) {
var h = htm ;
if ( ! $ . isEmpty ( zjMap [ d . courseInfoParentId ] ) ) {
$ . each ( zjMap [ d . courseInfoParentId ] . children , function ( key , v ) {
h += "<option value='" + v . courseInfoId + "'>" + v . courseInfoName + "</option>" ;
} ) ;
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 . courseInfoId ] ) ) {
var h = htm ;
if ( ! $ . isEmpty ( zjMap [ d . courseInfoParentId ] ) ) {
$ . each ( zjMap [ d . courseInfoParentId ] . children , function ( key , v ) {
h += "<option value='" + v . courseInfoId + "'>" + v . courseInfoName + "</option>" ;
} ) ;
}
selectMap [ d . courseInfoId ] = h + "</select>" ;
return h ;
} else {
return selectMap [ d . courseInfoId ] ;
}
selectMap [ d . courseInfoId ] = h + "</select>" ;
return h ;
} else {
return selectMap [ d . courseInfoId ] ;
} else {
return htm + "</select>" ; //三级
}
} else {
return htm + "</select>" ; //三级
}
}
} ,
{
field : 'resourcesInfoType' , width : 150 , title : '资源类型' , align : "center" , templet : function ( d ) { //(1视频 2课件 3附件)
return d . resourcesInfoType == 1 ? "视频" : d . resourcesInfoType == 2 ? "课件" : d . resourcesInfoType == 3 ? "附件" : '-' ;
} ,
{
field : 'unfinishedYD' , width : 150 , title : '上传院校' , align : "center"
} ,
{
field : 'resourcesInfoType' , width : 150 , title : '资源类型' , align : "center" , templet : function ( d ) { //(1视频 2课件 3附件)
var text = d . resourcesInfoType == 1 ? "视频" : d . resourcesInfoType == 2 ? "课件" : d . resourcesInfoType == 3 ? "附件" : '-' ;
return '<span class="textType">' + text + '</span>' ;
}
} ,
{
field : 'userId' , title : '操作' , width : 180 , align : "center" , templet : function ( d ) {
var htm = '<a class="layui-table-link" lay-event="edit">编辑</a>' ;
htm += '<a class="layui-table-link" lay-event="previewPage">' + ( d . resourcesInfoType == 3 ? '下载' : '预览' ) + '</a>' ;
htm += '<a class="layui-table-link" lay-event="del">删除</a>' ;
return htm ;
}
}
} ,
{
field : 'userId' , title : '操作' , width : 180 , align : "center" , templet : function ( d ) {
var htm = '<button type="button" class="layui-btn layui-btn-xs" lay-event="edit">编辑</button></a>' ;
htm += '<button type="button" class="layui-btn layui-btn-xs" lay-event="previewPage">' + ( d . resourcesInfoType == 3 ? '下载' : '预览' ) + '</button></a>' ;
htm += '<button type="button" class="layui-btn layui-btn-xs" lay-event="del">删除</button></a>' ;
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 ) ;
} ) ;
}
] ] , 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 ) {
table . on ( 'checkbox(resourcesInfoTable)' , function ( obj ) {
var resourcesInfo = obj . data ;
if ( obj . checked ) {
if ( obj . checked ) {
//按钮逻辑Lib.buttonEnable()
} else {
} else {
}
} )
} ,
initSearchForm : function ( ) {
Lib . initSearchForm ( $ ( "#searchForm" ) , resourcesInfoTable , form ) ;
initSearchForm : function ( ) {
Lib . initSearchForm ( $ ( "#searchForm" ) , resourcesInfoTable , form ) ;
} ,
initToolBar : function ( ) {
initToolBar : function ( ) {
toolbar = {
add : function ( ) { // 获取选中数据
add : function ( ) { // 获取选中数据
var url = "/jlw/resourcesInfo/add.do" ;
Common . openDlg ( url , "资源管理/新增资源" ) ;
Common . openDlg ( url , "资源管理/新增资源" ) ;
} ,
refresh : function ( ) { //刷新
searchForm . reset ( ) ;
Lib . doSearchForm ( $ ( "#searchForm" ) , resourcesInfoTable , 1 ) ;
} ,
search : function ( ) {
search : function ( ) {
Lib . doSearchForm ( $ ( "#searchForm" ) , resourcesInfoTable , 1 ) ;
} ,
allDel : function ( ) { //批量删除
allDel : function ( ) { //批量删除
var checkStatus = table . checkStatus ( 'resourcesInfoTable' )
, data = checkStatus . data , ids = "" ;
for ( var i = 0 ; i < data . length ; i ++ ) {
, data = checkStatus . data , ids = "" ;
for ( var i = 0 ; i < data . length ; i ++ ) {
ids += data [ i ] . resourcesInfoId ;
if ( i < data . length - 1 ) {
if ( i < data . length - 1 ) {
ids += "," ;
}
}
if ( $ . isEmpty ( ids ) ) {
if ( $ . isEmpty ( ids ) ) {
layer . msg ( "请选择需要删除的数据!" , {
offset : [ '50%' ] ,
icon : 2 ,
@ -163,16 +178,16 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
}
deleteInfo ( ids ) ;
} ,
bindingCourseInfo : function ( ) { //批量绑定课程
bindingCourseInfo : function ( ) { //批量绑定课程
var checkStatus = table . checkStatus ( 'resourcesInfoTable' )
, data = checkStatus . data , ids = "" ;
for ( var i = 0 ; i < data . length ; i ++ ) {
, data = checkStatus . data , ids = "" ;
for ( var i = 0 ; i < data . length ; i ++ ) {
ids += data [ i ] . resourcesInfoId ;
if ( i < data . length - 1 ) {
if ( i < data . length - 1 ) {
ids += "," ;
}
}
if ( $ . isEmpty ( ids ) ) {
if ( $ . isEmpty ( ids ) ) {
layer . msg ( "请选择需要绑定章节的数据!" , {
offset : [ '50%' ] ,
icon : 2 ,
@ -182,25 +197,25 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
}
bindingCourseInfo ( ids ) ;
}
} ;
$ ( '.ext-toolbar' ) . on ( 'click' , function ( ) {
} ;
$ ( '.ext-toolbar' ) . on ( 'click' , function ( ) {
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' ) {
var url = "/jlw/resourcesInfo/add.do?resourcesInfoId=" + data . resourcesInfoId ;
Common . openDlg ( url , "资源管理/编辑资源" ) ;
} else if ( obj . event === "del" ) {
var url = "/jlw/resourcesInfo/add.do?resourcesInfoId=" + data . resourcesInfoId ;
Common . openDlg ( url , "资源管理/编辑资源" ) ;
} else if ( obj . event === "del" ) {
deleteInfo ( data . resourcesInfoId ) ;
} else if ( obj . event === "previewPage" ) {
} else if ( obj . event === "previewPage" ) {
Lib . downloadFile ( data ) ;
}
} )
}
function deleteInfo ( ids ) {
function deleteInfo ( ids ) {
layer . confirm ( '是否确定删除数据?' , function ( index ) {
var ret = Common . postAjax ( "/jlw/resourcesInfo/delete.json" , { ids : ids } ) ;
layer . msg ( ret . code == 0 ? "删除成功!" : ret . msg , {
@ -216,7 +231,7 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
}
//批量绑定章节
function bindingCourseInfo ( ids ) {
function bindingCourseInfo ( ids ) {
layer . open ( {
type : 1 ,
title : "批量绑定章节" ,
@ -227,15 +242,18 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
content : $ ( "#bindingCourseInfo_dialog" ) ,
success : function ( layero , index ) {
$ ( "#bindingCourseInfo_dialog select" ) . val ( "" ) ;
$ ( "#bindingCourseInfo_dialog .layui-input-inline" ) . css ( "width" , "400px" ) ;
$ ( "#bindingCourseInfo_dialog .layui-input-inline" ) . css ( "width" , "400px" ) ;
form . render ( ) ;
} , yes : function ( index ) {
var courseInfoId = $ ( "#bindingCourseInfo_dialog select[name='courseInfoId']" ) . val ( ) ;
if ( $ . isEmpty ( courseInfoId ) ) {
if ( $ . isEmpty ( courseInfoId ) ) {
layer . msg ( "请选择归属小结!" ) ;
return ;
return ;
}
var ret = Common . postAjax ( "/jlw/resourcesInfo/setCourseInfoId.json" , { courseInfoId : courseInfoId , resourcesInfoIds : ids } ) ;
var ret = Common . postAjax ( "/jlw/resourcesInfo/setCourseInfoId.json" , {
courseInfoId : courseInfoId ,
resourcesInfoIds : ids
} ) ;
layer . msg ( ret . code == 0 ? "绑定成功!" : ret . msg , {
offset : [ '50%' ] ,
icon : ret . code == 0 ? 1 : 2 ,
@ -252,6 +270,15 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
} ) ;
}
//选择归属课程 并且根据选择的课程查询章节 resourcesQuestionIdsIsNotNull:查询题目不为空的章节
form . on ( 'select(select_courseInfoIds_)' , function ( obj ) {
Lib . getCourseInfo ( $ ( "select[name='courseInfoId_2']" ) , obj . value , 1 ) ;
} ) ;
//选择归属课程 并且根据选择的课程查询章节
form . on ( 'select(select_courseInfoIds_Node)' , function ( obj ) {
Lib . getCourseInfo ( $ ( "select[name='courseInfoId_3']" ) , obj . value ) ;
} ) ;
//选择归属课程 并且根据选择的课程查询章节
form . on ( 'select(select_courseId)' , function ( obj ) {
var this _ = $ ( "#bindingCourseInfo_dialog select[name='chapterId']" ) ;
@ -260,8 +287,8 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
this _ . append ( "<option value=''>请选择</option>" ) ;
this _1 . empty ( ) ;
this _1 . append ( "<option value=''>请选择</option>" ) ;
if ( ! $ . isEmpty ( obj . value ) ) {
$ . each ( courseInfoMap [ obj . value ] . children , function ( key , v ) {
if ( ! $ . isEmpty ( obj . value ) ) {
$ . each ( courseInfoMap [ obj . value ] . children , function ( key , v ) {
this _ . append ( "<option value='" + v . courseInfoId + "'>" + v . courseInfoName + "</option>" ) ;
} ) ;
}
@ -273,8 +300,8 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
var this _ = $ ( "#bindingCourseInfo_dialog select[name='courseInfoId']" ) ;
this _ . empty ( ) ;
this _ . append ( "<option value=''>请选择</option>" ) ;
if ( ! $ . isEmpty ( obj . value ) ) {
$ . each ( zjMap [ obj . value ] . children , function ( key , v ) {
if ( ! $ . isEmpty ( obj . value ) ) {
$ . each ( zjMap [ obj . value ] . children , function ( key , v ) {
this _ . append ( "<option value='" + v . courseInfoId + "'>" + v . courseInfoName + "</option>" ) ;
} ) ;
}
@ -289,8 +316,8 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
$ ( this ) . parents ( "td" ) . next ( ) . next ( ) . find ( "select" ) . empty ( ) ;
$ ( this ) . parents ( "td" ) . next ( ) . next ( ) . find ( "select" ) . append ( "<option value=''>请选择</option>" ) ;
if ( ! $ . isEmpty ( obj . value ) ) {
$ . each ( courseInfoMap [ obj . value ] . children , function ( key , v ) {
if ( ! $ . isEmpty ( obj . value ) ) {
$ . each ( courseInfoMap [ obj . value ] . children , function ( key , v ) {
this _ . append ( "<option value='" + v . courseInfoId + "'>" + v . courseInfoName + "</option>" ) ;
} ) ;
}
@ -302,8 +329,8 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
var this _ = $ ( this ) . parents ( "td" ) . next ( ) . find ( "select" ) ;
this _ . empty ( ) ;
this _ . append ( "<option value=''>请选择</option>" ) ;
if ( ! $ . isEmpty ( obj . value ) ) {
$ . each ( zjMap [ obj . value ] . children , function ( key , v ) {
if ( ! $ . isEmpty ( obj . value ) ) {
$ . each ( zjMap [ obj . value ] . children , function ( key , v ) {
this _ . append ( "<option value='" + v . courseInfoId + "'>" + v . courseInfoName + "</option>" ) ;
} ) ;
}
@ -312,11 +339,14 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
//选择归属课程 并且根据选择的课程查询章节
form . on ( 'select(select_courseInfoIds_2)' , function ( obj ) {
var r = $ ( this ) . parents ( "td" ) . find ( "input" ) . context . innerHTML . replace ( / /g , "" ) ;
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 } ) ;
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 ,
@ -325,6 +355,6 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
}
} ) ;
exports ( 'index' , view ) ;
exports ( 'index' , view ) ;
} ) ;