import{V as x,n as y,r as B,I as T,F as j,W as C}from"./index.17037962789732.js";import"./index.170379627897337.js";import"./index.170379627897315.js";import"./index.170379627897318.js";import"./index.170379627897319.js";import"./index.170379627897314.js";import"./index.170379627897326.js";import"./index.170379627897316.js";import"./index.170379627897317.js";import{u as V,e as w}from"./department.1703796278973.js";import{d as L,k as f,l as U,v as q,V as E,o as F,c as R,a as i,b as d,u as n,t as A,A as J}from"./vue.1703796278973.js";const X=L({__name:"EditDepartmentDialog",props:{treeData:null,data:null,visible:{type:Boolean}},emits:["refresh","update:visible"],setup(g,{emit:c}){const r=g,u=f(""),m=f(!1),b=()=>{var a;m.value=!0,(a=p.value)==null||a.validate().then(()=>t.submit()).then(e=>{c("refresh",e.result.id),c("update:visible",!1)}).finally(()=>m.value=!1)},_=U(()=>{if(!r.data.id)return r.treeData;const a=x(r.treeData),e=v(a,r.data.id);return e.disabled=!0,e.children&&e.children.length>0&&h(e.children),a}),v=(a,e)=>{let s=null;for(const l of a){if(l.id===e)return l;if(l.children&&l.children.length>0&&(s=v(l.children,e),s))return s}return null},h=a=>{a.length<1||a.forEach(e=>{e.disabled=!0,e.children&&e.children.length>0&&h(e.children)})},p=f(),t=q({data:{},beforeSortIndex:"",init:()=>{r.data.id?(u.value="编辑",t.data=x(r.data)):r.data.parentId?(u.value="新增子组织",t.data={name:"",sortIndex:r.data.sortIndex,parentId:r.data.parentId}):(u.value="新增",t.data={name:"",sortIndex:r.data.sortIndex}),t.beforeSortIndex=t.data.sortIndex,E(()=>{var a;(a=p.value)==null||a.clearValidate()})},checkSort:a=>{const e=a.target.value.match(/^[1-9]*/)[0];e?(t.data.sortIndex=e,t.beforeSortIndex=e):t.data.sortIndex=t.beforeSortIndex},submit:()=>(t.data.id?V:w)(t.data)});t.init();const D=()=>{const a=_.value.find(e=>e.id===t.data.parentId);t.data.sortIndex=a!=null&&a.children?a.children[a.children.length-1].sortIndex+1:1};return(a,e)=>{const s=y,l=B,I=T,k=j,S=C;return F(),R(S,{visible:"",title:n(u),width:"520px",onCancel:e[3]||(e[3]=o=>c("update:visible",!1)),onOk:b,class:"edit-dialog-container",cancelText:"取消",okText:"确定",confirmLoading:n(m)},{default:i(()=>[d(k,{ref_key:"formRef",ref:p,model:n(t).data,layout:"vertical"},{default:i(()=>[d(l,{name:"parentId",label:"上级组织"},{default:i(()=>[d(s,{value:n(t).data.parentId,"onUpdate:value":e[0]||(e[0]=o=>n(t).data.parentId=o),style:{width:"100%"},placeholder:"请选择上级组织","tree-data":n(_),"field-names":{value:"id"},onChange:D},{title:i(({name:o})=>[A(J(o),1)]),_:1},8,["value","tree-data"])]),_:1}),d(l,{name:"name",label:"名称",rules:[{required:!0,message:"请输入名称"},{max:64,message:"最多可输入64个字符"}]},{default:i(()=>[d(I,{value:n(t).data.name,"onUpdate:value":e[1]||(e[1]=o=>n(t).data.name=o),placeholder:"请输入名称"},null,8,["value"])]),_:1}),d(l,{name:"sortIndex",label:"排序",rules:[{required:!0,message:"请输入排序"}]},{default:i(()=>[d(I,{value:n(t).data.sortIndex,"onUpdate:value":e[2]||(e[2]=o=>n(t).data.sortIndex=o),placeholder:"请输入排序",maxlength:64,onBlur:n(t).checkSort},null,8,["value","onBlur"])]),_:1})]),_:1},8,["model"])]),_:1},8,["title","confirmLoading"])}}});export{X as _};
