import{u as ee,b as ae,r,ah as B,cD as le,o as p,y,q as n,v as b,p as s,P as V,x as T,n as t,s as q,c as F,F as I,A as $,aH as U,aI as S,c5 as te,c0 as oe,E as ne,i as se,k as ue,m as de,j as re,l as ie,bv as pe,D as me}from"./index.8d733f79.js";import{g as fe,k as ce,s as j}from"./faultType.8bb3732b.js";import{k as ve}from"./deviceTree.170dfbd9.js";const ge={class:"content-wrap"},_e={class:"dialog-footer"},Ve={__name:"addInCaseDialog",emits:["updateData"],setup(ye,{expose:M,emit:k}){const{proxy:g}=me(),D=ee(),{t:m}=ae(),d=r(1),O=r([{label:m("existCase"),value:1},{label:m("addCase"),value:0}]),A={value:"id",label:"label"},f=r(!1),E=r([]),h=r([]),R=r([]),c=r({id:""}),o=r({name:"",faultType:[],faultComponent:""}),G=B({id:[{required:!0,message:m("selectCaseP"),trigger:"change"}]}),H=B({name:[{required:!0,message:m("faultCaseNameP"),trigger:"blur"}],faultType:[{required:!0,message:m("faultTypeP"),trigger:"change"}],faultComponent:[{required:!0,message:m("faultComponentP"),trigger:"change"}]});function z(e){f.value=!0,d.value=1,o.value.deviceId=e.deviceId,o.value.faultType=e.faultTypeId,o.value.diagnosis=e.diagnosis,c.value.diagnosis=e.diagnosis,Q(),J(),K()}const J=()=>{fe().then(e=>{h.value=e.data})},K=()=>{ve({deviceId:o.value.deviceId,isLinkSensor:!0}).then(e=>{R.value=e.data.components})},Q=()=>{ce({deviceId:o.value.deviceId}).then(e=>{E.value=e.data})},w=(e,l)=>{for(let i=0;i<l.length;i++){const u=l[i];if(u.id===e)return u.label;if(u.children&&u.children.length){const v=w(e,u.children);if(v)return v}}return null},W=()=>{d.value===1&&g.$refs.haveFormRef.validate(e=>{e&&(k("updateData"),j(c.value).then(l=>{C(),l.code===200&&D.push({path:"/knowledgeBase/faultLib/edit",query:{id:l.data.id}})}))}),d.value===0&&g.$refs.addFormRef.validate(e=>{if(e){k("updateData");const l=o.value.faultType.map(u=>w(u,h.value)),i={...o.value,faultType:l.join("-"),faultTypeId:o.value.faultType.join("-")};j(i).then(u=>{C(),u.code===200&&D.push({path:"/knowledgeBase/faultLib/edit",query:{id:u.data.id}})})}})},C=()=>{f.value=!1},X=()=>{g.$refs.haveFormRef.resetFields(),g.$refs.addFormRef.resetFields()};return M({showModal:z}),(e,l)=>{const i=te,u=oe,v=ne,L=se,_=ue,N=de,Y=re,Z=le,P=ie,x=pe;return p(),y(x,{title:e.$t("addCaseLib"),modelValue:t(f),"onUpdate:modelValue":l[5]||(l[5]=a=>q(f)?f.value=a:null),width:"500px","align-center":!0,onClosed:X},{footer:n(()=>[b("div",_e,[s(P,{onClick:C},{default:n(()=>[V(T(e.$t("cancel")),1)]),_:1}),s(P,{type:"primary",onClick:W},{default:n(()=>[V(T(e.$t("confirm")),1)]),_:1})])]),default:n(()=>[b("div",ge,[s(u,{modelValue:t(d),"onUpdate:modelValue":l[0]||(l[0]=a=>q(d)?d.value=a:null)},{default:n(()=>[(p(!0),F(I,null,$(t(O),a=>(p(),y(i,{key:a.value,value:a.value},{default:n(()=>[V(T(a.label),1)]),_:2},1032,["value"]))),128))]),_:1},8,["modelValue"]),U(b("div",null,[s(N,{ref:"haveFormRef",model:t(c),rules:t(G)},{default:n(()=>[s(_,{label:e.$t("selectCase"),prop:"id"},{default:n(()=>[s(L,{modelValue:t(c).id,"onUpdate:modelValue":l[1]||(l[1]=a=>t(c).id=a),filterable:"",placeholder:e.$t("selectCaseP")},{default:n(()=>[(p(!0),F(I,null,$(t(E),a=>(p(),y(v,{key:a.id,label:a.name,value:a.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder"])]),_:1},8,["label"])]),_:1},8,["model","rules"])],512),[[S,t(d)===1]]),U(b("div",null,[s(N,{ref:"addFormRef",model:t(o),rules:t(H)},{default:n(()=>[s(_,{label:e.$t("faultCaseName"),prop:"name"},{default:n(()=>[s(Y,{modelValue:t(o).name,"onUpdate:modelValue":l[2]||(l[2]=a=>t(o).name=a),placeholder:e.$t("faultCaseNameP"),maxlength:"20"},null,8,["modelValue","placeholder"])]),_:1},8,["label"]),s(_,{label:e.$t("faultType"),prop:"faultType"},{default:n(()=>[s(Z,{modelValue:t(o).faultType,"onUpdate:modelValue":l[3]||(l[3]=a=>t(o).faultType=a),options:t(h),props:A,separator:"-",filterable:"",placeholder:e.$t("faultTypeP")},null,8,["modelValue","options","placeholder"])]),_:1},8,["label"]),s(_,{label:e.$t("faultComponent"),prop:"faultComponent"},{default:n(()=>[s(L,{modelValue:t(o).faultComponent,"onUpdate:modelValue":l[4]||(l[4]=a=>t(o).faultComponent=a),filterable:"",placeholder:e.$t("faultComponentP"),teleported:!1},{default:n(()=>[(p(!0),F(I,null,$(t(R),a=>(p(),y(v,{key:a.id,label:a.name,value:a.name},null,8,["label","value"]))),128))]),_:1},8,["modelValue","placeholder"])]),_:1},8,["label"])]),_:1},8,["model","rules"])],512),[[S,t(d)===0]])])]),_:1},8,["title","modelValue"])}}};export{Ve as default};
