import{a2 as e,e as t,r as l,Q as c,T as a,f as s,g as i,o,h,w as r,i as n,W as u,a as d,j as C,t as f,k,F as p,l as S,A as y,N as v,z as m,S as _}from"./index-Cg3FU-dV.js";import{_ as L}from"./uni-popup.B818XS1j.js";/* empty css */import{_ as g}from"./_plugin-vue_export-helper.BCo6x5W8.js";const w=g({__name:"index",props:{valueKey:{type:String,default:"id"},textKey:{type:String,default:"name"},childrenKey:{type:String,default:"children"},localdata:{type:Array,default:function(){return[]}},localTreeList:{type:Array,default:function(){return[]}},selectedData:{type:Array,default:function(){return[]}},title:{type:String,default:""},multiple:{type:Boolean,default:!0},selectParent:{type:Boolean,default:!0},selectShow:{type:Boolean,default:!1},confirmColor:{type:String,default:""},cancelColor:{type:String,default:""},titleColor:{type:String,default:""},switchColor:{type:String,default:""},border:{type:Boolean,default:!1}},emits:["cancel","select-change"],setup(g,{expose:w,emit:x}){const P=g,{valueKey:b,textKey:I,childrenKey:j,localdata:A,localTreeList:K,selectedData:B,title:E,multiple:D,selectParent:T,selectShow:Q,confirmColor:z,cancelColor:F,titleColor:N,switchColor:O,border:R}=e(P),U=t({showDialog:!1,treeList:[],selectedId:0}),W=x,q=l(null),G=()=>{q.value.close()},H=()=>{G(),W("cancel")},J=()=>{let e,t=[],l=-1;U.treeList.forEach(((c,a)=>{l>=0&&c.level>l||(2===c.checkStatus?(l=c.level,t.push(c.id),e=e?e+" / "+c.name:c.name):l=-1)})),t.length<=0||(G(),Z(),W("select-change",t))},M=(e=[],t=0,l,c=!0)=>{let a=0,s=-1,i=0;l&&(a=U.treeList.findIndex((e=>e.id===l.id))+1,s=l.id,i=D.value&&2==l.checkStatus?2:0),e.forEach((e=>{let l=!0;if(e&&e[j.value]){let t=e[j.value];Array.isArray(t)&&t.length>0&&(l=!1)}let o={id:e[b.value],name:e[I.value],level:t,isLastLevel:l,isShow:c,isShowChild:!1,checkStatus:i,orCheckStatus:0,parentId:s,children:e[j.value],childCount:e[j.value]?e[j.value].length:0,childCheckCount:0,childCheckPCount:0};B.value.indexOf(o.id)>=0&&(o.checkStatus=2,o.orCheckStatus=2,o.childCheckCount=o.children?o.children.length:0,Y(o)),U.treeList.splice(a,0,o),a++}))},V=(e,t)=>{const l=t+1;if(l>0)for(var c=l;ce.level))return;e.isShowChild?t.parentId===e.id&&(t.isShow=e.isShowChild,t.isShow||(t.isShowChild=!1)):(t.isShow=e.isShowChild,t.isShowChild=!1)}},X=(e,t)=>{if(e.childCount&&e.childCount>0)for(t++;te.level;){let l=U.treeList[t];l.checkStatus=e.checkStatus,2==l.checkStatus?(l.childCheckCount=l.childCount,l.childCheckPCount=0):0==l.checkStatus&&(l.childCheckCount=0,l.childCheckPCount=0),t++}},Y=(e,t,l)=>{const c=U.treeList.findIndex((t=>t.id==e.parentId));if(c>=0){let t=U.treeList[c];t.childCheckCount;let a=t.checkStatus;1==l?t.childCheckPCount-=1:2==l&&(t.childCheckCount-=1),1==e.checkStatus?t.childCheckPCount+=1:2==e.checkStatus&&(t.childCheckCount+=1),t.childCheckCount<=0&&t.childCheckPCount<=0?(t.childCheckCount=0,t.childCheckPCount=0,t.checkStatus=0):t.childCheckCount>=t.childCount?(t.childCheckCount=t.childCount,t.childCheckPCount=0,t.checkStatus=2):t.checkStatus=1,Y(t,c,a)}},Z=()=>{U.treeList.forEach(((e,t)=>{U.treeList[t].checkStatus=e.orCheckStatus})),U.selectedId=0},$=()=>{U.treeList=[],M(A.value)};return c((()=>{$()})),a((()=>[A,K]),((e,t)=>{const l=e[0].value,c=e[1].value;l&&$(),c.length>0&&(U.treeList=c)}),{deep:!0,immediate:!0}),w({show:()=>{q.value.open()}}),(e,t)=>{const l=m,c=_,a=s(i("uni-popup"),L);return o(),h(l,null,{default:r((()=>[n(a,{ref_key:"popupRef",ref:q,type:"bottom","mask-click":!1},{default:r((()=>[n(l,{class:"tree-dialog"},{default:r((()=>[n(l,{class:"tree-bar"},{default:r((()=>[n(l,{class:"tree-bar-cancel",style:u({color:d(F)}),"hover-class":"hover-c",onClick:H},{default:r((()=>[C("取消")])),_:1},8,["style"]),n(l,{class:"tree-bar-title",style:u({color:d(N)})},{default:r((()=>[C(f(d(E)),1)])),_:1},8,["style"]),n(l,{class:"tree-bar-confirm",style:u({color:d(z)}),"hover-class":"hover-c",onClick:J},{default:r((()=>[C("确定")])),_:1},8,["style"])])),_:1}),n(l,{class:"tree-view"},{default:r((()=>[n(c,{class:"tree-list","scroll-y":!0},{default:r((()=>[n(l,{class:"tree-list-content"},{default:r((()=>[(o(!0),k(p,null,S(U.treeList,((e,t)=>(o(),h(l,{key:t,class:y(["tree-item",{itemBorder:!0===d(R),show:e.isShow}]),style:u([{paddingLeft:30*e.level+"rpx"}])},{default:r((()=>[n(l,{class:"item-label"},{default:r((()=>[n(l,{class:"item-icon",onClick:l=>((e,t)=>{!0!==e.isLastLevel&&(e.isShowChild=!e.isShowChild,e.children?(M(e.children,e.level+1,e),e.children=void 0):V(e,t))})(e,t)},{default:r((()=>[e.isLastLevel?v("",!0):(o(),h(l,{key:0,class:"iconfont icon-jinru-copy",style:u({transform:!e.isLastLevel&&e.isShowChild?"rotate(90deg)":"rotate(0)"})},null,8,["style"]))])),_:2},1032,["onClick"]),n(l,{class:"uni-flex-item",onClick:l=>((e,t)=>{if(U.selectedId=e.id,!D.value)return e.checkStatus=0==e.checkStatus?2:0,U.treeList.forEach(((e,l)=>{U.treeList[l].checkStatus=l!=t?0:2})),[].push(e.id),void e.name;let l=e.checkStatus;switch(l){case 0:e.checkStatus=2,e.childCheckCount=e.childCount,e.childCheckPCount=0;break;case 1:case 2:e.checkStatus=0,e.childCheckCount=0,e.childCheckPCount=0}X(e,t),Y(e,t,l)})(e,t)},{default:r((()=>[n(l,{class:y(["item-name",e.id===U.selectedId?"active":""])},{default:r((()=>[C(f(e.name),1)])),_:2},1032,["class"]),v("",!0)])),_:2},1032,["onClick"])])),_:2},1024)])),_:2},1032,["style","class"])))),128))])),_:1})])),_:1})])),_:1})])),_:1})])),_:1},512)])),_:1})}}},[["__scopeId","data-v-5434b5cd"]]);export{w as b};