/** * ${comments}页面 * @author ${author} * @date ${datetime} */ layui.define(['layer','element','form','table','dynamicCondition'#if(${hasExcel}),'upload'#end #if(${hasParentField}),'tree'#end],function(exports){ #set($util = "$webUtil") #set($cookie = "$.cookie") #set($status = "${lcstatus}") var webUtil = $util; var Class = function(){ this.MODELNAME = "${jsPackage}"; this.moduleKey = "${className}"; this.backPath = ${backPath}; this.url = { controller:'${controllerUrl}', #if(!${hasParentField}) dataGrid:'grid${className}', #else tree:'tree${className}', #end addSave:'addSave', editSave:'editSave', #if(${hasParentField}) checkIsCanDelete:'checkIsCanDelete', referTree:'referTree' , #end deleteUrl:'deleteData', #if(${hasEnable}) enableData: 'enableData', disableData: 'disableData', #end getObjectByOid:'getObjectByOid' }; this.getContent=function(){ var that = this; return '
'; }; this.showContent=function (){ var that = this; var html = ""; html = [ '
', #if(${useWest}) '
', that.getWestToolbarHtml(), #if(${westLayoutPanelType} == "tree") '
', '', '
      ', '
', #end '
', #end '
', '
', that.getToolbarHtml(), #if(${centerLayoutPanelType} == "table") '
', #end #if(${centerLayoutPanelType} == "table_tree") '
', #end #if(${centerLayoutPanelType} == "form") '
', #end '
', '
', '
' ].join(""); $("#UIContent_"+that.id).html(html); }; #if(${useWest}) this.getWestToolbarHtml = function(){ var that = this; var html = [ '
', #if($westButtons.size()>0) #foreach($button in $westButtons) '', #end #end '
' ].join(""); return html; }; this.createWestSearchHtml = function () { var that = this; #if($westQuerys != "") webUtil.createSearchHtml($westQuerys,$("[layui-filter='toolbar_west_" + that.id + "']"),'west_' + that.id); webUtil.bindDefultButtonLisenter(that,"west_" + that.id); #end }; #end this.getToolbarHtml =function(){ var that = this; var html = [ '
', #if($centerButtons.size()>0) #foreach($button in $centerButtons) '', #end #end '
' ].join(""); return html; }; this.createSearchHtml = function () { var that = this; webUtil.bindDefultButtonLisenter(that, that.id); #if($centerQuerys !="") webUtil.createSearchHtml($centerQuerys ,$("[layui-filter='toolbar_" + that.id + "']"), "table_" + that.id); #end }; this.defaultAttrList = [ #foreach($attr in $uiAttributes) '$attr.id', #end '' ]; this.init = function(){ var that = this; webUtil.copyConfig(that,that.moduleKey); //需要加在定时中,否则样式不能正确展示,不知道原因 wangting setTimeout(function (){ that.showContent(); var easyuiLayout= $('#easyuiLayout_'+that.id) easyuiLayout.css({height:$('#portal_body').height()-43,width:$('#portal_body').width()-15}) easyuiLayout.layout(); #if(${useWest}) #if(${westLayoutPanelType} == "tree") that.initTree(); that.createWestSearchHtml(); #end #end #if(${centerLayoutPanelType} == "table") that.initMainTable(); #end #if(${centerLayoutPanelType} == "table_tree") that.initMainTable(${parentFieldName}); #end #if(${centerLayoutPanelType} == "form") that.initForm(); #end that.createSearchHtml(); },1) }; this.initMainTable = function (parentFieldName) { var that = this; var table = layui.table; that.checkColumns(); var tableWidth = $("#border_" + that.id).width(); var options = { elem: '#table_' + that.id, id: 'table_' + that.id, backPath:that.backPath, url: that.url.controller + that.url.dataGrid, page: { limit: 20, page: 1 }, width:tableWidth, selectMode:table.selectMode.muti, cols: [that.columns], method:'get', done:function(res,cur,total){ if(!that.fristMainLoad ){ table.on('tool(' + that.id + ')',function(obj){ var data = obj.data;//当前选择行的数据 var layEvent = obj.event;//点的是什么按钮 if(layEvent == 'EDIT'){ that.addOrEdit(false,data.oid); } }); }else{ if(total>0) { table.selectRecord('table_' + that.id, {index:0}); } } that.fristMainLoad = true; } }; if(parentFieldName){ options.treeConfig = { treepid:parentFieldName, treeid:'id', showField:'name' }; } table.render(options); }; this.checkColumns = function(){ var that = this; var table = layui.table; if(that.columns==null || that.columns.length==0){ that.columns = [table.getIndexColumn(),table.getCheckColumn(), #foreach($attr in $uiAttributes) { title: '$attr.name', #if($attr.vciAttrDataType == "VTString") #if($attr.referFlag) field: '$attr.referBtmTypeShowField', sort:true, sortField:'$attr.id', type:'refer', referConfig: { type:'default', referBo:'$attr.referBtmTypeId' }, width: 150 #else #if($attr.enumFlag) field: '$attr.enumShowField', sort:true, sortField:'$attr.id', type:'combox', comboxKey:"$attr.enumId", width: 150 #else #if($attr.id == "lcstatus") field: 'lcStatusText', sortField:'lcStatus', type:'combox', comboxKey:"${btmTypeIdLow}_$status", width:150 #elseif($attr.id == 'secretgrade') field: 'secretGradeText', width:60, type:'combox', comboxKey:"myDataSecret", hidden:configData.controllerSecret #else field: '$attr.id', sort:true, width: 150 #end #end #end #elseif($attr.vciAttrDataType == "VTLong") field: '$attr.id', type:'number', width: 100 #elseif($attr.vciAttrDataType == "VTInteger") field: '$attr.id', type:'number', width: 100 #elseif($attr.vciAttrDataType == "VTDouble") field: '$attr.id', type:'number', width: 100 #elseif($attr.vciAttrDataType == "VTDate") field: '$attr.id', width: 110, type:'date', templet: function (d) { return webUtil.formateDate(d.$attr.id); } #elseif($attr.vciAttrDataType == "VTDateTime") field: '$attr.id', width: 130, type:'datetime', templet: function (d) { return webUtil.formateDateTimeNoSecond(d.$attr.id); } #elseif($attr.vciAttrDataType == "VTBoolean") field: '$attr.id', width: 60, type:'combox', data:[{key:"true",value:"是"},{key:"false",value:"否"}], templet: function (d) { return webUtil.formateBoolean(d.$attr.id); } #end }, #end { field:'options', title:'操作', width:150, templet:function(d){ return '编辑'; } }]; } }; #if(${useWest}) #if(${westLayoutPanelType} == "tree") this.initTree = function () { var that = this; var tree = layui.tree; var treeUL = $('[layui-filter="tree_' + that.id + '"]'); var scrollHeight = treeUL.closest('.panel-body').height(); var treeHeight = scrollHeight - 100; treeUL.parent().height(treeHeight); tree.init("tree_" + that.id, treeUL, { url: that.url.controller + that.url.tree, backPath: that.backPath, extraParams: { isMuti: false, isQueryAllColumn: true }, showSearch:true, click: function (item, elem, options) { that.currentItemOid = item.oid; that.currentItemAttributes = item.attributes; #if(${centerLayoutPanelType} == "table") layui.table.reload('table_' + that.id,{ extraParams:{ "${westNextRegionParam}":that.currentItemAttributes.oid } }); #elseif(${centerLayoutPanelType} == "table_tree") layui.table.reload('table_' + that.id,{ extraParams: { "${westNextRegionParam}": that.currentItemAttributes.oid } }); #elseif(${centerLayoutPanelType} == "form") that.setFormValues(); #end } }); }; this.setFormValues = function () { var that = this; layui.form.load("form_info_" + that.id,{"oid":that.currentItemAttributes.oid}); }; #end #end this.getFormItems = function(onlyShow) { var that = this; var table = layui.table; return [ #foreach($attr in $uiAttributes) { field: '$attr.id', title: '$attr.name', #if($attr.nullable == "false") required: true, #end #if($attr.vciAttrDataType == "VTString") #if($attr.referFlag) type: 'refer', showField: '$attr.referBtmTypeShowField', referConfig: { type:'default', referBo:'$attr.referBtmTypeId' }, #else #if($attr.enumFlag) type: 'combox', comboxKey: '$attr.enumId', #else type: 'text', #end #end #end #if($attr.vciAttrDataType == "VTLong" || $attr.vciAttrDataType == "VTInteger" || $attr.vciAttrDataType == "VTDouble") verify: 'number', #elseif($attr.vciAttrDataType == "VTDate") type: 'date', #elseif($attr.vciAttrDataType == "VTDateTime") type: 'datetime', #elseif($attr.vciAttrDataType == "VTBoolean") type: 'truefalse', #end #if($attr.defaultValue) defaultValue:"$attr.defaultValue", #end readOnly:onlyShow } #if($foreach.hasNext),#end #end ]; }; #if(${centerLayoutPanelType} == "form") this.initForm = function () { var that = this; var form = layui.form; form.addItems("form_info_" + that.id, that.getFormItems(true), function () { }, {}, { defaultColumnOneRow: 2, labelWidth: 200 }); }; #end this.ADD = function () { var that = this; that.addOrEdit(true); }; this.EDIT = function(){ var that = this; #if(${hasParentField}) if(webUtil.isNull(that.currentItemOid)){ webUtil.showErrorMsg("请先从树上选择一条数据"); return false; } that.addOrEdit(false,that.currentItemOid); #else var oid = webUtil.getOidFromGrid("table_" + that.id,true,true); if(!oid){ return false; } that.addOrEdit(false,oid); #end }; this.addOrEdit = function(add,oid) { var that = this; var form = layui.form; var filter ="form_" + that.id; var addSaveIndex =webUtil.dialog({ title:add?'添加${comments}':'修改${comments}', btn:['保存','取消'], content:'
', resizing:function(layero){ form.doResize(filter); }, success:function(layero) { form.addItems(filter,that.getFormItems(false), function () { if(!add){ form.load(filter,{ backPath:that.backPath, url:that.url.controller + that.url.getObjectByOid, method:'get', params:{ oid:oid } }); }else{ var defaultValues = {}; #if(${hasParentField}) if(that.currentItemAttributes) { defaultValues["${parentFieldNameLow}"] = that.currentItemOid; defaultValues["${parentFieldNameLow}" + "name"] = that.currentItemAttributes.name; } #end //可以手动在此处添加默认值 form.setValues(defaultValues,filter); } }, {}, {defaultColumnOneRow: 2}); }, yes:function(layero){ if(form.validata(filter)){ var values = form.getValues(filter,true); var url = that.url.controller + (add?that.url.addSave:that.url.editSave); webUtil.manualAjax(add?'post':'put',url,JSON.stringify(values),function(result){ if(result.success){ webUtil.showMsgFromResult(result,(add ? "添加成功" : "修改成功")); layer.close(addSaveIndex); that.refresh(); }else{ webUtil.showErrorMsg(result.msg); } },function(xhr,err){ webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启"); },that.backPath); } }, btn2:function(layero){ layer.close(addSaveIndex); } }); }; this.DEL = function(){ var that = this; #if(${hasParentField}) if(webUtil.isNull(that.currentItemOid)){ webUtil.showErrorMsg("请先从树上的节点"); return false; } var ts = that.currentItemAttributes.ts; webUtil.showConfirmMsg("是否删除这条数据?如果被引用将不能被删除!",function () { var submitValue = {oid:that.currentItemOid,ts:ts}; webUtil.post(that.url.controller + that.url.checkIsDelete,submitValue,function(result){ if(result.success) { if ('true' == result.obj || true == result.obj) { webUtil.showConfirmMsg("当前数据包含有下级数据,要删除的话会和下级数据一起删除,你确认继续?", function () { that.doDelete(submitValue); }); } else { //说明可以删除 that.doDelete(submitValue); } }else { webUtil.showErrorMsg(result.msg); } },function (xhr,error) { webUtil.showErrorMsg("校验删除出现了错误,可能是服务器未启动") },that.backPath); }); #else var oid = webUtil.getOidFromGrid("table_" +that.id,true,true); if(!oid){ return false; } var ts= webUtil.getOidFromGrid("table_" +that.id,false,false,"ts"); webUtil.showConfirmMsg("是否删除这条数据?如果被引用将不能被删除!",function () { webUtil.deleteRequest(that.url.controller + that.url.deleteUrl,{oid:oid,ts:ts},function(result){ if(result.success){ webUtil.showMsgFromResult(result,"删除成功"); that.refresh(); }else{ webUtil.showErrorMsg(result.msg); } },function(xhr,err){ webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启"); },that.backPath); }); #end }; #if(${hasParentField}) this.doDelete = function (submitValue) { var that = this; webUtil.deleteRequest(that.url.controller + that.url.deleteUrl,submitValue,function(result){ if(result.success){ webUtil.showMsgFromResult(result,"删除成功"); that.refresh(); }else{ webUtil.showErrorMsg(result.msg); } },function (xhr,err) { webUtil.showErrorMsg("执行删除的时候出错了错误,可能是服务器暂时无法访问"); },that.backPath); }; #end this.refresh = function (#if(${hasParentField})buttonid,parentNodeOid#end) { var that = this; #if(${hasParentField}) var tree = layui.tree; if(webUtil.isNotNull(parentNodeOid)){ tree.reloadNode("tree_" + that.id,parentNodeOid); }else { tree.reload("tree_" + that.id); } #else layui.table.reload("table_" + that.id); #end }; #if(${hasEnable}) this.DISABLE = function () { var that = this; that.disableOrEnable(false); }; this.ENABLE = function () { var that = this; that.disableOrEnable(true); }; this.disableOrEnable = function (enable) { var that = this; var oid ; var ts ; #if(${hasParentField}) if(webUtil.isNull(that.currentItemOid)){ webUtil.showErrorMsg("请先从树上选择一条数据"); return false; } oid = that.currentItemOid; ts = that.currentItemAttributes.ts; #else oid = webUtil.getOidFromGrid("table_" + that.id,true,true); if(!oid){ return false; } ts = webUtil.getOidFromGrid("table_" + that.id,false,false,'ts'); #end webUtil.post(that.url.controller + (enable?that.url.enableData:that.url.disableData),{ oid:oid, ts:ts },function(result){ if(result.success){ webUtil.showMsgFromResult(result,(enable?'启用成功':'停用成功')); that.refresh(); }else{ webUtil.showErrorMsg(result.msg); } },function(xhr,err){ webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启"); },that.backPath); }; #end this.ADVQUERY = function () { var that = this; if(!that.serinorQueryInstance) { var dynamicCondition = layui.dynamicCondition; $('[layui-filter="toolbar_' + that.id + '"]').append('
'); that.checkColumns(); var dataFields = []; for(var i = 0 ; i < that.columns.length ; i ++){ dataFields[i] = that.columns[i]; } that.serinorQueryInstance = dynamicCondition.create({ fields: dataFields//查询字段 , tableId: "table_" + that.id//需要查询的表格 , type: "complex" //type:"simple"/"complex" 查询的方法 暂时写死为 complex , queryCallBack: function (requestData) {//查询之后的callback } }); } that.serinorQueryInstance.open(); }; }; var cs = new Class(); exports(cs.MODELNAME,cs); });