/**
* Created by weidy on 2018/5/17.
* 流程执行窗口
*/
layui.define(['table','element','layer','form','vciWebComboxStore','vciWebFileManager','vciWebDataGrid',
'process/vciWebProBusinessData','process/vciWebProBusinessDoc',
'process/vciWebProHistory','process/vciWebProExecutePanel'],function(exports){
var ExecuteTask = function(){
this.moduleKey = "vciWebProExecuteTask";
this.rejectRouteName="不同意";
this.backPath = configData.compatibility ? path : configData.processServicePath;//默认流程和项目的路径是一样的
this.url = {
getOutcome: 'processDefineController/getOutcomes',
checkUserSameTemplate:'processDefineController/checkUseSameTemplate',
dataDefine:'processDefineController/getDataDefine'//从后台获取显示关联数据的列表的code
};
this.allowMutiExecuteTask = false;//是否允许批量执行任务
this.id="vciWebProExecuteTask";
this.dialogForm ='';
this.defaults = {
dataTableBtmType:"input",//关联数据的表格在的业务类型,用于查询平台中的列表
dataTableCode:"ShowMyTaskLinkDataList"//关联数据的表格代号
};
};
ExecuteTask.prototype.getContent = function(){//获取基础的html
return "";
};
ExecuteTask.prototype.init = function(){//初始化
var that = this;
$webUtil.copyConfig(that,that.moduleKey);
};
ExecuteTask.prototype.showExecuteWindow=function(taskInfo,options,closeCallback){
var that = this;
if(!taskInfo){
$webUtil.showErrorMsg("没有流程相关的信息");
return;
}
var isMutiTask = false;
if(!$webUtil.isArray(taskInfo)){
taskInfo = [taskInfo];
}
if(taskInfo.length == 0 ){
$webUtil.showErrorMsg("没有流程相关的信息");
return;
}
if(taskInfo.length >1){
isMutiTask = true;
}
if(!that.allowMutiExecuteTask && isMutiTask){
$webUtil.showErrorMsg("不允许批量执行流程");
return false;
}
var taskOids = "";
var taskName = taskInfo[0].taskName;
var executionId = taskInfo[0].executionId;
layui.each(taskInfo,function(_index,_item){
taskOids += _item.taskOid + ",";
});
taskOids = layui.util.removeComma(taskOids);
var taskCodes = "";
layui.each(taskInfo,function(_index,_item){
taskCodes += _item.code + ",";
});
taskCodes = layui.util.removeComma(taskCodes);
var firstOid = taskInfo[0].taskOid;
//如果是批量执行流程,那就需要先是否使用相同的流程模板和相同的任务节点
if(isMutiTask){
$webUtil.post(that.url.checkUserSameTemplate,{taskOids:taskOids},function(result){
if(result.success){
$webUtil.showErrorMsg("暂时还没有添加对于批量执行任务的支持");
//批量的任务时,是不能查看数据,文件和流程历史的
//直接显示批量执行的窗口
//that.gotoShowWindow(taskOids,taskCodes,firstOid,taskName,isMutiTask,options,closeCallback,taskInfo);
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(){},that.backPath,true);
}else{
that.gotoShowWindow(taskOids,taskCodes,executionId,taskName,isMutiTask,options,closeCallback,taskInfo);
}
};
ExecuteTask.prototype.gotoShowWindow = function(taskOids,taskCodes,executionId,taskName,isMutiTask,options,closeCallback,taskInfo){
var that = this;
var form = layui.form;
var formId = "execute_task_form_" + taskOids;
var title = "执行[" + taskName + "]" + (isMutiTask?"等任务":"");
var tree = layui.tree;
var canSelectUserMap = null;
var windowArea= [(($webUtil.isNotNull(options.width) || options.width*1>1) ?options.width*1 : 950) +'px',
(($webUtil.isNotNull(options.height) && options.height*1>1) ?options.height*1 : 600) + 'px'];
if(options.fullScreen){
if(window.innerWidth){
windowArea = [(window.innerWidth-50) + "px",(window.innerHeight-50) + "px"];
}else{
windowArea = [(document.documentElement.clientWidth-50) + "px",(document.documentElement.clientHeight-50) + "px"];
}
}
var divWidth = windowArea[0].substring(0,windowArea[0].indexOf("px")) - 295;
that.closeedWindow = false;
var taskWindowIndex = layer.open({
type:1,
title:title,
//btn:['取消'],//感觉直接关闭比较好,取消占用太多纵向空间
//skin:'layui-layer-lan',
content:'
' +
'',
area:windowArea,
closeBtn:(options.full)?0:1,
shade:true,
shadeClose:true,
resize:true,
resizing:function(layero){
form.doResize();
},
yes:function(index,layero){
layer.close(taskWindowIndex);
if(closeCallback){
closeCallback(false);
}
},
success:function(layero){
//特别注意,多任务处理的,页面只能显示列表;而且多任务中的业务数据必须是同一个业务类型下;这个需要各自展示的页面中自行处理
//1. 添加关联的业务数据展示表单的选项卡,需要从后台去查询参数里定义,如果定义了tableCode,说明是显示平台的表格,如果是detailUrl说明是显示自定义的页面,否则显示默认的
//2. 添加关联文档的选项卡,只显示当前业务数据关联的文档,如果是明细数据,需要使用自定义的页面内容中展示
//3. 添加流程历史的选项卡,其中包含流程图和流程历史
//从后台先获取流程相关的配置
var compIdFix = taskOids;
$webUtil.post(that.url.dataDefine,{executionid:executionId},function(result){
if(result.success){
var businessDataComp = layui['process/vciWebProBusinessData'];//业务数据
var businessDocComp = layui['process/vciWebProBusinessDoc'];//关联文档
var processHistoryComp = layui['process/vciWebProHistory'];//操作历史
businessDataComp.businessBtmInProcess = result.obj.UIType;
businessDataComp.businessOidsInProcess = result.obj.businessOids;
businessDataComp.taskOidInProcess = taskOids;
businessDataComp.taskCodeInProcess = taskCodes;
businessDataComp.tableCode = result.obj.tableCode;
businessDataComp.detailUrl = result.obj.detailUrl;
businessDataComp.UIContentCode = result.obj.UIContentCode;
result.obj.UIContentCode && (businessDataComp.UIContentSelectData = taskInfo)
businessDataComp.viewProcessLinkBusinessToken = result.obj.viewProcessLinkBusinessToken;//用来在查看流程的数据时,告诉后台跳过权限的
businessDataComp.executionidNoInProcess = result.obj.executionidno;
businessDataComp.executionid = executionId;
businessDataComp.maxWidth = divWidth;
businessDataComp.maxHeight = null;
businessDataComp.id = "vciProcessBusinessData_executeTask_" + compIdFix;
businessDocComp.businessBtmInProcess = result.obj.UIType;
businessDocComp.businessOidsInProcess = result.obj.businessOids;
businessDocComp.taskOidInProcess = taskOids;
businessDocComp.taskCodeInProcess = taskCodes;
businessDocComp.id = "vciProcessBusinessDoc_executeTask_" + compIdFix;
processHistoryComp.taskOidInProcess = taskOids;
processHistoryComp.taskCodeInProcess = taskCodes;
processHistoryComp.executionId=executionId;
processHistoryComp.maxWidth = divWidth;
processHistoryComp.id = "vciProcessHistory_executeTask_" + compIdFix;
webUtil.ajax('get','/uiDataController/getDataAttr',{oid: result.obj.businessOids, btmname: result.obj.UIType} , function (res) {
if (res.success) {
if(res.data){
businessDataComp.businessDataInProcess=res.data;
processHistoryComp.businessDataInProcess=res.data;
businessDocComp.businessDataInProcess=res.data;
}else{
businessDataComp.businessDataInProcess=[res.obj];
processHistoryComp.businessDataInProcess=[res.obj];
businessDocComp.businessDataInProcess=[res.obj];
}
layui.element.tabAdd('processbusniessdata_' + formId,{
title:'业务数据信息',
id: "tab_" + businessDataComp.id,
unAllowClose:true,
item:businessDataComp
});
/*layui.element.tabAdd('processbusniessdata_' + formId,{
title:'业务数据关联文档',
id: "tab_" + businessDocComp.id,
unAllowClose:true,
item:businessDocComp
});*/
layui.element.tabAdd('processbusniessdata_' + formId,{
title:'流程跟踪',
id: "tab_" + processHistoryComp.id,
unAllowClose:true,
item:processHistoryComp
});
if(result.defaultDisplayDoc || result.defaultDisplayDoc == "true"){ //如果用户想优先看文件
layui.element.tabChange('processbusniessdata_' + formId, "tab_" + businessDocComp.id);
}else{
layui.element.tabChange('processbusniessdata_' + formId, "tab_" + businessDataComp.id);
}
} else {
webUtil.showErrorMsg(res.msg);
}
}, function (xhr, err) {
webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启");
}, that.backPath,true);
}else{
if(!that.closeedWindow){
$webUtil.showErrorMsg(result.msg,function(){
that.closeedWindow = true;
layer.close(taskWindowIndex);
if(closeCallback){
closeCallback(false);
}
});
}
}
},function(){
$webUtil.showErrorMsg("连接服务出现了问题");
},that.backPath,true);
//处理面板是同步处理的。
$webUtil.post(that.url.getOutcome,{taskOid:taskOids},function(result){
if(result.success&&result.obj && result.obj.length > 0){
//查询成功的
var outcomeMap = [];
var canSelectUserMap = null;
var end = false;
layui.each(result.obj,function(_index,_item){
if(!_item.processUser || _item.processUser == null || _item.processUser.length == 0){
if(_item.nextNodeUser && _item.nextNodeUser != null && _item.nextNodeUser.length > 0){
if(canSelectUserMap == null){
canSelectUserMap = {};
}
canSelectUserMap[_item.name] = _item.nextNodeUser;
}
}
outcomeMap.push({
key:_item.name,
value:_item.name
});
if(_item.nextTaskName == "结束"){
end = true;
}
});
var executePanel = layui['process/vciWebProExecutePanel'];
executePanel.id = "execute_" + compIdFix;
executePanel.taskOidInProcess = taskOids;
executePanel.outcomeMap = outcomeMap;
executePanel.executionId = executionId;
executePanel.taskName = taskName;
executePanel.creator = end?taskInfo[0].creator:"";
executePanel.canSelectUserMap = canSelectUserMap;
executePanel.finishListener = function(success){
if(success){
that.closeedWindow = false;
layer.close(taskWindowIndex);
if(closeCallback){
closeCallback(true);
}
}
};
$('#processtaskdo_' + formId).html(executePanel.getContent());
executePanel.init();
}else{//说明这些任务可能不是同一个流程模板,同一个的流程任务节点
if(!that.closeedWindow){
$webUtil.showErrorMsg(result.msg,function(){
that.closeedWindow = true;
layer.close(taskWindowIndex);
if(closeCallback){
closeCallback(false);
}
});
}
}
},function(){
$webUtil.showErrorMsg("连接服务出现了问题");
},that.backPath,true);
}
});
if(options.full){
layer.full(taskWindowIndex);
}
};
var et = new ExecuteTask();
exports("process/vciWebProExecuteTask",et);
});