import{K as J,I as M,r as T,av as P,a9 as R,a5 as q,aw as O,F as V}from"./index.17037962789732.js";import"./index.170379627897318.js";import"./index.170379627897319.js";import"./index.170379627897316.js";import"./index.170379627897317.js";import"./index.170379627897327.js";import"./index.170379627897314.js";import"./index.170379627897315.js";import{_ as $}from"./index.17037962789739.js";import{I as U,J as A,F as G}from"./instance.1703796278973.js";import{_ as K}from"./index.vue_vue_type_script_setup_true_lang.170379627897317.js";import{u as z}from"./instance.17037962789732.js";import{d as H,s as Q,v as W,k as D,p as X,T as Y,o as h,x as N,b as t,a,t as x,u as i,F as Z,h as ee,c as S,A as te,B as ae}from"./vue.1703796278973.js";const ge=H({__name:"index",props:["childData"],emits:["closeChildSave"],setup(B,{emit:F}){const c=B,w=z(),{current:r}=Q(w),l=W({name:"",productId:""}),j=D(),I=D(),y=D(!1),E=async()=>{const n=await U({terms:[{column:"accessProvider",value:"edge-child-device"}]});n.status===200&&(I.value=n.result,k())},k=()=>{var n,s,_;if((n=c.childData)!=null&&n.id){if(r.value.parentId=c.childData.id,l.name=(s=c.childData)==null?void 0:s.name,l.productId=(_=c.childData)==null?void 0:_.productId,L(l.productId),r.value.metadata){const d=r.value.metadata;d&&d.length!==0&&A(r.value.id,{deviceId:c.childData.id,query:{}}).then(m=>{var e;if(m.status===200){const f=(e=m.result[0])==null?void 0:e.reduce((o,g)=>{const u=d.find(p=>p.metadataId===g.metadataId);return u?Object.assign(u,g):o.push(g),o},d),C=f.filter(o=>o.metadataName);r.value.metadata=C;const v=f.filter(o=>!o.metadataName).map(o=>o.id);v&&v.length!==0&&G(r.value.id,{deviceId:c.childData.id,idList:[...v]})}})}y.value=!0}else r.value.parentId=""},L=n=>{var d,m;n&&(y.value=!0);const s=I.value.filter(e=>e.id===n)[0],_=(m=(d=JSON.parse(s.metadata||[]))==null?void 0:d.properties)==null?void 0:m.map(e=>({metadataType:"property",metadataName:`${e.name}(${e.id})`,metadataId:e.id,name:e.name}));r.value.metadata=_};X(()=>{E()}),Y("validate",async()=>j.value.validateFields());const b=()=>{F("closeChildSave")};return(n,s)=>{const _=J,d=$,m=M,e=T,f=P,C=R,v=q,o=O,g=V;return h(),N("div",null,[t(d,{data:"基本信息"},{extra:a(()=>[t(_,{onClick:b,style:{"margin-left":"10px"}},{default:a(()=>[x("返回")]),_:1})]),_:1}),t(g,{layout:"vertical",model:i(l),ref_key:"formRef",ref:j},{default:a(()=>[t(o,{gutter:24},{default:a(()=>[t(f,{span:12},{default:a(()=>[t(e,{label:"设备名称",name:"name",rules:{required:!0,message:"请输入设备名称"}},{default:a(()=>[t(m,{value:i(l).name,"onUpdate:value":s[0]||(s[0]=u=>i(l).name=u)},null,8,["value"])]),_:1})]),_:1}),t(f,{span:12},{default:a(()=>[t(e,{label:"产品名称",name:"productId",rules:{required:!0,message:"请选择产品名称"}},{default:a(()=>{var u;return[t(v,{disabled:(u=c.childData)==null?void 0:u.id,onChange:L,value:i(l).productId,"onUpdate:value":s[1]||(s[1]=p=>i(l).productId=p)},{default:a(()=>[(h(!0),N(Z,null,ee(i(I),p=>(h(),S(C,{key:p.id,value:p.id},{default:a(()=>[x(te(p.name),1)]),_:2},1032,["value"]))),128))]),_:1},8,["disabled","value"])]}),_:1})]),_:1})]),_:1}),i(y)?(h(),S(o,{key:0,gutter:24},{default:a(()=>[t(f,{span:24},{default:a(()=>[t(K,{productList:i(I),onClose:b,onGetEdgeMap:k},null,8,["productList"])]),_:1})]),_:1})):ae("",!0)]),_:1},8,["model"])])}}});export{ge as _};
