layui.define(['layer'],function(exports){
/**
* 参照的默认列表框
* wangting@2022-1-21
*/
var ReferGrid = function(){
this.defaultConfig = {
gridUrl:'/webReferController/referDataGrid',//表格的参照路径
tableDefinedUrl:'/webReferController/getTableDefine',
valueField:'oid',//值的字段
textField:'name'//显示的字段
};
this.backPath= configData.compatibility ? path : configData.objectServicePath
};
ReferGrid.prototype.init = function(){
};
ReferGrid.prototype.showReferDialog = function (referConfig){
var filter = referConfig.filter,
name = referConfig.name,
title = referConfig.title,
valueInfo = ($webUtil.isNotNull(referConfig.text)?("已设置的值为[" +referConfig.text +"]"):'未设置值'),
isMuti = referConfig.isMuti,
target = referConfig.target,
value = referConfig.value,
text = referConfig.text;
if(filter.indexOf('.')>-1){
filter=filter.split('.')[0]+'-'+filter.split('.')[1];
}
if(name.indexOf('.')>-1){
name=name.split('.')[0]+'-'+name.split('.')[1];
}
var options = referConfig.options;
var me = this;
var referFilter = filter+"_" + name;
var referIndex = $webUtil.dialog({
title:title,
btn:['确定','取消'],
content:'
',
area:[(($webUtil.isNotNull(options.width) && options.width*1>1) ?options.width*1 : 720) +'px',
(($webUtil.isNotNull(options.height) && options.height*1>1) ?options.height*1 : 625) + 'px'],
btnBefore:valueInfo,
resizing:function(layero){
me.doResize(filter,name);
},
yes:function(index,layero){
var selectValue = me.getSelectValue(filter,name,isMuti);
if(selectValue){
target.setValue(filter,name,selectValue.value,selectValue.rawValue,true,selectValue.allValues);
layer.close(referIndex);
}
},
success:function(layero){
me.showGrid(filter,name,options,value,text);
}
});
};
//显示
ReferGrid.prototype.showGrid=function(filter,name,options,value,rawValue){
var that = this;
that.setConfig(filter,name,options);
if($('#referGrid_' + filter + '_' + name).children().length>0){
$('#referGrid_' + filter + '_' + name).show();
}else{
var tableId = 'referGrid_' + filter + '_' + name;
layui.use('table',function(){//因为table里引用了form ,form里引用了这里
var table = layui.table;
var isMuti = $webUtil.getBoolean($webUtil.getValueFromObj(options,['isMuti'],false));
var requestData = {};
if(options.extraParams ){
for(var key in options.extraParams){
requestData[key] = options.extraParams[key];
}
}
if(options.useFormKey && options.formValues){
//使用表单上的字段来过滤
requestData['conditionMap["' + (options.paramForFormKey?options.paramForFormKey:options.useFormKey) + '"]'] = options.formValues[options.useFormKey];
}
if(options.where ){
for(var key in options.where){
requestData['conditionMap["' + key + '"]'] = options.where[key];
}
}
var copyParam = ['referField','referBo','textField','valueField','displayTable','whereSql','isMuti','queryScheme'];
for(var i= 0 ; i < copyParam.length ; i ++){
requestData[copyParam[i]] = options[copyParam[i]];
}
if(!requestData['referBo']){
requestData['referBo'] = options.referType;
}
if(options.tableConfig && options.tableConfig.cols && options.tableConfig.cols.length>0){
//说明传递了的
var hasIndex = false;
var hasCheck = false;
layui.each(options.tableConfig.cols,function (_index,_item){
if(_item.field == layui.table.config.indexName){
hasIndex = true;
}
if(_item.field == layui.table.config.checkName){
hasCheck = true;
}
});
if(!hasIndex){
options.tableConfig.cols.unshift(layui.table.getIndexColumn());
}
if(!hasCheck){
options.tableConfig.cols.unshift(layui.table.getCheckColumn());
}
}
//说明是自定义的表格
var tableConfig = options.tableConfig||{
page: {
limit: 15,
page: 1
},
cols: [layui.table.getIndexColumn(), layui.table.getCheckColumn(), {
field: 'id',
title: '英文名称',
sort:true,
width: 150
}, {
field: 'name',
title: '中文名称',
sort:true,
width: 150
},{
field: 'description',
title: '描述',
width: 250
},{
field:'secretGradeText',
title:'密级',
width: 60,
hidden:(!configData.controllerSecret)
}],
queryColumns: [
{
field: 'id',
title: '英文名称'
}, {
field: 'name',
title: '中文名称'
}
]
};
//可以定义表格了
table.render({
elem:'#referGrid_' + filter + '_' + name,
id:tableId,
backPath: options.backPath?options.backPath:that.backPath,
url:'uiDataController/defaultReferDataGrid',
page:tableConfig.page,
height:options.height?options.height:475,
where:requestData,
method:options.method,
selectMode:isMuti?table.selectMode.muti:table.selectMode.single,
cols:[tableConfig.cols],
initSort:options.initSort,
remoteSort:options.remoteSort
});
that.showSearchHtml(tableConfig.queryColumns,tableId,filter,name,requestData);
});
}
};
ReferGrid.prototype.showSearchHtml =function(queryColumns,tableId,filter,name,requestData){
//设置查询区域
var that = this;
var table = layui.table;
var toolbarElem = $('[layui-filter="referGrid_toolbar_' + filter + '_' + name +'"]');
if(queryColumns){
var toolbarHtml = '';
toolbarElem.html(toolbarHtml);
layui.form.render('select');
$('[name="referGrid_searchbtn_'+ filter + '_' + name +'"]').click(function(){
var searchField = $(this).parent().parent().find('select').val();
var searchValue = $(this).parent().parent().find('[name="referGrid_searchvalue_' + filter + '_' + name + '"]').val();
that.queryByCondition(tableId,requestData,searchField,searchValue);
});
$('[name="referGrid_searchvalue_'+ filter + '_' + name +'"]').keydown(function(e){
if(e.keyCode == 13) {
var searchField = $(this).parent().parent().find('select').val();
var searchValue = $(this).val();
that.queryByCondition(tableId, requestData, searchField,searchValue);
}
});
$('[name="referGrid_searchvalue_'+ filter + '_' + name +'"]').focus()
}
};
ReferGrid.prototype.queryByCondition = function(tableId,requestData,searchField,searchValue){
if($webUtil.isNotNull(searchValue)){
searchValue = "*" + searchValue + "*";
}
requestData['conditionMap["' + searchField + '"]'] = searchValue;
requestData['page']= 1;
var table = layui.table;
table.reload(
tableId, {
where: requestData
}
);
}
ReferGrid.prototype.setConfig=function(filter,name,options){
var that = this;
if(!that.referConfig){
that.referConfig = {};
}
that.referConfig[filter + "_" + name] = options;
};
ReferGrid.prototype.getConfig=function(filter,name){
var that = this;
if(!that.referConfig){
that.referConfig = {};
}
if((filter + "_" + name) in that.referConfig){
return that.referConfig[filter + "_" + name];
}
};
ReferGrid.prototype.getSelectValue = function(filter,name,isMuti){
var that = this;
var table = layui.table;
var config = that.getConfig(filter,name);
var selectValue = {};
var checkStatus = table.checkStatus('referGrid_' + filter + "_" + name);
if(checkStatus.data.length>0){
if(!isMuti && checkStatus.data.length>1){
$webUtil.showErrorMsg("每次只能选择一条数据");
return false;
}
var value = "";
var rawValue = "";
config.valueField = config.valueField?config.valueField:that.defaultConfig.valueField;
config.textField = config.textField?config.textField:that.defaultConfig.textField;
var isMutiValue = (config.valueField.indexOf(",")>-1);
var isMutiRaw = (config.textField.indexOf(",")>-1);
layui.each(checkStatus.data,function(_index,item){
if(isMutiValue){
var valueFieldArray = config.valueField.split(",");
layui.each(valueFieldArray,function(_indexField,_itemField){
value += item[_itemField] + (config.valueSep?config.valueSep:' ');
});
value+= ",";
}else {
value += item[config.valueField] + ",";
}
if(isMutiRaw) {
var rawFieldArray = config.textField.split(",");
layui.each(rawFieldArray,function(_indexField,_itemField){
rawValue += item[_itemField] + (config.textSep?config.textSep:' ');
});
rawValue+= ",";
}else{
rawValue += item[config.textField] + ",";
}
});
if($webUtil.endWith(value,",")){
value = value.substring(0,value.length - 1);
}
if($webUtil.endWith(rawValue,",")){
rawValue = rawValue.substring(0,rawValue.length -1);
}
selectValue = {
value : value,
rawValue : rawValue,
allValues: checkStatus.data
};
return selectValue;
}else{
return false;
}
};
ReferGrid.prototype.doResize = function(filter,name){
};
ReferGrid.prototype.destory = function(filter,name){
//销毁
var that = this;
if($('#referGrid_' + filter + '_' + name)){
$('#referGrid_' + filter + '_' + name).remove();
}
if(!that.referConfig){
that.referConfig = {};
}
if((filter + "_" + name) in that.referConfig){
delete that.referConfig[filter + "_" + name];
}
};
var rg = new ReferGrid();
exports('vciWebReferDefalut',rg);
});