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