layui.define(['layer','table','vciWebComboxStore'],function(exports){ /** * 数据表格--使用平台里的表单定义 * weidy@2018-03-08 */ var VciDataGrid = function(){ this.table = null; this.tableDefinedUrl='webUIController/getTableDefine';//默认的地址 this.elemTableMap = {};//table元素绑定的表格主键 this.elemFilterMap = {};//元素和filter映射 this.tableConfigData = {};//从后台获取的的表格配置内容 this.selectMode = null; }; VciDataGrid.prototype.init = function(){ var that = this; that.table = layui.table; if(that.selectMode == null){ that.selectMode = that.table.selectMode.single; } }; VciDataGrid.prototype.showGridByUrl = function(filter){//从后台获取表格信息 var that = this; var config = that.getConfig(filter); var tableConfigData; var requestData = {}; if(!config.extraParams && config.where){ config.extraParams = config.where; } if(config.extraParams){ for(var key in config.extraParams){ requestData["conditionMap['" + key + "']"] = config.extraParams[key]; } } var copyParam = ['btmType','tableCode'];//btmtype,表格所属类别-可以是业务类型,也可以链接类型,tableCode是表格的英文名称 for(var i= 0 ; i < copyParam.length ; i ++){ requestData[copyParam[i]] = config[copyParam[i]]; } requestData['isMuti'] = $webUtil.getBoolean(config.isMuti); if(config && config.isLoaded && config.tableId == that.elemTableMap[config.elemId]){ //说明加载过,而且该内容还在原处 that.table.reload(config.tableId,{}); }else{ if(config.tableId != that.elemTableMap[config.elemId]){ that.destroy(that.elemFilterMap[config.elemId]);//如果这个元素被其他的表格占用,则将原表格去掉 } if($webUtil.isNotNull(config.tableCode) && $webUtil.isNotNull(config.btmType) && that.tableConfigData[config.tableCode + "_" + config.btmType]){ //说明这个配置信息已经从后台获取过 //可以定义表格了 var tableConfigData = that.tableConfigData[config.tableCode + "_" + config.btmType] ; tableConfigData['filter'] = filter; tableConfigData['elem'] = config.elemId; tableConfigData['id'] = config.tableId; tableConfigData['url'] = ((config.url.indexOf('http:') == -1)?path +config.url : config.url); tableConfigData['height'] = config.height ? config.height : 475; tableConfigData['where'] = requestData; if($webUtil.getBoolean(config.isMuti) && "page" in tableConfigData){ delete tableConfigData.page; // tableConfigData['page'] = { // limit: -1, // page: 1 // } } tableConfigData['done'] = function(res,cur,count){ if(config.done){ config.done(res,cur,count); } }; that.table.render(tableConfigData); that.elemTableMap[config.elemId] = config.tableId; that.elemFilterMap[config.elemId] = filter; config.isLoaded = true; that.setConfig(filter,config); }else{ if($webUtil.isNotNull(config.tableCode) && $webUtil.isNotNull(config.btmType)) { //说明是使用平台的表格 $webUtil.post($webUtil.isNotNull(config.tableDefinedUrl)?config.tableDefinedUrl:that.tableDefinedUrl, requestData, function (result) { if (result.success) { var queryScheme = result.querySchema; if ($webUtil.isNotNull(queryScheme) && $webUtil.isNull(config.queryScheme)) { config.queryScheme = queryScheme; } requestData['queryScheme'] = config.queryScheme; requestData['btmType'] = config.btmType; var cols = []; if (result.showIndex) { cols.push({field: 'LAY_TABLE_INDEX', type: 'numbers', title: '序号'}); } if (result.showCheckbox) { cols.push({field: 'LAY_CHECKED', type: 'checkbox'}); } var referColumn = ""; if (result.columns) { layui.each(result.columns, function (_index, record) { var col = record; if (col.field.indexOf(".") > -1) { referColumn += col.field + ","; var tempField = col.field; if(tempField.indexOf(".")>-1){ tempField = tempField.substring(tempField.indexOf(".") + 1); } col.field = col.field.replace(".", "_"); col.templet = function(d){ return d[tempField]; } } if ($webUtil.isNotNull(col.enumCode)) { //是枚举的内容 var vciWebComboxStore = layui.vciWebComboxStore; vciWebComboxStore.newCombox(col.enumCode, { data: col.enumMap }); col.templet = function (d, thisItem) { var vciWebComboxStore = layui.vciWebComboxStore; return vciWebComboxStore.getComboxText(thisItem.enumCode, d[thisItem.field]); }; } cols.push(col); }); } requestData['referColumn'] = referColumn; var pageObject = false; if (result.limit > 0) { pageObject = { limit: result.limit, page: 1 }; } //可以定义表格了 tableConfigData = { filter: filter, elem: config.elemId, id: config.tableId, oid: config.old,//主键的字段,默认为oid url: config.url, page: pageObject, selectMode:that.selectMode, where: requestData, done: function (res, cur, count) { if (config.done) { config.done(res, cur, count); } }, cols: [cols] }; if(config.height){ tableConfigData.height = config.height; } that.table.render(tableConfigData); that.tableConfigData[config.tableCode + "_" + config.btmType] = tableConfigData; that.elemTableMap[config.elemId] = config.tableId; that.elemFilterMap[config.elemId] = filter; config.isLoaded = true; that.setConfig(filter, config); } else { $webUtil.showErrorMsg(result.msg); } }); } } } }; VciDataGrid.prototype.setConfig=function(filter,options){ var that = this; if(!that.vciGridConfig){ that.vciGridConfig = {}; } that.vciGridConfig[filter] = options; }; VciDataGrid.prototype.getConfig=function(filter){ var that = this; if(!that.vciGridConfig){ that.vciGridConfig = {}; } if((filter) in that.vciGridConfig){ return that.vciGridConfig[filter]; } }; VciDataGrid.prototype.doResize = function(filter){ }; VciDataGrid.prototype.destroy = function(filter){ //销毁 var that = this; var config = that.getConfig(filter); if(!config){ return; } if(config && $(config.elemId)){ $(config.elemId).remove(); } if(!that.vciGridConfig){ that.vciGridConfig = {}; } if(that.elemFilterMap[config.elemId]){ delete that.elemFilterMap[config.elemId]; } if(that.elemTableMap[config.elemId]){ delete that.elemTableMap[config.elemId]; } if(that.tableConfigData[config.tableCode + "_" + config.btmType]){ delete that.tableConfigData[config.tableCode + "_" + config.btmType]; } if((filter) in that.vciGridConfig){ delete that.vciGridConfig[filter]; } }; var dg = new VciDataGrid(); exports('vciWebDataGrid',dg); });