layui.define(['tool','oaPicker'], function (exports) { const layer = layui.layer; const form = layui.form; const tool = layui.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+='审批记录'; } return tem; }, createTemplate: function (flow) { let me = this; let checkHtml = `

审批操作

${me.flowTemplate(flow)} ${me.uidsTemplate()} ${me.copyTemplate()}
`; return checkHtml; }, //审批待提交模版 initTemplate: function (detail) { let me = this; let checkHtml = `

审批操作

${me.statusTemplate(detail.check_status)} ${me.recordTemplate(detail.check_record)} ${me.flowTemplate(detail.flow)} ${me.uidsTemplate()} ${me.copyTemplate()}
${me.btnTemplate()}
`; let viewHtml = `

审批操作

${me.statusTemplate(detail.check_status)} ${me.recordTemplate(detail.check_record)}
`; 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 = `

审批操作

${me.sets.check_copy == 1 ? checkCopy : ""} ${me.recordTemplate(detail.check_record)} ${detail.is_checker==1 && detail.step.check_role==0?checkNode:''} ${detail.is_checker==1?checkContent:''}
审批状态 ${me.checkStatus(detail.check_status)} 当前审批人 ${detail.check_unames}
审批流
${detail.admin_name}
创建
${flowHtml}
${detail.is_checker==1?btnCheck:''} ${detail.is_creater==1 && (detail.check_status==1 || detail.check_status==3)?btnBack:''} ${me.sets.check_back == 1 && detail.check_status==2?btnCheckBack:''}
`; return checkHtml; }, //审批撤回模版 backTemplate: function (detail) { let me = this; let btnHtml =''; if(me.sets.check_btn == 1){ btnHtml ='
'; } let checkHtml = `

审批操作

${me.statusTemplate(detail.check_status)} ${me.recordTemplate(detail.check_record)} ${me.flowTemplate(detail.flow)} ${me.uidsTemplate()} ${me.copyTemplate()}
${me.btnTemplate()}
`; let viewHtml = `

审批操作

${me.statusTemplate(detail.check_status)} ${me.recordTemplate(detail.check_record)}
`; 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.render(); } } }) //选择审批流 form.on('select(flowtype)', function(data){ var check_type = data.elem[data.elem.selectedIndex].title; if(data.value==''){ $('#checkTR').html(me.uidsTemplate()); checkBox.find('[name="check_copy_unames"]').val(''); checkBox.find('[name="check_copy_uids"]').val(''); form.render(); return false; } if(check_type == 1){ $('#checkTR').html(me.uidsTemplate()); form.render(); } $.ajax({ url: "/api/check/get_flow_users", type:'get', data:{id:data.value}, 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 = '审批流\ \
      '+flow_li+'
    \ '; $('#checkTR').html(formHtml); } } } }) }); //提交审批 form.on('submit(checkform)', function(data){ data.field.action_id = action_id; data.field.check_name = me.sets.check_name; let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { tool.sideClose(1000); } } tool.post("/api/check/submit_check", data.field, callback); return false; }); //审批操作按钮 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='确定拒绝该审批?'; } tool.ask(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.sideClose(1000); } } }) layer.close(index); }); } else if(check_status ==3){ layer.prompt({ formType: 2, title: '请输入撤回理由', area: ['480px', '120px'] //自定义文本域宽高 }, function(value, index, elem){ if(value==''){ 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:value }, success: function (e) { layer.msg(e.msg); if (e.code == 0) { tool.sideClose(1000); } } }) layer.close(index); }); } else if(check_status ==4){ layer.prompt({ formType: 2, title: '请输入反确认理由', area: ['480px', '120px'] //自定义文本域宽高 }, function(value, index, elem){ if(value==''){ 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:value }, success: function (e) { layer.msg(e.msg); if (e.code == 0) { tool.sideClose(1000); } } }) layer.close(index); }); } return false; }); } }; exports('oaCheck', obj); });