import{_ as F,a as J,r as h,o as v,y as _,q as d,v as I,p as u,P as R,x as C,n,s as $,t as N,e8 as U,j,br as z,l as A,bv as W,D as G}from"./index.8d733f79.js";import{E as H}from"./el-text.54dc8292.js";import{a as Q,n as X,b as Y,f as Z}from"./deviceTree.170dfbd9.js";const ee={class:"wrap"},te={class:"dialog-footer"},le={__name:"selectDeviceTree",emits:["selectDevice"],setup(ae,{expose:V,emit:E}){const{proxy:o}=G(),f=J(),g={children:"children",label:"label",isLeaf:"leaf"},c=h(!1),r=h(""),s=h([]);let i,p=[],y=!0;function S(e){c.value=!0,r.value="",s.value=[],p=e,f.query.deviceId&&y?w():k()}const k=()=>{Q({isLinkSensor:!0}).then(e=>{s.value=e.data||[],setTimeout(()=>{o.$refs.treeRef.setCheckedKeys(p)},0)})},w=()=>{X({id:f.query.deviceId,isLinkSensor:!0,level:2}).then(e=>{s.value=e.data||[];const t=T(s.value,f.query.deviceId);console.log("kkkk",t),setTimeout(()=>{for(let l=t.length-1;l>=0;l--)o.$refs.treeRef.updateKeyChildren(t[l].id,t[l].children)},0),setTimeout(()=>{o.$refs.treeRef.setCheckedKeys([t[0].id]),o.$refs.treeRef.setCurrentKey(t[0].id)},200),setTimeout(()=>{o.$refs.scrollbarRef.update(),document.getElementsByClassName("el-tree-node is-checked")[0].scrollIntoView({block:"center",inline:"nearest"})},1e3)})};function T(e,t){for(let l=0;l<e.length;l++){if(e[l].deviceId===+t)return[e[l]];if(e[l].children.length>0){const a=T(e[l].children,t);if(a)return a.concat(e[l])}}return null}function K(){setTimeout(()=>{o.$refs.scrollbarRef.update()},500)}const B=(e,t)=>{console.log("loadNode",e),!(e.data instanceof Array)&&Y({nodeId:e.data.id,isLinkSensor:!0}).then(l=>{for(let a=0;a<l.data.length;a++)l.data[a].level===2&&(l.data[a].leaf=!0);t(l.data||[])})},L=()=>{i&&(clearTimeout(i),i=null),i=setTimeout(()=>{q()},500)};function q(){s.value=[],r.value?Z({keyWord:r.value}).then(e=>{b(e.data),s.value=e.data||[],setTimeout(()=>{o.$refs.treeRef.setCheckedKeys(p)},0)}):k()}const b=e=>{e.forEach(t=>{var l;t.level===2?(t.children=[],t.leaf=!0):(l=t.children)!=null&&l.length&&b(t.children)})},M=()=>{let e=[];r.value?e=o.$refs.treeRef.getCheckedKeys(!0):e=o.$refs.treeRef.getCheckedKeys(),U(e).then(t=>{t.data&&E("selectDevice",t.data,e),D()}),y=!1},D=()=>{c.value=!1};return V({showModal:S}),(e,t)=>{const l=j,a=H,O=z,x=A,P=W;return v(),_(P,{title:e.$t("selectDevice"),modelValue:n(c),"onUpdate:modelValue":t[1]||(t[1]=m=>$(c)?c.value=m:null),width:"400px","align-center":!0},{footer:d(()=>[I("div",te,[u(x,{onClick:D},{default:d(()=>[R(C(e.$t("cancel")),1)]),_:1}),u(x,{type:"primary",onClick:M},{default:d(()=>[R(C(e.$t("confirm")),1)]),_:1})])]),default:d(()=>[I("div",ee,[u(l,{modelValue:n(r),"onUpdate:modelValue":t[0]||(t[0]=m=>$(r)?r.value=m:null),modelModifiers:{trim:!0},placeholder:e.$t("inputP"),style:{"margin-bottom":"16px"},clearable:"","suffix-icon":"Search",onInput:L},null,8,["modelValue","placeholder"]),u(O,{style:{flex:"1",height:"0"},ref:"scrollbarRef"},{default:d(()=>[n(r)?N("",!0):(v(),_(a,{key:0,lazy:"",load:B,ref:"treeRef",props:g,"show-checkbox":"","node-key":"id",data:n(s),"default-expand-all":!1,onNodeExpand:K},null,8,["data"])),n(r)?(v(),_(a,{key:1,ref:"treeRef",props:g,"show-checkbox":"","node-key":"id",data:n(s),"default-expand-all":""},null,8,["data"])):N("",!0)]),_:1},512)])]),_:1},8,["title","modelValue"])}}},ne=F(le,[["__scopeId","data-v-bf58e0e5"]]);export{ne as default};
