"use strict";const n=require("vue"),a=require("../Shared/base-iCmnU-fv.js"),N=require("../Shared/language-D6gRWx8H.js"),q=n.defineComponent({name:"ClSelectCascade",__name:"Index",props:{value:[String,Number],list:{type:Array,default:()=>[]},placeholder:String,className:{type:String,default:""},disabled:{type:Boolean,default:!1},isClear:{type:Boolean,default:!1},isSearch:{type:Boolean,default:!1},parentKey:{type:String,default:"parentId"},topParentValue:{type:String,default:"0"},width:String,isCheckValidate:{type:Boolean,default:!1},validateRules:{type:Array,default:()=>[{r:"required"}]},isShowInMsg:{type:Boolean,default:!0}},emits:["update:value","onChange"],setup(p,{expose:J,emit:P}){const u=p,S=P,{optPageLanguage:_,getPageLanguage:L}=N.useLanguage();L("common");const d=n.reactive({keyIndex:`selectCascade-${a.CommonBase.getRandom(8)}`,lastValue:u.value,isFirstDataFinish:!1}),C=n.ref([]),r={dataJson:{},dataGroup:{},parentIdsJson:{},defPlaceholder:_.value.pleaseSelect},w=n.computed(()=>{const{placeholder:e}=u;return e&&!a.CommonBase.isEmpty(e)?e.split("|"):[]}),D=n.computed(()=>{const{width:e}=u;return e&&!a.CommonBase.isEmpty(e)?e.split("|"):[]}),F=n.computed(()=>{const e={"panel-selectCascade":!0},{className:t}=u;return t&&!a.CommonBase.isEmpty(t)&&t.split(" ").forEach(s=>{a.CommonBase.isEmpty(s)||(e[s]=!0)}),e}),K=e=>{e!==d.lastValue&&(d.lastValue=e,S("update:value",e),S("onChange",e))},v=e=>a.CommonBase.isExistJsonKey(r.dataGroup,e.toString()),M=e=>{const t=e.toString();return v(t)?r.dataGroup[t]:[]},I=e=>{const t=e.toString();return a.CommonBase.isExistJsonKey(r.dataJson,t)?r.dataJson[t]:null},y=()=>`top_${u.topParentValue}`,E=e=>{const{parentKey:t,topParentValue:s}=u,o={},l={};a.CommonBase.isEmpty(e)||e.forEach(i=>{const c=a.CommonBase.getJsonClone(i),B=c.id.toString(),f=c[t].toString();o[B]=c;const g=f===s?y():f;a.CommonBase.isExistJsonKey(l,g)||(l[g]=[]),l[g].push(c)}),r.dataJson=o,r.dataGroup=l},m=(e,t)=>{const s={idx:e,pId:t,placeholder:r.defPlaceholder,list:[],sty:{},selected:""};if(!a.CommonBase.isEmpty(t)){const c=M(t);s.list=a.CommonBase.getListClone(c)}const o=w.value,l=o.length;l>0&&(l>e?s.placeholder=a.CommonBase.isEmpty(o[e])?r.defPlaceholder:o[e]:l===1&&(s.placeholder=o[0]));const i=D.value;return i.length>e&&(a.CommonBase.isEmpty(i[e])||(s.sty.width=i[e],s.sty.flex="none")),s},V=e=>{const{parentKey:t,topParentValue:s}=u;let o=[];if(a.CommonBase.isExistJsonKey(r.parentIdsJson,e)&&r.parentIdsJson[e].length>0)o=r.parentIdsJson[e];else{const l=I(e);if(!a.CommonBase.isUndefined(l)){const i=l[t].toString();if(i!==s&&!a.CommonBase.isUndefined(I(i))){o.push(i);const c=V(i);c.length>0&&(o=o.concat(c))}}r.parentIdsJson[e]=o}return o},h=e=>{const t=a.CommonBase.isUndefined(e)?u.value:e,s=[];if(a.CommonBase.isEmpty(t))s.push(m(0,y())),s.push(m(1,""));else{const o=t.toString(),l=V(o),i=l.length;if(i>0){l.forEach((B,f)=>{const g=f===0?y():B,k=m(f,g);k.selected=B,s.push(k)});const c=m(i,l[i-1]);c.selected=o,s.push(c)}else{const c=m(0,y());c.selected=o,s.push(c)}}C.value=s},U=()=>{E(u.list),h()};n.onMounted(()=>{n.nextTick(()=>{U()})}),n.watch(()=>u.value,(e,t)=>{e!==t&&!a.CommonBase.isUndefined(e)&&e!==d.lastValue&&d.isFirstDataFinish&&(h(),d.lastValue=e)}),n.watch(()=>u.list,e=>{d.isFirstDataFinish||(d.isFirstDataFinish=!0),r.parentIdsJson={},E(e);const{value:t}=u,s=t&&!a.CommonBase.isEmpty(t)&&a.CommonBase.isExistJsonKey(r.dataJson,t.toString())?t:"";h(s),d.lastValue=s});const x=e=>(console.log(e),!0),G=(e,t)=>{let s="";if(a.CommonBase.isEmpty(e)&&t===0)h("");else{const o=e.toString();v(o)?(C.value.splice(t+1),C.value.push(m(t+1,o))):s=e}K(s)};return J({getValue:()=>{},setValue:e=>{h(e)}}),(e,t)=>{const s=n.resolveComponent("cl-select"),o=n.resolveComponent("cl-form-validate");return n.openBlock(),n.createElementBlock("div",{class:n.normalizeClass(F.value)},[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(C.value,(l,i)=>(n.openBlock(),n.createElementBlock("div",{key:`${d.keyIndex}-${i}`,class:"selectCascade-item",style:n.normalizeStyle(l.sty)},[n.createVNode(o,{isShowMsg:p.isShowInMsg,isCheck:p.isCheckValidate,checkValue:l.selected,rules:p.validateRules},{default:n.withCtx(()=>[n.createVNode(s,{isClear:p.isClear,isSearch:p.isSearch,placeholder:l.placeholder,list:l.list,value:l.selected,"onUpdate:value":c=>l.selected=c,onOpenBefore:x,onOnChange:c=>G(c,i)},null,8,["isClear","isSearch","placeholder","list","value","onUpdate:value","onOnChange"])]),_:2},1032,["isShowMsg","isCheck","checkValue","rules"])],4))),128))],2)}}});module.exports=q;
//# sourceMappingURL=ClSelectCascade.cjs.map
