"use strict";(self["webpackChunkcarabi_x2"]=self["webpackChunkcarabi_x2"]||[]).push([[1058],{6749:function(t,e,s){s.r(e),s.d(e,{default:function(){return c}});var a=function(){var t=this,e=t._self._c;return e("Modal",{ref:"modal",attrs:{autoOpen:!1,fullHeight:!1,large:!1,title:"Импорт данных"},on:{closed:function(e){return t.$emit("close")}}},[e("div",{staticClass:"uk-padding"},[e("div",{directives:[{name:"show",rawName:"v-show",value:!t.uploading,expression:"!uploading"}],ref:"upload",staticClass:"js-upload uk-width-1-1",attrs:{"uk-form-custom":""}},[e("input",{ref:"uploadInput",attrs:{type:"file",disabled:!1},on:{change:function(e){return t.upload(e)}}}),e("button",{staticClass:"uk-button uk-width-1-1 pos-border-radius-none uk-button-primary",attrs:{type:"button",tabindex:"-1"}},[e("i",{staticClass:"fas fa-cloud-upload-alt"}),t._v(" Загрузить файл или таблицу (xls, xlsx, csv) ")])])]),t.uploading?e("div",{staticClass:"import-modal-progress uk-padding"},[e("div",{staticClass:"fa-3x uk-padding-small uk-flex uk-flex-center uk-flex-middle"},[e("div",[e("i",{staticClass:"fas fa-cog fa-spin"})])]),e("div",{staticClass:"progress-text uk-h5 uk-text-center"},[t._v(t._s(t.progressText))]),e("progress",{staticClass:"uk-progress",attrs:{max:"100"},domProps:{value:t.progress}})]):t._e()])},r=[],o=s(3216),i=s(3230);function l(t){return new Promise(((e,s)=>{let a=new FileReader;a.onload=()=>{e(a.result)},a.onerror=()=>{s(new Error("FileReader error"))},a.onabort=()=>{s(new Error("FileReader abort"))},a.readAsArrayBuffer(t)}))}var n={name:"ModalImportUpload",components:{Modal:()=>s.e(8362).then(s.bind(s,2215))},data(){return{uploading:!1,progress:0,progressText:"",patternId:null,documentId:null,loadDocId:null}},computed:{},watch:{},mounted(){},methods:{async open(t,e){this.patternId=t,this.documentId=e,await this.$refs.modal.open()},async upload(t){const e=t.target.files;if(1!==e.length)throw new Error("Загрузка возможна только по одному файлу");try{this.uploading=!0,await this.loadFile(e)}finally{t.target.value=null,setTimeout((()=>{this.uploading=!1,this.progress=0}),250)}},async loadFile(t){this.progress=0,this.progressText="Чтение файла...",await this.$nextTick(),this.filename=t[0].name;let e=this.filename.split(".").pop(),s=await l(t[0]),a=null;["xls","xlsx"].indexOf(e)>-1?(this.progressText="Обработка файла...",await this.$nextTick(),a=this.processXLS(s)):a=new Blob([s],{type:"application/octet-stream"}),this.progressText="Инициализация импорта...",await this.$nextTick();let r=await o.vd.query("CRM_LOAD_INIT_LOAD",{});console.log("prepareImport",r),this.loadDocId=r.RESULT,console.log("sendCSV"),this.progressText="Отправка файла...",await this.$nextTick();let i=new File([a],this.filename),n=await o.FH.fileStorage.uploadAttach(this.loadDocId,i,((t,e)=>{this.progress=Math.floor(100*t/e)}));this.progressText="Запуск...",await this.$nextTick(),await o.vd.query("CRM_LOAD RUN_PROCESS",{DOCUMENT_ID:this.documentId,LOAD_PATTERN_ID:this.patternId,ATTACH_ID:n},1),this.$refs.modal.close()},processXLS(t){console.log("processXLS");let e=new Uint8Array(t),s=i.LF(e,{type:"array"}),a=s.SheetNames[0],r=i.Wp.sheet_to_csv(s.Sheets[a],{FS:";",RS:"\r\n",blankrows:!1});return console.log("processXLS csv",r),this.filename=this.filename+".csv",new Blob([r],{type:"text/csv"})}}},d=n,u=s(1656),p=(0,u.A)(d,a,r,!1,null,null,null),c=p.exports}}]);
//# sourceMappingURL=ModalImportUpload.8b75540e.js.map