/**
|
* 按钮处理 升版
|
* @author wangting
|
* @date 2021-4-7
|
*/
|
layui.define(['layer','element','BaseAction'],function(exports){
|
var webUtil = $webUtil;
|
var Class = function() {
|
this.MODELNAME = "BaseRevisionAction";
|
this.moduleKey = "BaseRevisionAction";
|
this.getContent = function (id, options) {
|
var that = this;
|
that.id = id;
|
var html = [
|
'<div class="addOrEdit" id="addOrEdit_', id, ' lay-filter="addOrEdit_', id, '" style="display:block; text-align: center"></div>'
|
].join("");
|
return html;
|
};
|
this.doAction = function (options) {
|
var that = this;
|
webUtil.copyConfig(that, that.moduleKey);
|
that.id = options.id;
|
var paramVOS={
|
getDataUrl:'uiDataController/dataFormQuery',
|
getDataBackPath: configData.compatibility ? path : configData.objectServicePath,
|
getDataMethod:'post',
|
url:'uiDataController/upRevision',
|
backPath:configData.compatibility ? path : configData.objectServicePath,
|
method:'put',
|
uploadFileUrl:'vciFileUploadController/uploadFile',
|
uploadFileBackPath: configData.compatibility ? path : configData.fileServicePath
|
}
|
$.extend(paramVOS,options.paramVOS);
|
options.paramVOS=paramVOS;
|
|
var baseAction = layui['BaseAction'];
|
baseAction.callPreEvent(options, that, function (options) {
|
that.doEdit(options, function () {
|
baseAction.callPostEvent(options, that, options.callback);
|
});
|
});
|
};
|
|
this.doEdit=function (options,callback){
|
var that = this;
|
var paramVOS=$webUtil.paramLow(options.paramVOS);
|
if (!paramVOS['form'] && !paramVOS['context']&& !paramVOS['content']) {
|
$webUtil.showErrorMsg("按钮配置不正确");
|
return false;
|
}
|
var id=options.id;
|
var selectData=options.dataStore;
|
if(selectData.length<1){
|
$webUtil.showErrorMsg("请选择一条需要升版的数据");
|
return false;
|
}
|
if(!paramVOS.multi && selectData.length > 1){
|
$webUtil.showErrorMsg("仅能选择一条数据来操作");
|
return false;
|
}
|
if(paramVOS.checknotedit) {
|
var notedit = paramVOS.checknotedit.split('&');
|
var checknotedit=false;
|
layui.each(notedit, function (i, item) {
|
if (options.dataStore[0][item.split('=')[0]] == item.split('=')[1]) {
|
checknotedit=true;
|
return false;
|
}
|
})
|
if (checknotedit) {
|
$webUtil.showErrorMsg($webUtil.replaceFreeMarker(paramVOS.checknoteditmsg,options.dataStore,{}) || '当前数据不允许升版');
|
return false;
|
}
|
}
|
var table = layui.table;
|
if (paramVOS.form) {
|
var filter = "addOrEdit_" + id;
|
var form = layui.form;
|
var content = ['<form id="', filter, '" lay-filter="', filter, '" class="layui-form" style="margin:15px 30px 50px 0;" ></form>'
|
].join('');
|
var addSaveIndex = layer.open({
|
type: 1,
|
title: paramVOS.title,
|
btn: ['保存', '取消'],
|
//skin: 'layui-layer-lan',
|
content: content,
|
//area: ['1860px', '200px'],
|
maxWidth: $(window).width() - 100,
|
maxHeight: $(window).height() - 100,
|
closeBtn: 1,
|
shade: true,
|
shadeClose: true,
|
resize: true,
|
resizing: function (layero) {
|
form.doResize(filter);
|
},
|
success: function (layero,layerIndex,classP) {
|
$webUtil.get('webUIController/getFormDefineById', {
|
btmType: paramVOS.type,
|
id: paramVOS.form
|
}, function (result) {
|
if (result.success) {
|
var formCallback = function () {
|
var baseAction = layui['BaseAction'];
|
if ($('#' + filter + ' .layui-upload-drag').length > 0) {
|
baseAction.renderUploadFile('#' + filter + ' .layui-upload-drag', paramVOS)
|
}
|
if (paramVOS.uploadattachment && paramVOS.uploadattachment == 'true') {
|
//显示上传附件
|
baseAction.renderUploadAttach(filter, paramVOS)
|
}
|
if ($('#' + filter + ' .webeditor').length > 0) {
|
//编辑器
|
var editId='editor_'+$('#' + filter + ' .webeditor').attr('name')
|
baseAction.renderEditor(editId,'',paramVOS,function (){
|
baseAction.relocationOpen(classP)
|
});
|
}
|
baseAction.relocationOpen(classP)
|
|
|
//获取选中的数据
|
var sourceDataMap = {};
|
layui.each(options.sourceData, function (i, item) {
|
if(item.constructor === Object) return;
|
sourceDataMap['sourceDataMap["' + i + '"]'] = item;
|
})
|
$webUtil.ajax(paramVOS.getdatamethod, paramVOS.getdataurl, $.extend({
|
btmname: paramVOS.type,
|
formDefineId: paramVOS.form,
|
oid: selectData[0].oid
|
}, sourceDataMap),
|
function (result) {
|
if (result.success) {
|
form.setValues(result.obj.data, filter);
|
//文件
|
if (result.obj.filePathFieldMap) {
|
var filepath = layui.$('#' + filter + ' .uploadDemoView input.uploadFileOid').attr('name');
|
layui.$('#' + filter + ' .uploadDemoView').removeClass('layui-hide').find('img').attr('src', paramVOS.uploadfilebackpath + 'vciFileDownloadController/downloadByFileOid?fileOid=' + result.obj.filePathFieldMap[filepath].oid + '&' + TOKEN_KEY + '=' + $webUtil.getToken());
|
layui.$('#' + filter + ' .uploadDemoView input.uploadFileOid').val(result.obj.filePathFieldMap[filepath].filePath);
|
}
|
//附件
|
if (result.obj.attachmentFileVOs && result.obj.attachmentFileVOs.length > 0) {
|
var val = [];
|
layui.each(result.obj.attachmentFileVOs, function (i, attachmentFile) {
|
val.push(attachmentFile.oid)
|
})
|
$('#' + filter + ' [name="releaseFileOids"]').val(val.join(','))
|
}
|
if ($('#' + filter + ' .webeditor').length > 0) {
|
//编辑器
|
var initV=result.obj.data[$('#' + filter + ' .webeditor').attr('name')];
|
editor.html(initV);
|
$('#' + filter + ' .webeditor').val(initV);
|
}
|
|
}
|
}, function (xhr, error) {
|
$webUtil.showErrorMsg("获取数据出现了错误,可能是文件服务没有启动");
|
}, paramVOS.getdatabackpath)
|
|
}
|
|
form.addItems(filter, result.obj.items, formCallback, {}, {
|
defaultColumnOneRow: result.obj.columnOneRow
|
});
|
} else {
|
$webUtil.showErrorMsg(result.msg||'获取表单失败');
|
}
|
|
}, function (xhr, error) {
|
$webUtil.showErrorMsg("获取表单出现了错误,可能是文件服务没有启动");
|
}, paramVOS.backpath)
|
},
|
yes: function (layero) {
|
if (form.validata(filter)) {
|
var saveFn=function (){
|
var formValues = form.getDefaultValues(filter, true);
|
if(formValues.otherValue.releaseFileOids){
|
formValues.otherValue.releaseFileOids=formValues.otherValue.releaseFileOids.split(',');
|
}
|
if (!formValues.defaultValues.btmname) {
|
formValues.defaultValues.btmname = paramVOS.type;
|
}
|
var datas = {
|
formDefineId: paramVOS.form,
|
upVersion:paramVOS.upversion,
|
preEvent: paramVOS.prepvent,
|
afterEvent: paramVOS.afterevent,
|
beforeServerEvent: paramVOS.beforeserverevent,
|
afterServerEvent: paramVOS.afterserverevent,
|
releaseFileOids: formValues.otherValue.releaseFileOids||[],
|
data: formValues.otherValue
|
}
|
$.extend(datas, formValues.defaultValues);
|
datas['copyfromversion']=formValues.defaultValues.oid;
|
datas.oid=undefined;
|
$webUtil.manualAjax(paramVOS.method, paramVOS.url, JSON.stringify(datas), function (result) {
|
if (result.success) {
|
$webUtil.showMsgFromResult(result, paramVOS.title + '成功');
|
that.refresh();
|
if (options.callback) {
|
options.callback()
|
}
|
if (paramVOS.saveafterevent) {
|
var urlobj=$webUtil.getUrlParams(paramVOS.saveafterevent);
|
layui.use(urlobj.jsPath, function () {
|
var pathAction = layui[urlobj.jsPath];
|
var id = 'saveBeforeEvent_' + id;
|
pathAction[urlobj.methodName](paramVOS, id, selectData);
|
})
|
}
|
if(callback){
|
callback()
|
}
|
layer.close(addSaveIndex);
|
} else {
|
$webUtil.showErrorMsg(result.msg||paramVOS.title + '失败');
|
}
|
}, function (xhr, error) {
|
$webUtil.showErrorMsg("访问服务器出现了错误,可能服务器没有开启,或者连接失败");
|
}, paramVOS.backpath);
|
|
}
|
if (paramVOS.savebeforeevent) {
|
var urlobj=$webUtil.getUrlParams(paramVOS.savebeforeevent);
|
layui.use(urlobj.jsPath, function () {
|
var pathAction = layui[urlobj.jsPath];
|
var id = 'saveBeforeEvent_' + id;
|
pathAction[urlobj.methodName]({
|
paramVOS: paramVOS,
|
id: id,
|
dataStore: selectData,
|
sourceData:options.sourceData,
|
callback: saveFn
|
});
|
})
|
}else{
|
saveFn();
|
}
|
}
|
},
|
btn2: function (layero) {
|
layer.close(addSaveIndex)
|
}
|
});
|
} else if (paramVOS.context||paramVOS.content) {
|
layui.use('platform/objectService/VciUIContentViewer', function () {
|
var newTabClass = layui['platform/objectService/VciUIContentViewer'];
|
newTabClass.id = id;
|
newTabClass.multiCompent = true;
|
newTabClass.sourceData = {
|
btmType: paramVOS.type,
|
content: paramVOS.context,
|
dataOid:options.dataStore[0].oid,
|
actionData: {
|
selectData: options.sourceData,
|
dataStore:options.dataStore,
|
isOpen: true,
|
paramVOS: paramVOS
|
}
|
};
|
|
var filter = "addOrEdit_" + id;
|
var content = ['<div id="', filter, '" lay-filter="', filter, '" style="margin:5px;" >',newTabClass.getContent(id),'</div>']
|
var addSaveIndex = layer.open({
|
type: 1,
|
title: paramVOS.title,
|
//skin: 'layui-layer-lan',
|
content: content.join(''),
|
area: [$(window).width() - 100+'px', $(window).height() - 100+'px'],
|
shade: true,
|
shadeClose: true,
|
resize: true,
|
resizing: function (layero) {
|
},
|
success: function (layero,layerIndex,classP) {
|
newTabClass.init(id, newTabClass.sourceData,function (){
|
//layui['BaseAction'].relocationOpen(classP)
|
})
|
},
|
cancel: function (layero) {
|
if (options.callback) {
|
options.callback()
|
}
|
}
|
});
|
});
|
}
|
}
|
|
this.refresh = function () {
|
var that = this;
|
|
};
|
|
this.destory = function () {
|
var that = this;
|
var filter = "addOrEdit_" + that.id;
|
$('#'+filter).remove()
|
};
|
};
|
var cs = new Class();
|
exports(cs.MODELNAME,cs);
|
});
|