/**
|
* 流程处理的页面
|
* 支持批量执行任务
|
* 批量任务必须是同一个模板,同一个任务,并且都设置了负责人的
|
* 单一任务,如果下一节点没有设置负责人,需要选择负责人
|
*/
|
layui.define(['layer','form','table','BaseAction'],function(exports){
|
var ProcessExecutePanel = function(){
|
this.id = "vciWebProExecutePanel";
|
this.modelKey = "vciWebProExecutePanel";
|
this.taskOidInProcess = "";//任务主键
|
this.taskName = "";//任务名称
|
this.executionId = "";//执行主键
|
this.backPath = configData.compatibility ? path : configData.processServicePath;
|
this.outcomeMap = [];//所有的路由
|
this.canSelectUserMap = null;//下一负责人的映射
|
this.creator = "";//流程发起人 用于流程完毕推送消息
|
this.url = {
|
execute :'webProcessCommandController/completeTasks',//最终的执行URL
|
getOutcome: 'processDefineController/getOutcomes'//获取路由
|
}
|
};
|
|
ProcessExecutePanel.prototype.getContent = function(){
|
var that = this;
|
var formId = "form_" + that.id;
|
return '<div id="' + formId + '" lay-filter="' + formId + '" class="layui-form" style="width:250px;"></div>';
|
};
|
ProcessExecutePanel.prototype.init = function() {
|
var that = this;
|
if (that.outcomeMap == null || that.outcomeMap.length == 0) {
|
$webUtil.showErrorMsg("没有可供执行的操作,无法执行任务");
|
if (that.finishListener) {
|
that.finishListener(false);
|
}
|
return;
|
}
|
var form = layui.form;
|
var formId = "form_" + that.id;
|
//直接添加代码,因为使用表单的添加方法不能完全达到效果
|
var formHtmls = [];
|
formHtmls.push('<input type="text" name="taskOids" style="display:none;"/>');
|
formHtmls.push('<div class="layui-form-item"><div class="layui-form-mid layui-word-aux" style="max-width:240px;width:240px;font-size:10px;word-wrap: break-word;word-break: break-all;overflow: hidden;"><span style="color: #000000">当前任务:</span>' + that.taskName + '</div></div>');//当前任务提示
|
|
var needSetNextUser = false;
|
if (that.canSelectUserMap != null) {
|
needSetNextUser = true;
|
}
|
if (needSetNextUser) {//TODO 有下一负责人的情况没有测试
|
//需要添加下一负责的时候,选项单选按钮,因为需要选择后再选择处理人
|
formHtmls.push('<div class="layui-form-item"><div class="llayui-form-mid layui-word-aux layui-field-required" style="font-size:10px;">选择处理方式:</div></div>');
|
formHtmls.push('<div class="layui-form-item"><div class="layui-input-block">');
|
layui.each(that.outcomeMap, function (_index, _item) {
|
formHtmls.push('<input type="radio" name="outcome" value="' + _item.key + '" lay-filter="outcome" title="' + _item.value + '" ' + ((_index == 0) ? 'checked' : '') + ' />');
|
});
|
formHtmls.push('</div></div>');
|
//下一负责人,只有同意的时候才有下一负责人
|
var nextUserData = that.canSelectUserMap[that.outcomeMap[0].key];
|
//需要处理一下显示的名称
|
if (nextUserData) {
|
layui.each(nextUserData, function (_userIndex, _userItem) {
|
if (_userItem.type == "role") {
|
_userItem.name = _userItem.name + "(角色)";
|
} else if (_userItem.type == "dept") {
|
_userItem.name = _userItem.name + "(部门)";
|
} else {
|
_userItem.name = "(" + _userItem.id + ")" + _userItem.name;
|
}
|
if (_userItem.secret && _userItem.secret * 1 > 0 && _userItem.secretText) {
|
_userItem.name += " [" + _userItem.secretText + "]";
|
}
|
if (_userItem.children && _userItem.children.length > 0) {
|
layui.each(_userItem.children, function (_childrenUserIndex, _childrenUserItem) {
|
_childrenUserItem.name = "(" + _childrenUserItem.id + ")" + _childrenUserItem.name;
|
if (_childrenUserItem.secret && _childrenUserItem.secret * 1 > 0 && _childrenUserItem.secretText) {
|
_childrenUserItem.name += " [" + _childrenUserItem.secretText + "]";
|
}
|
});
|
}
|
});
|
}
|
formHtmls.push('<div class="layui-form-item" style="' +
|
(nextUserData ? '' : "display:none;") + '">' +
|
'<div class="llayui-form-mid layui-word-aux">下一负责人:</div></div>');
|
formHtmls.push('<div class="layui-form-item" style="' +
|
(nextUserData ? '' : "display:none;") + '"><div class="layui-input-block" style="margin-left:5px;margin-top:5px;">');
|
formHtmls.push('<select name="nextTaskUser" required lay-filter="nextTaskUser" style="width:230px" ');
|
var referConfigString = JSON.stringify({
|
textField: 'name',
|
valueField: 'id',
|
loadType: 'all',
|
type: 'tree',
|
isMuti: false,
|
data: (nextUserData ? nextUserData : [])
|
}, function (key, val) {
|
if (typeof val === 'function') {
|
return val + '';
|
}
|
return val;
|
});
|
formHtmls.push(' lay-refer=\'' + referConfigString + '\' lay-refer-showField="name" inDialog="true">');
|
formHtmls.push('<option value=""></option></select></div></div>');
|
//当修改了处理方式的时候,同步要修改下一负责人的内容
|
form.on('radio(outcome)', function (data) {
|
var selectOutComeElem = $('select[name="nextTaskUser"]');
|
if (that.canSelectUserMap && that.canSelectUserMap[data.value]) {
|
//说明应该设置下一负责人
|
var referConfigString1 = JSON.stringify({
|
textField: 'name',
|
valueField: 'id',
|
loadType: 'all',
|
type: 'tree',
|
isMuti: false,
|
data: that.canSelectUserMap[data.value]
|
}, function (key, val) {
|
if (typeof val === 'function') {
|
return val + '';
|
}
|
return val;
|
});
|
selectOutComeElem.attr("lay-refer", referConfigString1);
|
selectOutComeElem.parent().parent().show();
|
selectOutComeElem.parent().parent().prev().show();
|
} else {
|
//不设置下一负责人,那应该隐藏
|
selectOutComeElem.parent().parent().hide();
|
selectOutComeElem.parent().parent().prev().hide();
|
}
|
});
|
}
|
formHtmls.push('<div class="layui-form-item"><div class="layui-form-mid layui-word-aux" style="font-size:10px;color:#2080da;"><span style="color: #000000">请在下方输入您的审批意见:</span></div></div>');//审批意见
|
formHtmls.push('<div class="layui-form-item layui-form-text"><div class="layui-input-block" style="margin-left:0px">' +
|
'<textarea name="note" placeholder="" class="layui-textarea"></textarea>' +
|
'</div></div>');
|
|
var fileHtml = '<div class="layui-upload-drag processFile" data-value="processFile" id="upload-drag-processFile" extendAttrMap=\'{"accept":"file"}\' lay-filter="processFile" >' +
|
' <i class="layui-icon" style="font-size: 36px;"></i>' +
|
' <p style="font-size: 12px;">点击上传,或将文件拖拽到此处</p>' +
|
' <div class="layui-hide uploadDemoView">' +
|
' <hr>' +
|
'<input class="uploadFileOid" type="hidden" name="processFile">'+
|
' <img src="" alt="已上传图片" style="max-width: 180px">' +
|
' </div>' +
|
'</div>';
|
formHtmls.push('<div class="layui-form-item"><label class="layui-form-label" style="width: 90px;padding: 0;color:#000;">审批意见附件:</label><div class="layui-input-block" style="margin-left: 90px">'+fileHtml+'</div></div>');//附件
|
formHtmls.push('<div class="layui-form-mid layui-word-aux" style="font-size:10px;color:#000 !important;padding: 0 !important;line-height: 16px">已上传审批文件:</div>');
|
formHtmls.push('<table id="table_profile" lay-filter="table_profile" style="overflow-x:auto;clear:both"></table>')
|
if (needSetNextUser) {
|
formHtmls.push('<div class="layui-form-item"><div class="layui-input-inline" style="padding:5px 0;">' +
|
'<button class="layui-btn" name="processOutCome" lay-filter="processTask_ok_' + that.id + '">确定提交</button></div></div>');
|
} else {
|
formHtmls.push('<div class="layui-form-item">');
|
that.setRouter = false;//是否需要提示重新设置流程模板
|
var outcomeBtn=[],outcomeBtn2=[]
|
layui.each(that.outcomeMap, function (_index, _item) {
|
if (_index == 0 && _item.key == "未命名路由") {
|
that.setRouter = true;
|
outcomeBtn.push('<button style="margin: 0 10px 10px 0;display: block" class="layui-btn layui-btn-sm" name="processOutCome" lay-filter="processTask_ok_' + that.id + '_' + _index + '" type="button">执行</button>');
|
} else if (_index == 1 && _item.key == "未命名路由" && setRouter) {
|
$webUtil.showErrorMsg("流程模板错误!请修改流程模板!");
|
that.setRouter = false;
|
return false
|
}else if(_item.key=='同意'){
|
outcomeBtn.push('<button style="margin: 0 10px 10px 0;display: block;" class="layui-btn layui-btn-sm ' + ((_index % 2 == 1) ? 'layui-btn-primary' : '') + '" name="processOutCome" lay-filter="processTask_ok_' + that.id + '_' + _index + '" type="button">同意</button>');
|
} else {
|
outcomeBtn2.push('<button style="margin: 0 10px 10px 0;display: block" class="layui-btn layui-btn-sm ' + ((_index % 2 == 1) ? 'layui-btn-primary' : '') + '" name="processOutCome" lay-filter="processTask_ok_' + that.id + '_' + _index + '" type="button">' + _item.key + '</button>');
|
}
|
|
});
|
if(outcomeBtn.length>0){
|
formHtmls.push('<div class="layui-input-inline" style="padding:5px 0;min-width: auto;margin-right: 0">'+outcomeBtn.join('')+'</div>');
|
}
|
if(outcomeBtn2.length>0){
|
formHtmls.push('<div class="layui-input-inline" style="padding:5px 0;min-width: auto;margin-right: 0">'+outcomeBtn2.join('')+'</div>');
|
}
|
formHtmls.push('</div>');
|
}
|
$("#" + formId).html(formHtmls.join(''));
|
$('#' + formId + ' [name="processOutCome"]').click(function () {
|
that.executeTask(needSetNextUser ? "" : $(this).html());
|
});
|
form.render();
|
var baseAction = layui['BaseAction'];
|
baseAction.renderUploadFile('#upload-drag-processFile', {
|
uploadfileurl: 'webProcessCommandController/uploadAuditSuggestFile',
|
uploadfilebackpath: configData.compatibility ? path : configData.fileServicePath
|
},{
|
taskOids:that.taskOidInProcess
|
},function (){
|
that.refresh()
|
})
|
that.initFileTable('table_profile')
|
$('#' + formId + '_attach .layui-upload').css({'margin-left': '0'})
|
form.setValues({
|
taskOids: that.taskOidInProcess,
|
taskName: that.taskName
|
});
|
};
|
ProcessExecutePanel.prototype.initFileTable = function(id) {
|
var that = this;
|
var table = layui.table;
|
table.render({
|
elem: '#' + id,
|
id: id,
|
url: 'processDefineController/listAuditSuggestFile',
|
backPath: that.backPath,
|
selectMode: table.selectMode.signal,
|
width: 250,
|
extraParams: {
|
taskOids:that.taskOidInProcess
|
},
|
cols: [[{
|
title: '文件名',
|
field: 'name',
|
width: 120,
|
templet:function (d){
|
return '<a class="layui-btn layui-btn-intable" style="width: 100%;text-overflow: ellipsis;overflow: hidden;" title="'+d.name+'" lay-event="PREVIEW">'+d.name+'</a>'
|
}
|
}, {
|
title: '上传人',
|
field: 'creator',
|
width: 68
|
},{
|
field:'option',
|
title:'操作',
|
width:56,
|
templet:function (d){
|
return '<a class="layui-btn layui-btn-intable" lay-event="download">下载</a>';
|
}
|
}]],
|
done: function (res, cur, total) {
|
table.on('tool(' + id + ')',function(obj){
|
var data = obj.data;//当前选择行的数据
|
var layEvent = obj.event;//点的是什么按钮
|
if(layEvent == 'PREVIEW'){
|
//文件预览
|
layui.use('BaseFileDownloadAction', function () {
|
var vciWebFilePreview = layui['BaseFileDownloadAction'];
|
vciWebFilePreview.PREVIEW(data.oid,{fileOid:data.oid},function (){
|
$webUtil.showErrorMsg("文件预览失败,请联系管理员")
|
})
|
})
|
}else if(layEvent=='download'){
|
layui.use('BaseFileDownloadAction', function () {
|
var vciWebFilePreview = layui['BaseFileDownloadAction'];
|
vciWebFilePreview.doAction({
|
paramVOS: {},
|
id: 'download'+data.oid,
|
dataStore: [data]
|
})
|
})
|
}
|
});
|
}
|
});
|
};
|
ProcessExecutePanel.prototype.executeTask = function(outcome){
|
var that = this;
|
var form = layui.form;
|
var formId = "form_" + that.id;
|
if(form.validata(formId)){
|
//校验通过
|
var values = form.getValues(formId);
|
if($webUtil.isNull(outcome) && $webUtil.isNull(values.outcome)){
|
$webUtil.showErrorMsg("请必须选择处理方式");
|
return false;
|
}
|
if($webUtil.isNotNull(outcome) && $webUtil.isNull(values.outcome)){
|
values.outcome =outcome;
|
}
|
var nextTaskUser = values.nextTaskUser;
|
if($webUtil.isNull(nextTaskUser) && that.canSelectUserMap !=null && that.canSelectUserMap[values.outcome]){
|
$webUtil.showErrorMsg("请必须选择下一负责人");
|
return false;
|
}
|
if(that.setRouter && values.outcome =='执行'){
|
values.outcome = '未命名路由';
|
outcome = "未命名路由";
|
}
|
if("不同意"==values.outcome && $webUtil.isNull(values.note)){
|
$webUtil.showErrorMsg("当处理方式为不同意时,需要填写审批意见");
|
return false;
|
}
|
if("同意"==values.outcome && $webUtil.isNull(values.note)){
|
values.note = "同意";
|
}
|
var requestData = {
|
taskOids:values.taskOids,
|
outCome:($webUtil.isNotNull(outcome)?outcome:(values.outcome)),
|
note:values.note,
|
nextTaskUserIds:nextTaskUser
|
};
|
|
$webUtil.post(that.url.execute,requestData,function(result){
|
if(result.success){
|
if(that.finishListener){
|
that.finishListener(true);
|
}
|
$webUtil.showMsg("流程任务执行成功");
|
}else{
|
$webUtil.showErrorMsg(result.msg);
|
}
|
},{
|
},that.backPath,true);
|
}
|
};
|
|
ProcessExecutePanel.prototype.refresh=function (){
|
layui.table.reload('table_profile')
|
}
|
|
var bdp = new ProcessExecutePanel();
|
exports('process/vciWebProExecutePanel',bdp);
|
});
|