/**
|
* 主数据编码表单
|
* @author wangting
|
* @date 2022-4-12
|
*/
|
layui.define(['layer','element','form','table','dynamicCondition' ,'tree','transfer'],function(exports){
|
var webUtil = $webUtil;
|
var Class = function(){
|
this.MODELNAME = "mdm/MdmEngineForm";
|
this.moduleKey = "MdmEngineForm";
|
this.backPath = configData.compatibility? path:configData.mdmService;
|
this.url = {
|
classifyController: 'codeClassifyController/',
|
classifyTree:'referTree',
|
controller:'mdmEngineController/',
|
tableUI:'getUIInfoByClassifyOid',
|
formUI:'getFormDefineByTemplateOid',
|
tableData:'gridTableDataByClassifyOid',
|
getDataByOid:'getDataByOid'
|
};
|
this.config={}
|
this.getContent = function (){
|
var that = this;
|
return '<div id="UIContent_' + that.id + '" style="overflow: auto;padding:0 5px"></div>';
|
};
|
this.showContent=function(){
|
var html = "";
|
$("#UIContent_" + this.id).html(html);
|
};
|
this.init = function(){
|
var that = this;
|
webUtil.copyConfig(that,that.moduleKey);
|
this.config[that.id] = {
|
sourceData:that.sourceData
|
};
|
};
|
this.getFormDefine = function (codetemplateoid,codeClassifyOid,callback){
|
var that = this;
|
webUtil.get(that.url.controller + that.url.formUI,{templateOid: codetemplateoid,codeClassifyOid:codeClassifyOid},function (result){
|
if(!result.success) {
|
$webUtil.showErrorMsg(result.msg);
|
}else{
|
if(callback){
|
callback(result.obj);
|
}
|
}
|
});
|
};
|
this.getFormCol = function (formDefineVO,options) {
|
var screenWidth = webUtil.getDialogScreenWidth(options||{fullScreen:true});
|
var hasPrefix = false;
|
var hasSuffix = false;
|
layui.each(formDefineVO.items, function (_index, _item) {
|
if ($webUtil.isNotNull(_item.prefix)) {
|
hasPrefix = true;
|
}
|
if ($webUtil.isNotNull(_item.suffix)) {
|
hasSuffix = true;
|
}
|
});
|
var preWidth = 430;
|
if (hasPrefix) {
|
preWidth += 40;
|
}
|
if (hasSuffix) {
|
preWidth += 40;
|
}
|
//忘记form里面为啥要减去1了,不敢改
|
return (screenWidth - screenWidth % preWidth) / preWidth ;
|
};
|
this.getFormItemsByVO = function (formDefineVO,readOnly,colCount,add){
|
var that=this;
|
layui.each(formDefineVO.items, function (_index, _item) {
|
//因为表单上的字段上已经设置了readOnly,在默认上设置的readOnly不会生效,我们需要自行转换一下
|
if(_item.field == 'id' || _item.field == 'lcstatus'){
|
if(!add &&_item.field == 'id' && _item.hidden ){
|
_item.hidden= false;
|
}
|
_item.readOnly = true;
|
}else {
|
_item.readOnly = readOnly?readOnly:_item.readOnly;
|
if(_item.field=='lcstatus' && _item.readOnly){
|
_item.field='lcstatus_text';
|
_item.type='text';
|
}
|
}
|
_item.inputWidth = 250;
|
if(_item.type=="textarea"){
|
_item.useAllWidth=true;
|
_item.inputWidth = 415 * colCount - 160;
|
}
|
if(_item.type=="combox"){
|
_item.search = true;
|
}
|
if(webUtil.isNotNull(_item.selectLibFlag)) {
|
_item.type = 'combox';
|
_item.comboxTextField=_item.field;
|
_item.field= _item.comboxTextField+'Select';
|
_item.comboxKey = formDefineVO.oid+'_'+_item.field;
|
_item.editable = true;
|
_item.search = true;
|
_item.url = "bdSelectInputController/listByFlag";
|
_item.backPath = that.backPath;
|
_item.extraParams = {
|
namespace: formDefineVO.btmType,
|
flag: _item.field
|
}
|
}
|
});
|
return formDefineVO.items;
|
};
|
//码值表单项
|
this.getCodeValueItems=function (data,formfilter) {
|
var that=this;
|
var items = [];
|
layui.each(data, function (i, item) {
|
if(item.sectype=="codefixedsec"){
|
//固定码段
|
var fixedValueVOList=[];
|
layui.each(item.fixedValueVOList,function (valueIndex,valueItem){
|
fixedValueVOList.push({key:valueItem.id,value: valueItem.id})
|
})
|
items.push({
|
field: item.oid,
|
title: item.name,
|
required: item.nullableFlag!='true',
|
type: 'combox',
|
data:fixedValueVOList,
|
search:true
|
})
|
}else if(item.sectype=="codeclassifysec") {
|
//分类码段
|
var classifyitem = {
|
field: item.oid,
|
title: item.name,
|
required: item.nullableFlag != 'true',
|
type: 'refer',
|
showField: item.name,
|
readOnly:webUtil.isNull(item.parentClassifySecOid)?false:true,
|
parentClassifySecOid:item.parentClassifySecOid,
|
referConfig: {
|
backPath: that.backPath,
|
isMuti: false,
|
type: 'grid',
|
width: 680,
|
tableConfig: {
|
limit:-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
|
}],
|
queryColumns: [
|
{
|
field: 'id',
|
title: '英文名称'
|
}, {
|
field: 'name',
|
title: '中文名称'
|
}
|
]
|
},
|
url: that.url.controller + '/listCodeClassifyValueBySecOid',
|
extraParams: {
|
classifySecOid: item.oid,
|
parentClassifyValueOid: ''
|
}
|
}
|
}
|
items.push(classifyitem);
|
if(item.parentClassifySecOid){
|
layui.form.on('select('+formfilter+')',function (data){
|
if(data.name==item.parentClassifySecOid){
|
var parentClassifyValueOid=data.value;
|
var allItems=layui.form.getFormItems(formfilter);
|
var childItems=[];
|
layui.each(allItems,function (i,item){
|
if(item.parentClassifySecOid==data.name){
|
item.readOnly=false;
|
item.referConfig.extraParams.parentClassifyValueOid=parentClassifyValueOid
|
childItems.push(item)
|
}
|
})
|
layui.form.changeItems(formfilter,childItems)
|
}
|
})
|
}
|
|
}else if(item.sectype=="codevariablesec"){
|
//可变码段
|
items.push({
|
field: item.oid,
|
title: item.name,
|
required: item.nullableFlag!='true'
|
})
|
}else if(item.sectype=="coderefersec"){
|
//引用码段
|
var referConfig=JSON.parse(item.referValueInfo)
|
if(referConfig && referConfig.tableConfig && referConfig.tableConfig.cols.length>0){
|
referConfig.tableConfig.cols.unshift(layui.table.getIndexColumn(), layui.table.getCheckColumn());
|
layui.each(referConfig.tableConfig.cols,function (i,item){
|
if(item.templet!=''){
|
referConfig.tableConfig.cols[i].templet=eval("(" + item.templet + ")")
|
}
|
})
|
}
|
items.push({
|
field: item.oid,
|
title: item.name,
|
required: item.nullableFlag!='true',
|
type: 'refer',
|
showField: item.name,
|
referConfig: referConfig
|
})
|
}
|
})
|
return items;
|
}
|
|
//相似项
|
this.initResembleTable = function (componentVO,filter){
|
var that = this;
|
var table = layui.table;
|
if(componentVO.resembleTableVO && componentVO.resembleTableVO.cols && componentVO.resembleTableVO.cols.length>0){
|
//处理列表
|
var cols = [];
|
var eventMap = {};
|
for (var i = 0; i < componentVO.resembleTableVO.cols.length; i++) {
|
if (i == 0) {
|
componentVO.resembleTableVO.cols[i].unshift({
|
field: table.config.indexName,
|
type: 'numbers',
|
title: '序号',
|
rowspan: componentVO.resembleTableVO.cols.length,
|
width: 40
|
}, {
|
field: table.config.checkName,
|
type: 'checkbox',
|
rowspan: componentVO.resembleTableVO.cols.length,
|
width: 30
|
})
|
}
|
//每个字段都需要扫描一下是否有事件
|
for (var j = 0; j < componentVO.resembleTableVO.cols[i].length; j++) {
|
var record = componentVO.resembleTableVO.cols[i][j];
|
if(record.optionJsMap){
|
for(var key in record.optionJsMap){
|
eventMap[key] = record.optionJsMap[key];
|
}
|
}
|
if(record.field == 'id' && $webUtil.isNull(record.templet)){
|
//企业编码的默认添加超链接
|
record.templet = '<div><a name="code" href="javascript:;" dataIndex="{{d.LAY_INDEX}}" lay-event="VIEWDETAIL" data-oid="{{d.oid}}" data-template="{{d.codetemplateoid}}" style="text-decoration:underline;color:blue;" >{{d.id}}</a></div>';
|
}
|
}
|
|
cols.push(componentVO.resembleTableVO.cols[i]);
|
}
|
table.render({
|
elem: '#resemble_' + filter,
|
id: "resemble_" + filter,
|
data:[],
|
limits: -1,
|
selectMode: table.selectMode.muti,
|
cols: cols,
|
done: function (res, cur, total) {
|
table.on('tool(resemble_' + filter + ')', function (obj) {
|
var data = obj.data;//当前选择行的数据
|
var layEvent = obj.event;//点的是什么按钮
|
|
if (layEvent == 'VIEWDETAIL') {
|
that.VIEWDETAIL(data.oid,data.codetemplateoid);
|
} else {
|
if (layEvent in eventMap) {
|
that.callEvent(eventMap[layEvent], data);
|
}
|
}
|
});
|
}
|
});
|
}else{
|
layui.element.tabDelete("tab_" + filter, "resemble");
|
}
|
};
|
|
this.callEvent = function (jsPath,data){
|
var that = this;
|
if(jsPath && data){
|
if($webUtil.startWith(jsPath.toLowerCase(),"usejs:")||$webUtil.startWith(jsPath.toLowerCase(),"js:")){
|
//是执行js
|
if($webUtil.startWith(jsPath.toLowerCase(),"usejs:")){
|
jsPath = jsPath.substr(6);
|
}else {
|
jsPath = jsPath.substr(3);
|
}
|
layui.use(jsPath,function (){
|
layui[jsPath].doEvent(data,that);
|
});
|
}else if($webUtil.startWith(jsPath.toLowerCase(),"https://") || $webUtil.startWith(jsPath.toLowerCase(),"http://")){
|
var tabId = (data.oid || jsPath) + "_link";
|
portal.showTabByMenu(data.oid || jsPath,{
|
id:data.oid || jsPath,
|
text:'查看链接',
|
url:jsPath
|
});
|
}else if(that[jsPath]){
|
that[jsPath](data);
|
}else{
|
//直接是js的暂时还不支持
|
}
|
}
|
};
|
this.VIEWDETAIL = function (oid,codetemplateoid,codeClassifyOid){
|
//表单详情
|
var that = this;
|
if(!oid){
|
return false;
|
}
|
if(!codetemplateoid){
|
return false;
|
}
|
that.getFormDefine(codetemplateoid,codeClassifyOid,function (componentVO){
|
var formDefineVO= componentVO.formDefineVO;
|
if(formDefineVO){
|
var filter=oid + "_detail_form";
|
var form = layui.form;
|
var colCount = that.getFormCol(formDefineVO);
|
var items = that.getFormItemsByVO(formDefineVO,true,colCount,false);
|
webUtil.dialog({
|
title: '查看详细信息',
|
fullScreen:true,
|
content: '<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form " style="margin-top:5px" ></form>',
|
resizing: function (layero) {
|
form.doResize(filter);
|
},
|
success: function (layero) {
|
form.addItems(filter, items,
|
function () {
|
//只传递了数据的主键,所以我们需要从后台获取一下
|
form.load(filter,{
|
backPath:that.backPath,
|
url:that.url.controller + that.url.getDataByOid,
|
method:'get',
|
params:{
|
oid:oid,
|
templateOid:codetemplateoid
|
}
|
});
|
}, {}, {defaultColumnOneRow:colCount,labelWidth:150});
|
}
|
});
|
}
|
});
|
};
|
};
|
var cs = new Class();
|
exports(cs.MODELNAME,cs);
|
});
|