import{_ as e,k as s,c as t,b as l,d as a,l as i,O as o,Q as n,j as r,s as u,w as p,g as d,i as c,P as f,p as m,K as h}from"./index-DuyQv-rd.js";const g={class:"upload-container"},x=["href"],y={class:"button-group"},b={class:"alert"},v={key:0},S={class:"file-info"},w={class:"v-r-message"},z=["innerHTML"];const C=e({components:{},props:{url:{type:String,default:""},template:{type:Object,default:()=>({url:"",fileName:"未定义文件名"})},importExcelBefore:{type:Function,default:e=>!0}},data:()=>({maxSize:100,model:!0,file:null,loadingStatus:!1,message:"",resultClass:""}),methods:{clearMsg(){this.message=""},reset(){this.file=null,this.message="",this.resultClass=""},getFileType(){let e=this.file.name.split(".").pop().toLocaleLowerCase()||"";return-1!=["numbers","csv","xls","xlsx"].indexOf(e)||(this.$Message.error("只能选择excel文件"),!1)},beforeUpload(e){return this.file=e,this.getFileType(),!1},upload(){let e=h+this.url;if(!e)return this.$Message.error("没有配置好Url");if(!this.file)return this.$Message.error("请选择文件");var s=new FormData;s.append("fileInput",this.file),this.importExcelBefore(s)&&(this.loadingStatus=!0,this.http.post(e,s).then((e=>{this.loadingStatus=!1,this.file=null,e.status&&this.$emit("importExcelAfter",e),this.message=e.message,this.resultClass=e.status?"v-r-success":"v-r-error"}),(e=>{this.loadingStatus=!1})))},dowloadTemplate(){let e=h+this.template.url,s=new XMLHttpRequest;s.open("GET",e,!0),s.setRequestHeader("Content-type","application/json"),s.setRequestHeader("Authorization",this.$store.getters.getToken());let t=this.template.fileName+".xlsx",l=this.$refs.template;s.responseType="blob";let a=this;this.loadingStatus=!0,s.onload=function(e){if(a.loadingStatus=!1,"application/json"==s.response.type)return a.message.error("未找到下载文件");let i=s.response;l.download=t;let o=new Blob([i]);l.href=URL.createObjectURL(o),l.click()},s.send()}}},[["render",function(e,h,C,k,M,T){const _=s("el-button"),L=s("el-upload"),$=s("el-alert");return l(),t("div",g,[a("a",{href:C.template.url,ref:"template"},null,8,x),a("div",y,[r(L,{style:{float:"left"},ref:"uploadFile","max-size":M.maxSize,"on-change":T.clearMsg,"before-upload":T.beforeUpload,action:C.url},{default:p((()=>[r(_,{size:"small"},{default:p((()=>h[0]||(h[0]=[a("i",{class:"el-icon-folder-opened"},null,-1),d("选择文件")]))),_:1})])),_:1},8,["max-size","on-change","before-upload","action"]),C.template.url?(l(),u(_,{key:0,style:{"margin-left":"10px"},type:"primary",size:"small",onClick:T.dowloadTemplate,loading:M.loadingStatus},{default:p((()=>h[1]||(h[1]=[a("i",{class:"el-icon-bottom"},null,-1),d(" 下载模板")]))),_:1},8,["onClick","loading"])):i("",!0),r(_,{type:"success",size:"small",onClick:T.upload,loading:M.loadingStatus},{default:p((()=>h[2]||(h[2]=[a("i",{class:"el-icon-top"},null,-1),d(" 上传文件")]))),_:1},8,["onClick","loading"])]),a("div",b,[r($,{title:"上传说明",type:"warning",closable:!1,"show-icon":""},{default:p((()=>[d("只能上传excel文件,文件大小不超过"+c(M.maxSize)+"M",1)])),_:1})]),M.file?(l(),t("div",v,[h[3]||(h[3]=a("h3",null,"文件列表",-1)),a("div",S,[a("span",null,"文件名："+c(M.file.name),1),a("span",null,"大小"+c((M.file.size/1024).toFixed(2))+"KB",1)])])):i("",!0),o(a("div",w,[h[4]||(h[4]=a("h3",{class:"title"},"上传结果",-1)),a("div",{class:m(["text",M.resultClass]),innerHTML:M.message},null,10,z)],512),[[f,M.message]]),n(e.$slots,"default",{},void 0,!0)])}],["__scopeId","data-v-055f6a94"]]);export{C as default};
