mbui.define(['form','layer','userPicker'], function (exports) {
const layer = mbui.layer;
const form = mbui.form;
const tool = mbui.tool;
const opts={
"checkBox":"checkBox",//审核容器id
"check_copy": 1,//是否需要抄送人
"check_name": "",//审核类型标识
"check_btn":1,//是否显示提交审核按钮
"check_back":0,//是否支持反确认审核操作
"checking_btn":''//待审核状态下添加的按钮
};
const obj = {
loading:false,
checkStatus: function (status) {
statusArray = ['待提交审批','审批中','审批通过','审批不通过','已撤回'];
return ''+statusArray[status]+' ';
},
statusTemplate: function (status) {
let me = this;
let tem =`
审批状态
${me.checkStatus(status)}
`;
return tem;
},
uidsTemplate: function () {
let tem =`
审批人
`;
return tem;
},
flowTemplate: function (data) {
let flowtype='--请选择-- ';
if(data && data.length>0){
for(let i=0;i'+data[i].title+'';
}
}
let tem =`
`;
return tem;
},
copyTemplate: function () {
let me = this;
let tem =`
抄 送 人
`;
if(me.sets.check_copy == 1){
return tem;
}else{
return '';
}
},
btnTemplate: function () {
let me = this;
let tem =`
提交审批
重置
${me.sets.checking_btn}
`;
if(me.sets.check_btn == 1){
return tem;
}else{
return '';
}
},
recordTemplate: function (record) {
let me = this;
let tem ='';
if(record.length>0){
tem+='';
tem+='
审批记录
';
tem+='
';
for(let l=0;l'+record[l].check_time_str+''+record[l].name+' 『'+record[l].status_str+'』 了此申请。审批意见:'+record[l].content+'。
';
}
tem+='
';
tem+='';
}
return tem;
},
createTemplate: function (flow) {
let me = this;
let checkHtml = `
`;
return checkHtml;
},
//审批待提交模版
initTemplate: function (detail) {
let me = this;
let checkHtml = `
`;
let viewHtml = `
`;
if(detail.is_creater==1){
return checkHtml;
}
else{
return viewHtml;
}
},
//审批中模版
checkTemplate: function (detail) {
let me = this,flowHtml='',list = detail.nodes;
for(var f=0;f1){
check_types= ' 会签 ';
if(list[f].check_types==2){
check_types= ' 或签 ';
}
}
}
if(list[f].check_role == 0 || list[f].check_role == 5){
checkUser=list[f].check_uids_info[0].name;
}
if(list[f].check_role == 1 || list[f].check_role == 2 || list[f].check_role == 3 || list[f].check_role == 4){
checkUser=list[f].flow_name;
}
if(list[f].check_list.length>0){
let one=0,two=0,three=0;
for(var m=0;m 0){
iconStatus =' ';
strStatus ='拒绝
';
}
else{
if(one > 0){
iconStatus =' ';
strStatus ='待审批
';
}
else{
iconStatus =' ';
strStatus ='通过
';
}
}
}
//或签
if(list[f].check_types==2){
if(two > 0){
iconStatus =' ';
strStatus ='通过
';
}
else{
iconStatus =' ';
strStatus ='拒绝
';
}
}
}
flowHtml+= ''+iconStatus+'
'+check_types+checkUser+'
'+strStatus+iconRight+'
';
}
let checkCopy=`
抄 送 人
${detail.copy_unames}
`;
let checkNode = `
下一审批人
`;
let checkContent = `
审批意见
`;
let btnCheck=' 通过 拒绝 ';
if(detail.step.check_role==5){
btnCheck=' 通过 退回 ';
}
let btnBack=' 撤回 ';
let btnCheckBack='反确认审核 ';
let checkHtml = `
`;
return checkHtml;
},
//审批撤回模版
backTemplate: function (detail) {
let me = this;
let btnHtml ='';
if(me.sets.check_btn == 1){
btnHtml ='提交审批 重置
';
}
let checkHtml = `
`;
let viewHtml = `
`;
if(detail.is_creater==1){
return checkHtml;
}
else{
return viewHtml;
}
},
submit:function(data,callback){
tool.post("/api/check/submit_check", data, callback);
},
init: function (options) {
this.sets = $.extend({}, opts, options);
let me = this;
let checkBox = $('#'+me.sets.checkBox);
let action_id = checkBox.data('id');
let check_status = checkBox.data('status');
let check_flow_id = checkBox.data('checkflowid');
if(action_id === undefined || check_status === undefined || check_flow_id === undefined){
return false;
}
//获取审批信息
$.ajax({
url: "/api/check/get_flow_nodes",
type:'get',
data:{check_name:me.sets.check_name,action_id:action_id,flow_id:check_flow_id},
success: function (e) {
if (e.code == 0) {
if(check_status==0){
if(action_id==0){
checkBox.append(me.createTemplate(e.data));
}
else{
checkBox.append(me.initTemplate(e.data));
}
}
else if(check_status==4){
checkBox.append(me.backTemplate(e.data));
}
else{
checkBox.append(me.checkTemplate(e.data));
}
//提交审批
form({
target: '#formCheckBox',
submit:function(data){
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
tool.reload(2000);
}
}
data.action_id = action_id;
data.check_name = me.sets.check_name;
tool.post("/api/check/submit_check", data, callback);
return false;
}
});
}
}
})
$('body').on('change','input[name="check_node"]',function() {
var val = this.value;
if(val==2){
$('.next-admin').show();
}
else{
$('.next-admin').hide();
}
});
//选择审批流
$('body').on('change','select[name="flow_id"]', function(data){
var check_type = $('select[name="flow_id"] option:selected').attr('title');
var selectedValue = $(this).val();
if(selectedValue==''){
$('#checkTR').html(me.uidsTemplate());
checkBox.find('[name="check_copy_unames"]').val('');
checkBox.find('[name="check_copy_uids"]').val('');
return false;
}
if(check_type == 1){
$('#checkTR').html(me.uidsTemplate());
}
$.ajax({
url: "/api/check/get_flow_users",
type:'get',
data:{id:selectedValue},
success: function (e) {
if (e.code == 0) {
var flow_li='',flow_idx=0;
var flow_data = e.data.flow_data;
if(e.data.copy_uids && e.data.copy_uids !='' && me.sets.check_copy==1){
checkBox.find('[name="check_copy_unames"]').val(e.data.copy_unames);
checkBox.find('[name="check_copy_uids"]').val(e.data.copy_uids.split(','));
}
if(check_type == 2 || check_type == 3){
for(var a=0;a0){
flow_idx++;
for(var b=0;b '+check_uids_info[b].name+'';
}
flow_li+='第'+flow_idx+'级审批『'+check_role+'』'+check_types+''+user_li+'
';
}
}
formHtml = '';
$('#checkTR').html(formHtml);
}
}
}
})
});
//审批操作按钮
checkBox.on('click','.btn-check', function(data){
let content=checkBox.find('[name="content"]').val();
let check_status=$(this).data('status');
let check_role = checkBox.find('input[name="check_role"]').val();
let check_node=0,check_uids='';
if(check_role == 0 && check_status==1){
check_node = checkBox.find('input[name="check_node"]:checked').val();
check_uids = checkBox.find('input[name="check_uids"]').val();
if(!check_node){
layer.msg('请选择下一审批节点');
return false;
}
if(check_node == 2 && check_uids==''){
layer.msg('请选择下一审批人');
return false;
}
}
if(check_status ==1 || check_status==2){
if(content==''){
layer.msg('请输入审批意见');
return false;
}
let confirmTips='确定通过该审批?';
if(check_status==2){
confirmTips='确定拒绝该审批?';
}
layer.confirm(confirmTips, function(index){
$.ajax({
url: "/api/check/flow_check",
type:'post',
data:{
action_id:action_id,
check_name:me.sets.check_name,
check_flow_id:check_flow_id,
check_node:check_node,
check_uids:check_uids,
check:check_status,
content:content
},
success: function (e) {
layer.msg(e.msg);
if (e.code == 0) {
tool.reload(1000);
}
}
})
layer.close(index);
});
}
else if(check_status ==3){
layer.prompt('请输入撤回理由', function(val, index){
if(val==''){
layer.msg('请输入撤回理由');
return false;
}
$.ajax({
url: "/api/check/flow_check",
type:'post',
data:{
action_id:action_id,
check_name:me.sets.check_name,
check_flow_id:check_flow_id,
check:check_status,
content:val
},
success: function (e) {
layer.msg(e.msg);
if (e.code == 0) {
tool.reload(1000);
}
}
})
layer.close(index);
});
}
else if(check_status ==4){
layer.prompt('请输入反确认理由', function(val, index){
if(val==''){
layer.msg('请输入反确认理由');
return false;
}
$.ajax({
url: "/api/check/flow_check",
type:'post',
data:{
action_id:action_id,
check_name:me.sets.check_name,
check_flow_id:check_flow_id,
check:check_status,
content:val
},
success: function (e) {
layer.msg(e.msg);
if (e.code == 0) {
tool.reload(1000);
}
}
})
layer.close(index);
});
}
return false;
});
}
};
exports('oaCheck', obj);
});