import{l as U,U as L,A as q}from"./api.f6d3ac4b.js";import{O}from"./index.ad3efb29.js";import{G as T}from"./elementPlus.4833989a.js";import{d as j,r as c,Z as D,j as B,ai as u,o as M,M as N,O as d,U as o,u as t,S as V,T as z}from"./vue.adf17aba.js";import{_ as A}from"./_plugin-vue_export-helper.c27b6911.js";import"./echarts.72dc8373.js";const R=j({__name:"index",props:{initFormData:{default:()=>null},treeData:{default:()=>[]},cacheData:{default:()=>[]}},emits:["drawerClose"],setup(g,{emit:w}){const k={children:"children",label:"name",value:"id",isLeaf:(l,e)=>!(e!=null&&e.data.hasChild)},p=c(),v=D({name:[{required:!0,message:"部门名称必填",trigger:"blur"}],key:[{required:!0,message:"部门标识必填",trigger:"blur"}]}),n=g,F=w;let _=c([]),a=D({key:"",parent:"",name:"",owner:"",description:""}),f=c(!1);const h=()=>{var l,e;(l=n.initFormData)!=null&&l.id&&(a.id=(e=n.initFormData)==null?void 0:e.id,a.key=n.initFormData.key||"",a.parent=n.initFormData.parent||"",a.name=n.initFormData.name||"",a.owner=n.initFormData.owner||"",a.description=n.initFormData.description||"")},x=(l,e)=>{l.level!==0&&U({parent:l.data.id}).then(r=>{e(r.data)})},C=()=>{var l;(l=p.value)==null||l.validate(async e=>{if(e)try{let r;f.value=!0,a.id?r=await L(a):r=await q(a),(r==null?void 0:r.code)===2e3&&(O(r.msg),y("submit"))}finally{f.value=!1}})},y=(l="")=>{var e;F("drawerClose",l),(e=p.value)==null||e.resetFields()};return B(async()=>{n.treeData.map(l=>{_.value.push(l)}),h()}),(l,e)=>{const r=u("el-tree-select"),s=u("el-form-item"),m=u("el-input"),b=u("el-button");return M(),N(t(T),{ref_key:"formRef",ref:p,rules:v,model:t(a),"label-width":"100px","label-position":"right",class:"dept-form-com"},{default:d(()=>[o(s,{label:"父级部门",prop:"parent"},{default:d(()=>[o(r,{modelValue:t(a).parent,"onUpdate:modelValue":e[0]||(e[0]=i=>t(a).parent=i),props:k,data:t(_),"cache-data":n.cacheData,lazy:"","check-strictly":"",load:x,style:{width:"100%"}},null,8,["modelValue","data","cache-data"])]),_:1}),o(s,{required:"",label:"部门名称",prop:"name"},{default:d(()=>[o(m,{modelValue:t(a).name,"onUpdate:modelValue":e[1]||(e[1]=i=>t(a).name=i)},null,8,["modelValue"])]),_:1}),o(s,{required:"",label:"部门标识",prop:"key"},{default:d(()=>[o(m,{modelValue:t(a).key,"onUpdate:modelValue":e[2]||(e[2]=i=>t(a).key=i)},null,8,["modelValue"])]),_:1}),o(s,{label:"负责人"},{default:d(()=>[o(m,{modelValue:t(a).owner,"onUpdate:modelValue":e[3]||(e[3]=i=>t(a).owner=i)},null,8,["modelValue"])]),_:1}),o(s,{label:"备注"},{default:d(()=>[o(m,{modelValue:t(a).description,"onUpdate:modelValue":e[4]||(e[4]=i=>t(a).description=i),maxlength:"200","show-word-limit":"",type:"textarea"},null,8,["modelValue"])]),_:1}),o(s,null,{default:d(()=>[o(b,{onClick:C,type:"primary",loading:t(f)},{default:d(()=>[V(z(t(a).id?"保存":"新增"),1)]),_:1},8,["loading"]),o(b,{onClick:y},{default:d(()=>[V("取消 ")]),_:1})]),_:1})]),_:1},8,["rules","model"])}}});const H=A(R,[["__scopeId","data-v-b0f4a7b9"]]);export{H as default};
