| 1 |
- import{t as P,R as Z,K as re,E as N}from"./index.BteTc5v8.js";import{U as ie,A as de,a as pe,b as ue}from"./api.3lElPRkW.js";import{a as ce,r as G,w as J,_ as O,t as me,aj as i,J as S,o as f,K as l,S as e,b as v,P as k,c as D,a9 as M,R as z,M as x,Q as _e,u as K}from"./vue.D1BjjNmv.js";import{_ as fe}from"./_plugin-vue_export-helper.DlAUqK2U.js";function ge(){return P({url:"/api/system/device/category/",method:"get"})}function ve(){return P({url:"/api/system/app_user/?user_type=3",method:"get"})}function ye(E){return P({url:"/api/system/approval/workflow_step/?workflow_id="+E,method:"get"})}const be={class:"workflow-steps"},we={class:"workflow-step"},ke={class:"step-title"},Ve={class:"step-roles"},qe={style:{"text-align":"center",margin:"16px 0"}},he={class:"workflow-step"},Ue=ce({__name:"index",props:{visible:{type:Boolean},editData:{},mode:{}},emits:["update:visible","success"],setup(E,{emit:ee}){const p=E,Q=ee,q=G(p.visible);J(()=>p.visible,a=>q.value=a),J(q,a=>Q("update:visible",a));const W=O([]);ve().then(a=>{const t=a.data;W.splice(0,W.length,...t)}).catch(a=>{console.error("请求失败:",a)});const A=O([]);ge().then(a=>{const t=a.data;console.log("获取到的data值:",t),A.splice(0,A.length,...t)}).catch(a=>{console.error("请求失败:",a)});const te=()=>({name:"",passType:"",leaderId:null}),B=()=>({roles:[te()]}),o=O({name:"",scene:"",workflow_type:"0",description:"",is_active:!0,condition:{days:1,roles:[],equipment:[],borrow_types:[],team_type:[]},steps:[B()]}),L=O({name:[{required:!0,message:"请输入流程名称",trigger:"blur"}],workflow_type:[{required:!0,message:"请选择流程类型",trigger:"change"}],description:[{required:!0,message:"请输入流程描述",trigger:"blur"}],is_active:[{required:!0,message:"请输选择是否启用",trigger:"blur"}],"condition.days":[{required:!0,message:"请输入借用天数",trigger:"change"}],"condition.roles":[{required:!0,message:"请选择用户角色",trigger:"change"}],"condition.equipment":[{required:!1,message:"请选择设备标签",trigger:"change"}],"condition.borrow_types":[{required:!0,message:"请选择借用类型",trigger:"change"}],"condition.team_type":[{required:!0,message:"请选择借用方式",trigger:"change"}]}),H=G();function X(){o.steps.forEach((a,t)=>{a.roles.forEach((u,n)=>{L[`steps.${t}.roles.${n}.name`]=[{required:!0,message:"请选择角色",trigger:"change"}],L[`steps.${t}.roles.${n}.passType`]=[{required:!0,message:"请选择通过条件",trigger:"change"}]})})}const R=G("");J(()=>p.editData,async a=>{if(console.error("编辑时获取到的值val:",a),a){const t=JSON.parse(JSON.stringify(a));o.name=t.name||"",o.scene=t.scene||"",o.workflow_type=String(t.workflow_type??"0"),o.description=t.description||"",o.is_active=t.is_active??!0;const u=t.trigger_conditions||{};o.condition={days:1,roles:u.user_types||[],equipment:Array.isArray(u.equipment_categories)?u.equipment_categories[0]:"",borrow_types:u.borrow_types||[],team_type:u.team_type||[]};const n=await ye(t.id);n&&n.data?(R.value=n.data[0].id,o.steps=n.data.map(d=>({roles:[{name:d.step_name||"",passType:String(d.step_type??"1"),leaderId:d.leaderId||null}]}))):o.steps=[B()],X()}else o.name="",o.scene="",o.workflow_type="0",o.description="",o.is_active=!0,o.condition={days:1,roles:[],equipment:[],borrow_types:[],team_type:[]},o.steps=[B()];X(),await me()},{immediate:!0});function oe(){if(o.steps.length>=5){N.warning("最多只能添加 5 个审批步骤");return}o.steps.push(B())}function le(a){o.steps.length>1&&o.steps.splice(a,1)}function ae(a,t){o.steps[a].roles.length>1&&o.steps[a].roles.splice(t,1)}function Y(){q.value=!1}const se={管理员:1,指导老师:2};async function ne(){var n,d,g,V,h,$,m,U,C;try{await((n=H.value)==null?void 0:n.validate())}catch(r){console.warn("表单验证失败:",r);return}const a=!!p.editData,t={name:o.name,workflow_type:o.workflow_type,description:o.description,is_active:typeof o.is_active=="boolean"?o.is_active:!0,trigger_conditions:{equipment_categories:(d=o.condition)!=null&&d.equipment?[o.condition.equipment]:["贵重设备"],borrow_types:(V=(g=o.condition)==null?void 0:g.borrow_types)!=null&&V.length?o.condition.borrow_types:["0","1","2"],team_type:($=(h=o.condition)==null?void 0:h.team_type)!=null&&$.length?o.condition.team_type:["0","1"],user_types:(U=(m=o.condition)==null?void 0:m.roles)!=null&&U.length?o.condition.roles:["student","teacher"]}};let u="";if(a){console.log(R.value);const r=await ie(R.value,t);if(u=R.value,console.log(r),!r||r.code!==2e3){N.error("编辑流程失败");return}}else{const r=await de(t);if(u=(C=r==null?void 0:r.data)==null?void 0:C.id,!u){N.error("新增未能获取流程 ID");return}}for(let r=0;r<o.steps.length;r++){const y=o.steps[r],w=r+1,T=y.roles.map(c=>c.name).filter(Boolean),F=y.roles.map(c=>c.passType).filter(Boolean),j=y.roles.map(c=>c.leaderId).filter(Boolean),s=F[0]||"1",_=T.map(c=>se[c]).filter(Boolean),b={workflow:String(u),step_name:`${T.join(",")}审批`,step_order:w,step_type:s,description:`由${T.join(",")}进行审批`,approvers:[1],app_approvers:j.length>0?j:[],approver_roles:_,approver_depts:[],approval_conditions:{required_fields:[],value_ranges:{}},timeout_hours:24,timeout_action:"auto_reject",is_active:!0};console.log(`步骤 ${w} payload`,b),a?await pe(p.editData.id,b):await ue(b)}N.success("保存成功"),Q("success"),q.value=!1}return(a,t)=>{const u=i("el-input"),n=i("el-form-item"),d=i("el-col"),g=i("el-option"),V=i("el-select"),h=i("el-row"),$=i("el-divider"),m=i("el-checkbox"),U=i("el-checkbox-group"),C=i("el-card"),r=i("el-icon"),y=i("el-button"),w=i("el-radio"),T=i("el-radio-group"),F=i("el-form"),j=i("el-dialog");return f(),S(j,{title:a.editData?p.mode==="view"?"查看":"编辑":"新建审批流程",modelValue:q.value,"onUpdate:modelValue":t[8]||(t[8]=s=>q.value=s),width:"900px",onClose:Y},{footer:l(()=>[e(y,{onClick:Y},{default:l(()=>t[18]||(t[18]=[k("关闭")])),_:1}),p.mode!=="view"?(f(),S(y,{key:0,type:"primary",onClick:ne},{default:l(()=>t[19]||(t[19]=[k("提交")])),_:1})):x("",!0)]),default:l(()=>[e(F,{model:o,"label-width":"110px",rules:L,ref_key:"formRef",ref:H,disabled:p.mode==="view"},{default:l(()=>[e(h,{gutter:20},{default:l(()=>[e(d,{span:12},{default:l(()=>[e(n,{label:"流程名称",prop:"name"},{default:l(()=>[e(u,{modelValue:o.name,"onUpdate:modelValue":t[0]||(t[0]=s=>o.name=s),placeholder:"请输入"},null,8,["modelValue"])]),_:1})]),_:1}),e(d,{span:12},{default:l(()=>[e(n,{label:"流程类型",prop:"workflow_type"},{default:l(()=>[e(V,{modelValue:o.workflow_type,"onUpdate:modelValue":t[1]||(t[1]=s=>o.workflow_type=s),placeholder:"请选择流程类型",disabled:p.mode==="view"},{default:l(()=>[e(g,{label:"设备借用申请",value:"0"})]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1})]),_:1}),e(h,{gutter:20},{default:l(()=>[e(d,{span:12},{default:l(()=>[e(n,{label:"流程描述",prop:"description"},{default:l(()=>[e(u,{modelValue:o.description,"onUpdate:modelValue":t[2]||(t[2]=s=>o.description=s),type:"textarea",rows:2,placeholder:"请输入流程描述",disabled:p.mode==="view"},null,8,["modelValue","disabled"])]),_:1})]),_:1}),e(d,{span:12},{default:l(()=>[e(n,{label:"是否启用",prop:"is_active"},{default:l(()=>[e(V,{modelValue:o.is_active,"onUpdate:modelValue":t[3]||(t[3]=s=>o.is_active=s),placeholder:"请选择启用还是禁用",disabled:p.mode==="view"},{default:l(()=>[e(g,{label:"启用",value:!0}),e(g,{label:"禁用",value:!1})]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1})]),_:1}),e($,null,{default:l(()=>t[9]||(t[9]=[k("条件选择")])),_:1}),e(h,{gutter:20},{default:l(()=>[e(d,{span:8},{default:l(()=>[e(n,{label:"用户角色",prop:"condition.roles"},{default:l(()=>[e(U,{modelValue:o.condition.roles,"onUpdate:modelValue":t[4]||(t[4]=s=>o.condition.roles=s)},{default:l(()=>[e(m,{label:"教师",value:"teacher"}),e(m,{label:"学生",value:"student"}),e(m,{label:"非本院师生",value:"external"})]),_:1},8,["modelValue"])]),_:1})]),_:1}),e(d,{span:8},{default:l(()=>[e(n,{label:"设备标签",prop:"condition.equipment"},{default:l(()=>[e(V,{modelValue:o.condition.equipment,"onUpdate:modelValue":t[5]||(t[5]=s=>o.condition.equipment=s),placeholder:"请选择"},{default:l(()=>[(f(!0),D(z,null,M(A,(s,_)=>(f(),S(g,{key:_,label:s.name,value:s.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1})]),_:1}),e(d,{span:8},{default:l(()=>[e(n,{label:"借用类型",prop:"condition.borrow_types"},{default:l(()=>[e(U,{modelValue:o.condition.borrow_types,"onUpdate:modelValue":t[6]||(t[6]=s=>o.condition.borrow_types=s),disabled:p.mode==="view"},{default:l(()=>[e(m,{label:"常规借用",value:"0"}),e(m,{label:"课堂借用",value:"1"}),e(m,{label:"特殊借用",value:"2"})]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1}),e(d,{span:8},{default:l(()=>[e(n,{label:"借用方式",prop:"condition.team_type"},{default:l(()=>[e(U,{modelValue:o.condition.team_type,"onUpdate:modelValue":t[7]||(t[7]=s=>o.condition.team_type=s),disabled:p.mode==="view"},{default:l(()=>[e(m,{label:"个人借用",value:"0"}),e(m,{label:"团队借用",value:"1"})]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1})]),_:1}),e($,null,{default:l(()=>t[10]||(t[10]=[k("流程配置")])),_:1}),v("div",be,[v("div",we,[e(C,{shadow:"never",class:"step-card borrower"},{default:l(()=>t[11]||(t[11]=[v("div",{class:"step-title"},"借用人",-1)])),_:1}),t[12]||(t[12]=v("div",{class:"step-line"},null,-1))]),(f(!0),D(z,null,M(o.steps,(s,_)=>(f(),D("div",{class:"workflow-step",key:_},[e(C,{shadow:"never",class:"step-card"},{default:l(()=>[v("div",ke,[k(" 审批步骤"+_e(_+1)+" ",1),o.steps.length>1&&_!==0?(f(),S(y,{key:0,type:"danger",size:"small",onClick:b=>le(_),style:{"margin-left":"10px"}},{default:l(()=>[e(r,null,{default:l(()=>[e(K(Z))]),_:1}),t[13]||(t[13]=k(" 删除步骤 "))]),_:2},1032,["onClick"])):x("",!0)]),v("div",Ve,[(f(!0),D(z,null,M(s.roles,(b,c)=>(f(),D("div",{key:c,class:"role-row",style:{position:"relative",padding:"0 20px"}},[e(n,{label:"角色","label-position":"left","label-width":"100px",prop:`steps.${_}.roles.${c}.name`,rules:[{required:!0,message:"请选择角色",trigger:"change"}]},{default:l(()=>[e(V,{modelValue:b.name,"onUpdate:modelValue":I=>b.name=I,placeholder:"请选择角色",style:{width:"300px"}},{default:l(()=>[e(g,{label:"老师",value:"老师"}),e(g,{label:"管理员",value:"管理员"}),e(g,{label:"学院领导",value:"学院领导"})]),_:2},1032,["modelValue","onUpdate:modelValue"])]),_:2},1032,["prop"]),e(n,{label:"通过条件","label-position":"left",prop:`steps.${_}.roles.${c}.passType`,rules:[{required:!0,message:"请选择通过条件",trigger:"change"}]},{default:l(()=>[e(T,{modelValue:b.passType,"onUpdate:modelValue":I=>b.passType=I},{default:l(()=>[e(w,{label:"1名通过即可",value:"1"}),e(w,{label:"所有人员通过",value:"2"}),e(w,{label:"部门负责人审批",value:"3"}),e(w,{label:"角色审批",value:"4"}),e(w,{label:"自动审批",value:"5"})]),_:2},1032,["modelValue","onUpdate:modelValue"])]),_:2},1032,["prop"]),s.roles.length>1&&c!==0?(f(),S(y,{key:0,type:"danger",size:"small",onClick:I=>ae(_,c),style:{position:"absolute",right:"0",top:"0"}},{default:l(()=>[e(r,null,{default:l(()=>[e(K(Z))]),_:1}),t[14]||(t[14]=k(" 删除角色 "))]),_:2},1032,["onClick"])):x("",!0)]))),128))])]),_:2},1024),t[15]||(t[15]=v("div",{class:"step-line"},null,-1))]))),128)),v("div",qe,[p.mode!=="view"?(f(),S(y,{key:0,type:"primary",onClick:oe,disabled:o.steps.length>=5},{default:l(()=>[e(r,null,{default:l(()=>[e(K(re))]),_:1}),t[16]||(t[16]=k(" 添加审批步骤 "))]),_:1},8,["disabled"])):x("",!0)]),v("div",he,[e(C,{shadow:"never",class:"step-card done"},{default:l(()=>t[17]||(t[17]=[v("div",{class:"step-title"},"审批完成",-1)])),_:1})])])]),_:1},8,["model","rules","disabled"])]),_:1},8,["title","modelValue"])}}}),De=fe(Ue,[["__scopeId","data-v-9214eb32"]]);export{De as default};
|