import{_ as q,b as J,a as U,u as z,r as u,w as F,e as G,J as H,$ as Q,o as I,c as $,v as K,n as d,x as b,p as v,q as w,s as A,O as W,D as X,ak as Y,j as Z}from"./index.8d733f79.js";import{_ as ee}from"./dialogContent.8cf6deaf.js";import{E as te}from"./el-text.54dc8292.js";import{w as ae}from"./setValue.1d09ba51.js";const le={key:0,style:{display:"inline-block"}},re={key:1,style:{display:"inline-block"}},oe={__name:"treeSelect",props:{modelValue:Boolean,targetLevel:Number,targetId:String,placeholder:{type:String,default:"\u8BF7\u9009\u62E9"}},emits:["ensureId"],setup(B,{expose:R,emit:N}){const s=B,{t:m,locale:ne}=J(),V={children:"children",label:"label"},y={0:"factoryId",1:"organizationId",2:"deviceId"};U(),z();const{proxy:r}=X(),i=u(!1),p=u([]),P=u(""),l=u({}),o=u({}),h=u("");u([]);const g=u();F(h,e=>{r.$refs.treeRef.filter(e)}),G(()=>{T()});function S(e){i.value=!0,P.value=e.id,l.value.id&&setTimeout(()=>{r.$refs.treeRef.setCurrentKey(l.value.id),g.value=l.value.id},0)}const T=async()=>{const e=await ae({userId:H.session.getJSON("userInfo").id});e.data.length?(x(e.data),p.value=e.data,s.targetId?l.value=D(p.value,s.targetId):l.value=k(p.value),!l.value||JSON.stringify(l.value)==="{}"?r.$modal.msgError(m("noData")):N("ensureId",l.value[y[s.targetLevel]],l.value)):r.$modal.msgError(m("noData"))},L=e=>{if(e.level===5){r.$refs.treeRef.setCurrentKey(g.value);return}g.value=e.id,o.value=e};function k(e){for(let t=0;t<e.length;t++){if(e[t].level===s.targetLevel)return e[t];if(Array.isArray(e[t].children)){const a=k(e[t].children);if(a!==null)return a}}return null}function D(e,t){for(let a=0;a<e.length;a++){if(e[a][y[s.targetLevel]]===Number(t))return e[a];if(Array.isArray(e[a].children)){const n=D(e[a].children,t);if(n!==null)return n}}return null}const O=(e,t,a)=>{if(a.data.level===3)return!1;if(!e)return!0;const n=[];C(a,n,e);let c=!1;return n.forEach(_=>{c=c||_}),c},C=(e,t,a)=>{const n=e.data&&e.data.label&&e.data.label.toUpperCase().includes(a.toUpperCase());n&&t.push(n),!n&&e.level!==1&&e.parent&&C(e.parent,t,a)},x=e=>{for(let t=0;t<e.length;t++)Array.isArray(e[t].children)&&(e[t].children.length&&e[t].level===2&&(e[t].children=[]),x(e[t].children))};function j(){const e={0:{confirmKey:"jumpFactory",authKey:"noFactoryAuth",name:"\u5DE5\u5382",routeName:"factoryBoard",path:"/dashboard/factory",urlParams:{factoryId:o.value.factoryId}},1:{confirmKey:"jumpOrg",authKey:"noOrgAuth",name:"\u4EA7\u7EBF",routeName:"orgBoard",path:"/dashboard/org",urlParams:{orgId:o.value.organizationId}},2:{confirmKey:"jumpDevice",authKey:"noDeviceAuth",name:"\u8BBE\u5907",routeName:"deviceBoard",path:"/dashboard/device",urlParams:{deviceId:o.value.deviceId}}};if(o.value.level!==s.targetLevel&&(o.value.level||o.value.level===0)){const t=e[o.value.level];r.$modal.confirm(m(`${t.confirmKey}`)).then(()=>{r.$router.hasRoute(t.routeName)?r.$router.push({path:t.path,query:{...t.urlParams,isMenu:r.$route.query.isMenu,isShowBoard:r.$route.query.isShowBoard}}):r.$modal.msgError(m(`${t.authKey}`))}).catch(()=>{});return}!o.value||JSON.stringify(o.value)==="{}"||(l.value={...o.value},N("ensureId",l.value[y[s.targetLevel]],l.value)),i.value=!1}return R({showModal:S}),(e,t)=>{const a=Q("arrow-down"),n=Y,c=Z,_=te,M=ee;return I(),$("div",null,[K("div",{class:"customSelect",onClick:S},[d(l).label?(I(),$("div",le,b(d(l).label),1)):(I(),$("div",re,b(s.placeholder),1)),v(n,{class:"el-icon--right"},{default:w(()=>[v(a)]),_:1})]),v(M,{modelValue:d(i),"onUpdate:modelValue":t[1]||(t[1]=f=>A(i)?i.value=f:null),title:e.$t("selectTreeNode"),onConfirm:j,onCancel:t[2]||(t[2]=f=>i.value=!1),width:"600"},{main:w(()=>[v(c,{modelValue:d(h),"onUpdate:modelValue":t[0]||(t[0]=f=>A(h)?h.value=f:null),placeholder:e.$t("inputP"),"suffix-icon":"Search",clearable:"",style:{"margin-bottom":"16px"}},null,8,["modelValue","placeholder"]),v(_,{ref:"treeRef",class:"filter-tree","node-key":"id",data:d(p),props:V,"default-expanded-keys":[d(l).id],"expand-on-click-node":!1,"filter-node-method":O,onNodeClick:L,"highlight-current":""},{default:w(({node:f,data:E})=>[K("div",{style:W({cursor:E.level===5?"not-allowed ":""})},b(E.label),5)]),_:1},8,["data","default-expanded-keys"])]),_:1},8,["modelValue","title"])])}}},ce=q(oe,[["__scopeId","data-v-823c5126"]]);export{ce as default};
