import{d as N,O as j,k as m,v as U,m as R,r as J,o as I,x as q,b as r,a as l,u as a,M as P,z as k,t as z,c as D,A as F,B as G}from"./vue.1703796278973.js";import{aO as H,V as M,o as Q,M as W,I as X,aL as Y,a as Z,aA as ee}from"./index.17037962789732.js";import"./index.1703796278973303.js";import"./index.170379627897317.js";import"./index.1703796278973304.js";import"./index.170379627897314.js";import"./index.170379627897315.js";import{_ as T}from"./index.vue_vue_type_script_setup_true_name_PermissionButton_lang.1703796278973.js";import{g as te,h as se}from"./department.1703796278973.js";import{A as L}from"./utils.1703796278973.js";import{_ as ne}from"./EditDepartmentDialog.vue_vue_type_script_setup_true_lang.1703796278973.js";import{_ as oe}from"./_plugin-vue_export-helper.1703796278973.js";import"./index.17037962789733.js";import"./dayjs.min.1703796278973.js";import"./isArray.1703796278973.js";import"./editor.api.1703796278973.js";import"./preload-helper.1703796278973.js";import"./monaco.contribution.1703796278973.js";import"./index.170379627897320.js";import"./index.170379627897321.js";import"./permission.1703796278973.js";import"./system.1703796278973.js";import"./comm.1703796278973.js";import"./index.170379627897332.js";import"./index.170379627897333.js";import"./index.170379627897334.js";import"./default.1703796278973.js";import"./consts.1703796278973.js";import"./404.1703796278973.js";import"./moment.1703796278973.js";import"./index.170379627897337.js";import"./index.170379627897318.js";import"./index.170379627897319.js";import"./index.170379627897326.js";import"./index.170379627897316.js";const ae={class:"left-tree-container"},ie={class:"add-btn"},re={class:"tree"},le=N({__name:"LeftTree",emits:["change"],setup(pe,{emit:E}){const v="system/Department",K=j().query.save,p=m(""),C=m(!1),w=m([]),u=new Map,d=m([]),f=m([]),y=m([]);function b(t){C.value=!0;const e={paging:!1,sorts:[{name:"sortIndex",order:"asc"}]};p.value&&(e.terms=[{column:"name$LIKE",value:`%${p.value}%`}]),te(e).then(s=>{f.value=[s.result[0].id],w.value=s.result.sort((o,n)=>o.sortIndex===n.sortIndex?n.createTime-o.createTime:o.sortIndex-n.sortIndex),A(s.result),d.value=s.result,t&&t()}).finally(()=>{C.value=!1})}const O=H(()=>{const t=p.value,e=new Map;if(t){const o=[];u.forEach(n=>{n.name.includes(t)&&(o.push(n.parentId),e.set(n.id,n))}),s(o),d.value=L(M([...e.values()]))}else d.value=L(M([...u.values()])),y.value=[];function s(o){const n=[];o.length&&o.forEach(_=>{if(u.has(_)){const g=u.get(_);n.push(g.parentId),e.set(_,g)}})}},500);function A(t){t&&t.map(e=>{u.set(e.id,Q(M(e),["children"])),e.children&&A(e.children)})}function S(t){se(t).then(()=>{W.success("操作成功"),b()})}function V(t){window!=null&&window.onTabSaveSuccess&&window.onTabSaveSuccess(t),setTimeout(()=>window.close(),300),b()}const c=U({visible:!1,selectItem:{}}),h=(t={})=>{let e=t.sortIndex||1;if(!t.id){let s=[];t.parentId?s=t.children:s=d.value;const o=(s==null?void 0:s.length)>0?s==null?void 0:s.map(n=>n.sortIndex):[0];e=Math.max(...o)+1}c.selectItem={...t,sortIndex:e},c.visible=!0};B();function B(){b(K?h:void 0),R(f,t=>{E("change",t[0])})}return(t,e)=>{const s=J("AIcon"),o=X,n=Y,_=Z,g=ee;return I(),q("div",ae,[r(o,{value:a(p),"onUpdate:value":e[0]||(e[0]=i=>P(p)?p.value=i:null),onChange:a(O),placeholder:"请输入组织名称",class:"search-input",allowClear:""},{suffix:l(()=>[r(s,{type:"SearchOutlined"})]),_:1},8,["value","onChange"]),k("div",ie,[r(T,{type:"primary",class:"add-btn",hasPermission:`${v}:add`,onClick:e[1]||(e[1]=i=>h())},{default:l(()=>[z(" 新增 ")]),_:1},8,["hasPermission"])]),k("div",re,[r(g,{spinning:a(C)},{default:l(()=>[a(d).length>0?(I(),D(n,{key:0,"tree-data":a(d),"selected-keys":a(f),"onUpdate:selected-keys":e[3]||(e[3]=i=>P(f)?f.value=i:null),expandedKeys:a(y),"onUpdate:expandedKeys":e[4]||(e[4]=i=>P(y)?y.value=i:null),fieldNames:{key:"id"}},{title:l(({name:i,data:x})=>[k("span",null,F(i),1),k("span",{class:"func-btns",onClick:e[2]||(e[2]=$=>$.stopPropagation())},[r(T,{hasPermission:`${v}:update`,type:"link",tooltip:{title:"编辑"},onClick:$=>h(x)},{default:l(()=>[r(s,{type:"EditOutlined"})]),_:2},1032,["hasPermission","onClick"]),r(T,{hasPermission:`${v}:add`,type:"link",tooltip:{title:"新增子组织"},onClick:$=>h({...x,id:"",parentId:x.id})},{default:l(()=>[r(s,{type:"PlusCircleOutlined"})]),_:2},1032,["hasPermission","onClick"]),r(T,{type:"link",hasPermission:`${v}:delete`,tooltip:{title:"删除"},popConfirm:{title:"确定要删除吗",onConfirm:()=>S(x.id)}},{default:l(()=>[r(s,{type:"DeleteOutlined"})]),_:2},1032,["hasPermission","popConfirm"])])]),_:1},8,["tree-data","selected-keys","expandedKeys"])):(I(),D(_,{key:1,description:"暂无数据"}))]),_:1},8,["spinning"])]),a(c).visible?(I(),D(ne,{key:0,visible:a(c).visible,"onUpdate:visible":e[5]||(e[5]=i=>a(c).visible=i),"tree-data":a(w),data:a(c).selectItem,onRefresh:V},null,8,["visible","tree-data","data"])):G("",!0)])}}});const ze=oe(le,[["__scopeId","data-v-2d82c378"]]);export{ze as default};
