import{a as U,r as G}from"./region-GJtcctBc.js";import{d as F,r,ay as M,a4 as A,az as q,h as N,o as y,E as H,j as t,c as B,D as R,aA as J,ac as K,l as f,aB as O,i as Q,w as P,p as k,W as X,al as Y,G as Z}from"./index-9PRMimni.js";const ee={hideArea:{type:Boolean,default:!1},onlyProvince:{type:Boolean,default:!1},value:{type:Array,default:[]},wrapper:{type:String,default:""},labelField:{type:String,default:"name"},valueField:{type:String,default:"id"}},b=F({__name:"Region",props:{...ee},emits:["change"],setup(I,{emit:d}){const l=I,v=d,a=r(!1),i=r(null),o=r(null),s=r(null),c=r([]),m=r([]),g=r([]),S=r(!1),w=r([]);M(()=>l.value,e=>{S.value=!!(e&&e.length),w.value=e},{immediate:!0});const V=A(()=>l.wrapper?l.wrapper:""),z=A(()=>g.value.length&&!l.onlyProvince&&!l.hideArea),D=A(()=>m.value.length&&!l.onlyProvince);function L(){S.value?E():T()}async function E(){a.value=!0;const e=w.value[0]||null,n=w.value[1]||null,u=w.value[2]||null;c.value=x(await U()),m.value=await h(e,!0),g.value=await h(n,!0),await K(()=>{i.value=e,o.value=n,s.value=u,a.value=!1,v("change",C())})}async function T(){const e=await U();c.value=x(e),a.value=!1}async function h(e,n){if(!e)return[];const u=await G({parentId:e});return n||(a.value=!1),u&&u.length?x(u):[]}async function W(){a.value=!0;const e=await h(i.value);o.value=null,s.value=null,g.value=[],m.value=e,v("change",C()),a.value=!1}async function $(){a.value=!0;const e=await h(o.value);s.value=null,g.value=e,v("change",C()),a.value=!1}async function j(){v("change",C())}function x(e){return!e||!e.length?[]:e.map(n=>({label:n[l.labelField],value:n[l.valueField]}))}function C(){const e=f(c).filter(p=>p.value===i.value);if(l.onlyProvince)return[...e];const n=f(m).filter(p=>p.value===o.value);if(l.hideArea)return[...e,...n];const u=f(g).filter(p=>p.value===s.value);return[...e,...n,...u]}return q(()=>{L()}),(e,n)=>{const u=J,p=O;return y(),N("div",{class:H([V.value,"flex flex-row region"])},[t(u,{value:i.value,"onUpdate:value":[n[0]||(n[0]=_=>i.value=_),W],options:c.value,clearable:""},null,8,["value","options"]),D.value?(y(),B(u,{key:0,value:o.value,"onUpdate:value":[n[1]||(n[1]=_=>o.value=_),$],options:m.value,class:"ml-2.5",clearable:""},null,8,["value","options"])):R("",!0),z.value?(y(),B(u,{key:1,value:s.value,"onUpdate:value":[n[2]||(n[2]=_=>s.value=_),j],options:g.value,class:"ml-2.5",clearable:""},null,8,["value","options"])):R("",!0),a.value?(y(),B(p,{key:2,class:"ml-2.5",size:"small"})):R("",!0)],2)}}}),ae={class:"n-layout-page-header"},te=F({__name:"index",setup(I){const d=r([1,11,111]);function l(v){console.log(v)}return(v,a)=>{const i=X,o=Y,s=Z;return y(),N("div",null,[Q("div",ae,[t(i,{bordered:!1,title:"地区"},{default:P(()=>a[2]||(a[2]=[k(" 地区组件，用于选择省市区，比如填写地址，配送地址，等... ")])),_:1})]),t(i,{bordered:!1,class:"mt-3 proCard"},{default:P(()=>[t(o,{title:"添加场景",type:"info"},{default:P(()=>a[3]||(a[3]=[k(" 自动加载数据，显示省市区")])),_:1}),t(f(b),{class:"Region mt-3",onChange:l}),t(s),t(o,{title:"回显场景",type:"info"},{default:P(()=>a[4]||(a[4]=[k(" 设置默认值，自动加载数据，并且选中")])),_:1}),t(f(b),{value:d.value,"onUpdate:value":a[0]||(a[0]=c=>d.value=c),class:"Region mt-3",onChange:l},null,8,["value"]),t(s),t(o,{title:"只显示省市",type:"info"}),t(f(b),{value:d.value,"onUpdate:value":a[1]||(a[1]=c=>d.value=c),hideArea:!0,class:"Region mt-3",onChange:l},null,8,["value"]),t(s),t(o,{title:"只显示省",type:"info"}),t(f(b),{onlyProvince:!0,class:"Region mt-3",onChange:l})]),_:1})])}}});export{te as default};
