import{b as T,r as $,$ as B,cE as M,o as p,c as P,v as V,aH as b,y as v,q as l,P as f,x as c,p as o,n as g,t as R,ay as q,l as F,j as Q,cp as W,ak as j,bn as A,cq as z,D as G}from"./index.8d733f79.js";import{E as J}from"./el-input-number.60463ef8.js";import{e as K,f as O}from"./deviceHealth.f8ad4f4a.js";import X from"./importModal.ce3a6d08.js";import"./index.28f6da25.js";import"./el-progress.ee3fa77d.js";import"./collector.4eeb72e6.js";const Y={style:{height:"100%"}},Z={style:{"margin-bottom":"20px"}},ee={style:{height:"calc(100% - 52px)"},class:"tableWrap"},te=V("span",{style:{margin:"0 16px"}},"\u4E00",-1),de={__name:"levelSet",setup(le,{expose:x}){const{t:m}=T(),{proxy:n}=G(),r=$([]),h=$(null),w=$(),E=()=>{K({factoryId:h.value}).then(e=>{r.value=e.data,q(()=>{w.value=document.getElementsByClassName("tableWrap")[0].offsetHeight})})},k=()=>{if(r.value.length===10){n.$modal.msgError(m("addNumLimit"));return}r.value.push({name:"",maxValue:null,minValue:null})},C=e=>{n.$modal.confirm(m("confirmDelete")).then(()=>{r.value=r.value.filter(a=>a!==e)}).catch(()=>{})};function L(e){for(let t=0;t<e.length;t++){const{name:u,minValue:i,maxValue:_}=e[t];if(u==="")return n.$modal.msgError(m("healthLevelNameP")),!1;if(i===null||_===null)return n.$modal.msgError(m("healthScoreP")),!1;if(i>=_)return n.$modal.msgError(m("healthLevelUpLow")),!1}const a=[...e].sort((t,u)=>t.minValue-u.minValue);if(a[0].minValue!==0)return n.$modal.msgError(m("healthLow0")),!1;if(a[a.length-1].maxValue!==100)return n.$modal.msgError(m("healthUp100")),!1;for(let t=1;t<a.length;t++){const u=a[t-1].maxValue,i=a[t].minValue;if(u!==i)return n.$modal.msgError(m("healthNoCoincide")),!1}return!0}const N=()=>{if(L(r.value)){const e={factoryId:h.value,levels:r.value};O(e).then(a=>{n.$modal.msgSuccess(a.msg)})}};x({showTarget:e=>{h.value=e.factoryId,E()}});const S=()=>{n.$refs.importModalRef.showModal(h.value)};return(e,a)=>{const t=F,u=Q,i=W,_=B("QuestionFilled"),H=j,U=A,I=J,D=z,y=M("hasPermi");return p(),P("div",Y,[V("div",Z,[b((p(),v(t,{type:"primary",onClick:k},{default:l(()=>[f(c(e.$t("add")),1)]),_:1})),[[y,["deviceHealth_healthSet_add"]]]),b((p(),v(t,{type:"primary",onClick:N},{default:l(()=>[f(c(e.$t("save")),1)]),_:1})),[[y,["deviceHealth_healthSet_edit"]]]),b((p(),v(t,{onClick:S},{default:l(()=>[f(c(e.$t("healthyImport")),1)]),_:1})),[[y,["deviceHealth_healthSet_edit"]]])]),V("div",ee,[o(D,{data:g(r),"max-height":g(w)},{default:l(()=>[o(i,{label:e.$t("healthLevelName"),"min-width":"200"},{default:l(s=>[o(u,{modelValue:s.row.name,"onUpdate:modelValue":d=>s.row.name=d,maxlength:"20"},null,8,["modelValue","onUpdate:modelValue"])]),_:1},8,["label"]),o(i,{label:e.$t("healthScore"),"min-width":"400"},{header:l(()=>[f(c(e.$t("healthScore"))+" ",1),o(U,{placement:"top"},{content:l(()=>[V("div",null,c(e.$t("healthLevelDesc")),1)]),default:l(()=>[o(H,null,{default:l(()=>[o(_)]),_:1})]),_:1})]),default:l(s=>[o(I,{modelValue:s.row.minValue,"onUpdate:modelValue":d=>s.row.minValue=d,precision:0,max:100,min:0,controls:!1,style:{width:"40%"}},null,8,["modelValue","onUpdate:modelValue"]),te,o(I,{modelValue:s.row.maxValue,"onUpdate:modelValue":d=>s.row.maxValue=d,precision:0,max:100,min:0,controls:!1,style:{width:"40%"}},null,8,["modelValue","onUpdate:modelValue"])]),_:1},8,["label"]),o(i,{label:e.$t("action"),"min-width":"150"},{default:l(s=>[g(r).length>1?(p(),v(t,{key:0,link:"",type:"danger",onClick:d=>C(s.row)},{default:l(()=>[f(c(e.$t("delete")),1)]),_:2},1032,["onClick"])):R("",!0)]),_:1},8,["label"])]),_:1},8,["data","max-height"])]),o(X,{ref:"importModalRef",factoryId:g(h),onRefresh:E},null,8,["factoryId"])])}}};export{de as default};
