import{em as R,d as I,r as d,ay as W,az as j,j as n,aB as M,cg as O,aa as T,c as X,o as $,w as u,W as q,l as h,p as G,X as H}from"./index-9PRMimni.js";import{a as x,r as B}from"./region-GJtcctBc.js";const J={...R,hideArea:{type:Boolean,default:!1},onlyProvince:{type:Boolean,default:!1},labelField:{type:String,default:"name"},valueField:{type:String,default:"id"},remote:{type:Boolean,default:!0},cascade:{type:Boolean,default:!1}},y=I({name:"ProCascader",props:J,emits:["complete"],setup(l,{emit:_,expose:w,slots:c}){const i=d(!1),f=d(!1),t=d([]),o=d(),p=d([]);W(()=>l.value,e=>{f.value=!!(e&&e.length),t.value=e},{immediate:!0});function v(){f.value?L():A()}function m(e){i.value=e}async function L(){if(!t.value.length)return;m(!0);const{onlyProvince:e,hideArea:s}=l,a=t.value[0]||null,r=t.value[1]||null,D=t.value[2]||null,N=g(await x()),z=await F(a),E=await F(r),P=g(N);P.forEach(C=>{!e&&a===C[l.valueField]&&(C.children=z,s||C.children.forEach(b=>{r===b[l.valueField]&&(b.children=E)}))}),o.value=e?a:s?r:D,p.value=P,m(!1)}async function F(e,s){if(!e)return[];const a=await B({parentId:e});return a&&a.length?g(a):[]}async function A(){if(l.options&&l.options.length){p.value=l.options,m(!1);return}const e=await x();p.value=g(e),m(!1)}function g(e){const{onlyProvince:s,hideArea:a}=l;return!e||!e.length?[]:e.map(r=>({...r,depth:r.depth,isLeaf:s||a&&r.depth===2?!0:r.depth===3}))}async function S(e){const s=e[l.valueField];return await B({parentId:s})}function U(e){return new Promise(async s=>{const a=await S(e);e.children=g(a),s()})}function V(e,s,a){_("complete",e,s,a)}function k(){return{action:c?.action,arrow:c?.arrow,empty:c?.empty,notFound:c?.notFound}}return j(()=>{v()}),w({setLoading:m}),()=>n(M,{show:i.value,size:"small"},{default:()=>[n(O,T(l,{"check-strategy":"child",value:o.value,"onUpdate:value":e=>o.value=e,options:p.value,onLoad:U,onUpdateValue:V}),k())]})}}),Y=I({__name:"proCascader",setup(l){const _=d([2,33,331]),w=d([2]),c=d([{id:1,name:"广东省",children:[{id:11,name:"深圳市"},{id:22,name:"广州市"}]},{id:2,name:"江西省"}]);function i(f,t,o){console.log("complete:value",f),console.log("complete:option",t),console.log("complete:pathValues",o)}return(f,t)=>{const o=q,p=H;return $(),X(p,{title:"省市区联动 ProCascader",content:"基于 Cascader 组件扩展，轻松使用 省市区联动选择，支持自定义字段名",showFooter:""},{default:u(()=>[n(o,{bordered:!1,class:"mt-3 proCard",title:"基本使用","content-style":"padding-top: 0;"},{default:u(()=>[n(h(y),{labelField:"name",valueField:"id",onComplete:i,style:{width:"220px"}})]),_:1}),n(o,{bordered:!1,class:"mt-3 proCard",title:"省份","content-style":"padding-top: 0;"},{default:u(()=>[n(h(y),{onlyProvince:"",value:w.value,"onUpdate:value":t[0]||(t[0]=v=>w.value=v),labelField:"name",valueField:"id",onComplete:i,style:{width:"220px"}},null,8,["value"])]),_:1}),n(o,{bordered:!1,class:"mt-3 proCard",title:"省份/城市","content-style":"padding-top: 0;"},{default:u(()=>[n(h(y),{hideArea:"",labelField:"name",valueField:"id",onComplete:i,style:{width:"220px"}})]),_:1}),n(o,{bordered:!1,class:"mt-3 proCard",title:"省份/城市/区县联动","content-style":"padding-top: 0;"},{default:u(()=>[n(h(y),{value:_.value,"onUpdate:value":t[1]||(t[1]=v=>_.value=v),labelField:"name",valueField:"id",onComplete:i,style:{width:"220px"}},null,8,["value"])]),_:1}),n(o,{bordered:!1,class:"mt-3 proCard",title:"自定义数据源","content-style":"padding-top: 0;"},{default:u(()=>[n(h(y),{options:c.value,labelField:"name",valueField:"id",onComplete:i,style:{width:"220px"}},{action:u(()=>t[2]||(t[2]=[G(" 站在能分割世界的桥 ")])),_:1},8,["options"])]),_:1})]),_:1})}}});export{Y as default};
