1 |
- import{u as w}from"./useAsync.505ab391.js";import{a as R,I as V,r as h,f as c,ax as C,ay as x,az as D,u as _}from"./index.ecc6b905.js";const j={api:{type:Function,required:!0},value:{type:String},subLabelProp:{type:String},requestProp:{type:String},responseLabelProp:{type:String},responseValProp:{type:String},placeholder:{type:String},isRoot:{type:Boolean},width:{type:String},disabled:{type:Boolean,default:!1},showDisabled:{type:Boolean,default:!1},prop:{type:String,default:()=>"list"}};function q(a){return typeof a=="function"||Object.prototype.toString.call(a)==="[object Object]"&&!D(a)}const z=R({name:"RemoteSelect",props:j,emits:["listChange","itemChange","itenDetail","update:value","inital"],setup(a,{emit:d,expose:S}){const i=V({get(){return a.value},set(o){d("update:value",o)}}),g=w(),s=h([]),n=h(!1);async function P(o){const{responseLabelProp:e,responseValProp:t,subLabelProp:u,api:p}=a;n.value=!0;const b={page:1,size:100,...o},{code:f,data:r,message:v}=await p(b);n.value=!1,g({code:f,message:v,handler:()=>{const y=a.isRoot?r:r[a.prop];s.value=y.map(l=>({...l,status:l.status+"",label:l[e]?l[e]+"":"",value:l[t]?l[t]+"":"",subLabel:l[u]?l[u]+"":""})),a.isRoot||(i.value=s.value[0][t]?s.value[0][t]+"":"",d("inital",s.value[0][t]?s.value[0][t]+"":""))}})}async function L(o){if(!o)return;const{responseLabelProp:e,responseValProp:t,requestProp:u,subLabelProp:p,api:b}=a;n.value=!0;const{code:f,data:r,message:v}=await b({[u||e]:o});g({code:f,message:v,handler:()=>{const y=a.isRoot?r:r[a.prop];s.value=y.map(l=>({...l,label:l[e]?l[e]+"":"",value:l[t]?l[t]+"":"",subLabel:l[p]?l[p]+"":"",status:l.status+""})),d("listChange",_(s))}}),n.value=!1}return S({initalData:P}),()=>{let o;return c(x,{class:"w-full",modelValue:i.value,"onUpdate:modelValue":e=>i.value=e,placeholder:a.placeholder,remoteMethod:L,loading:n.value,disabled:a.disabled,reserveKeyword:!0,filterable:!0,clearable:!0,remote:!0,style:{wdith:a.width?a.width+"px":""},onChange:e=>{d("itemChange",s.value.find(t=>t.value===e))}},q(o=s.value.map(e=>c(C,{label:e.subLabel?e.label+" - "+e.subLabel:e.label,key:e.value,value:e.value,disabled:a.showDisabled?e.status+""=="0":!1},{default:()=>[c("span",{style:"float: left"},[e.label]),c("span",{style:"float: right;color: var(--el-text-color-secondary);font-size: 13px;"},[e.subLabel])]})))?o:{default:()=>[o]})}}}),E=z;export{E as R};
|