import{r as g,E as p,H as I}from"./index.BKEMpsLA.js";import{a as h,r as m,q as j,aj as n,c as U,o as w,S as l,K as o,b as c,Q as A,P as _,R as F,a9 as H,u as J,J as K}from"./vue.YrNK8sx4.js";import{_ as L}from"./_plugin-vue_export-helper.DlAUqK2U.js";const Q=[{value:1,label:"学院"},{value:2,label:"系部"},{value:3,label:"年级"},{value:4,label:"班级/组别"}];function Y(){return g({url:"/api/system/organization/tree/",method:"get"})}function W(u){return g({url:"/api/system/organization/",method:"post",data:{...u}})}function X(u,v){return g({url:`/api/system/organization/${u}/`,method:"put",data:{...v}})}function Z(u){return g({url:`/api/system/organization/${u}/`,method:"delete"})}const ee={class:"organization-container"},le={class:"card-header"},te={class:"custom-tree-node"},oe={class:"dialog-footer"},ae=h({__name:"index",setup(u){const v=m([]),d=m(!1),f=m("add"),x=m(null),O={children:"children",label:"name"},y=m(),a=m({name:"",code:"",org_type:1,parent:null,sort_order:0,description:"",is_active:!0}),q={name:[{required:!0,message:"请输入机构名称",trigger:"blur"}],code:[{required:!0,message:"请输入机构编码",trigger:"blur"}],org_type:[{required:!0,message:"请选择机构类型",trigger:"change"}],sort_order:[{required:!0,message:"请输入排序号",trigger:"blur"}]},b=async()=>{try{const r=await Y();v.value=r.data}catch(r){console.error("获取组织机构树失败:",r),p.error("获取组织机构树失败")}},C=r=>{f.value="add",a.value={name:"",code:"",org_type:r?r.org_type===1?2:r.org_type===2?3:4:1,parent:(r==null?void 0:r.id)||null,sort_order:0,description:"",is_active:!0},d.value=!0},E=r=>{f.value="edit",x.value=r,a.value={...r},d.value=!0},T=async(r,e)=>{try{await I.confirm("确认删除该组织机构吗？","提示",{type:"warning"}),await Z(e.id),p.success("删除成功"),await b()}catch(s){s!=="cancel"&&(console.error("删除失败:",s),p.error("删除失败"))}},$=async()=>{if(y.value)try{await y.value.validate(),f.value==="add"?(await W(a.value),p.success("新增成功")):(await X(x.value.id,a.value),p.success("更新成功")),d.value=!1,await b()}catch(r){console.error("提交失败:",r),p.error("提交失败")}};return j(()=>{b()}),(r,e)=>{const s=n("el-button"),B=n("el-tree"),D=n("el-card"),V=n("el-input"),i=n("el-form-item"),N=n("el-option"),P=n("el-select"),R=n("el-input-number"),S=n("el-switch"),M=n("el-form"),G=n("el-dialog");return w(),U("div",ee,[l(D,{class:"box-card"},{header:o(()=>[c("div",le,[e[9]||(e[9]=c("span",null,"组织架构管理",-1)),l(s,{type:"primary",onClick:C},{default:o(()=>e[8]||(e[8]=[_("新增组织架构")])),_:1})])]),default:o(()=>[l(B,{data:v.value,props:O,"node-key":"id","default-expand-all":"","expand-on-click-node":!1},{default:o(({node:t,data:k})=>[c("span",te,[c("span",null,A(t.label),1),c("span",null,[l(s,{link:"",type:"primary",onClick:z=>C(k)},{default:o(()=>e[10]||(e[10]=[_(" 添加子级 ")])),_:2},1032,["onClick"]),l(s,{link:"",type:"primary",onClick:z=>E(k)},{default:o(()=>e[11]||(e[11]=[_(" 编辑 ")])),_:2},1032,["onClick"]),l(s,{link:"",type:"danger",onClick:z=>T(t,k)},{default:o(()=>e[12]||(e[12]=[_(" 删除 ")])),_:2},1032,["onClick"])])])]),_:1},8,["data"])]),_:1}),l(G,{modelValue:d.value,"onUpdate:modelValue":e[7]||(e[7]=t=>d.value=t),title:f.value==="add"?"新增组织架构":"编辑组织架构",width:"500px"},{footer:o(()=>[c("span",oe,[l(s,{onClick:e[6]||(e[6]=t=>d.value=!1)},{default:o(()=>e[13]||(e[13]=[_("取消")])),_:1}),l(s,{type:"primary",onClick:$},{default:o(()=>e[14]||(e[14]=[_(" 确定 ")])),_:1})])]),default:o(()=>[l(M,{ref_key:"formRef",ref:y,model:a.value,rules:q,"label-width":"100px"},{default:o(()=>[l(i,{label:"组织名称",prop:"name"},{default:o(()=>[l(V,{modelValue:a.value.name,"onUpdate:modelValue":e[0]||(e[0]=t=>a.value.name=t),placeholder:"请输入组织名称"},null,8,["modelValue"])]),_:1}),l(i,{label:"组织编码",prop:"code"},{default:o(()=>[l(V,{modelValue:a.value.code,"onUpdate:modelValue":e[1]||(e[1]=t=>a.value.code=t),placeholder:"请输入组织编码"},null,8,["modelValue"])]),_:1}),l(i,{label:"组织类型",prop:"org_type"},{default:o(()=>[l(P,{modelValue:a.value.org_type,"onUpdate:modelValue":e[2]||(e[2]=t=>a.value.org_type=t),placeholder:"请选择组织类型"},{default:o(()=>[(w(!0),U(F,null,H(J(Q),t=>(w(),K(N,{key:t.value,value:t.value,label:t.label},null,8,["value","label"]))),128))]),_:1},8,["modelValue"])]),_:1}),l(i,{label:"排序",prop:"sort_order"},{default:o(()=>[l(R,{modelValue:a.value.sort_order,"onUpdate:modelValue":e[3]||(e[3]=t=>a.value.sort_order=t),min:1},null,8,["modelValue"])]),_:1}),l(i,{label:"描述",prop:"description"},{default:o(()=>[l(V,{modelValue:a.value.description,"onUpdate:modelValue":e[4]||(e[4]=t=>a.value.description=t),type:"textarea",placeholder:"请输入描述"},null,8,["modelValue"])]),_:1}),l(i,{label:"是否启用",prop:"is_active"},{default:o(()=>[l(S,{modelValue:a.value.is_active,"onUpdate:modelValue":e[5]||(e[5]=t=>a.value.is_active=t)},null,8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue","title"])])}}}),ue=L(ae,[["__scopeId","data-v-5de41d05"]]);export{ue as default};
