import{d as N,O,P as R,ab as D,n as _,Q as T,p as U,R as z,w as P,r as y,o as c,A as h,y as j,i as Q,a as S,c as E,F as W,z as G,h as J,H as K,_ as X,U as Y,ax as b,ay as k}from"./index.js";const Z={key:1,class:"super-loading"},$={key:2,class:"super-no-more"},ee=N({__name:"super",props:{noAll:{type:Boolean,required:!1},noSet:{type:Boolean,required:!1},code:{type:String,required:!1,default:""},isSupplier:{type:Boolean,required:!1},placeholder:{type:String,required:!1}},emits:["change","update:code"],setup(x,{expose:L,emit:B}){const F=B,l=x,{setCurrentCompany:q}=O(),C=R(),{userLevel:i}=D(),d=_(l.code),w=_(null),r=_([]),e=T({loading:!1,noMore:!1,name:"",count:0,page:1});let s=null;const M=Y(H,500);function A(o){return i.value==="3"||l.isSupplier?o:o.map(a=>({...a,code:a.companyNo,name:a.company_name}))}async function m(o,n){e.name=o,e.page=1,e.noMore=!1;const a=i.value==="3"||l.isSupplier,p=a||l.isSupplier?b:k,{data:u,message:t,code:f}=await p({[a?"name":"company_name"]:e.name,[a?"code":"companyNo"]:n,size:10,page:e.page});C({code:f,message:t,handler:()=>{r.value=A(u.list),e.count=u.count,e.loading=!1;const g=Math.ceil(e.count/10);e.noMore=g<=1}})}function I(o){const n=r.value.find(({code:a})=>a===o);l.noSet||q(n),F("change",n)}async function H(){const o=s.clientHeight,n=s.scrollTop,a=s.scrollHeight;if(o+n>=a&&!e.noMore){e.page++,e.loading=!0;const p=i.value==="3"||l.isSupplier?b:k,{data:u,message:t,code:f}=await p({name:e.name,page:e.page,size:10,noRela:!0}),g=v=>{r.value=[...r.value,...A(v)]};C({code:f,message:t,handler:()=>{e.count=u.count;const v=Math.ceil(e.count/10);if(e.page>v){e.noMore=!0,e.loading=!1;return}g(u.list)}})}}U(()=>{setTimeout(()=>{var n;const o=document.querySelector(".super-item");!o||(s=(n=o.parentElement)==null?void 0:n.parentElement,s&&s.addEventListener("scroll",M,!1))},1e3)}),z(()=>{e.loading=!1,e.noMore=!1,e.name="",e.page=1,s&&s.removeEventListener("scroll",M)}),P(()=>i.value,o=>{o!==""&&(e.loading=!1,e.noMore=!1,e.name="",e.page=1,r.value=[],m(void 0,l.code))});const V=o=>{const{code:n,name:a}=o;return n+" / "+a};return m(void 0,l.code),L({selectAll:()=>d.value=""}),(o,n)=>{const a=y("ElOption"),p=y("IconifyIconOffline"),u=y("ElSelect");return c(),h(u,{filterable:"",remote:"",modelValue:d.value,"onUpdate:modelValue":n[0]||(n[0]=t=>d.value=t),"remote-method":m,onChange:I,style:{width:"450px"},placeholder:o.placeholder,ref_key:"selectRef",ref:w},{default:j(()=>[o.noAll?S("v-if",!0):(c(),h(a,{key:0,label:Q(i)==="3"?"\u6240\u6709\u4F9B\u5E94\u5546\u516C\u53F8":"\u6240\u6709\u4E1A\u52A1\u516C\u53F8",value:""},null,8,["label"])),(c(!0),E(W,null,G(r.value,t=>(c(),h(a,{class:"super-item",key:t.code,value:t.code,label:V(t)},null,8,["value","label"]))),128)),e.loading?(c(),E("p",Z,[J(p,{class:"animate-spin",icon:"Loading"}),n[1]||(n[1]=K(" \u52A0\u8F7D\u4E2D "))])):S("v-if",!0),e.noMore?(c(),E("p",$,"\u6CA1\u6709\u66F4\u591A\u6570\u636E\u4E86...")):S("v-if",!0)]),_:1},8,["modelValue","placeholder"])}}});var ne=X(ee,[["__scopeId","data-v-894137a8"],["__file","D:/work/jiesuan/settle-vue3/src/layout/components/company/super.vue"]]);export{ne as S};
