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