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