"use strict";(self["webpackChunkcarabi_x2"]=self["webpackChunkcarabi_x2"]||[]).push([[4597],{3354:function(t,e,a){a.r(e),a.d(e,{default:function(){return f}});var o=function(){var t=this,e=t._self._c;return e("Modal",{ref:"modal",attrs:{title:"Загрузка",autoOpen:!0,fullHeight:!1,large:!1},on:{closed:function(e){return t.$emit("closed")}}},[e("div",{staticClass:"uk-padding-small"},[e("div",{},[t._v(" Формат: "),t._l(t.formats,(function(a){return e("label",{key:a,staticClass:"uk-margin-left",on:{click:function(e){t.format=a}}},[e("input",{staticClass:"uk-radio",attrs:{type:"radio"},domProps:{checked:t.format===a}}),t._v(" "+t._s(a)+" ")])}))],2),e("div",{staticClass:"uk-margin-top"},[t._v(" Максимум записей: "),e("input",{directives:[{name:"model",rawName:"v-model",value:t.maxRecords,expression:"maxRecords"}],staticClass:"uk-input uk-form-small uk-margin-left",staticStyle:{width:"100px"},domProps:{value:t.maxRecords},on:{input:function(e){e.target.composing||(t.maxRecords=e.target.value)}}})])]),e("div",{staticClass:"uk-modal-footer uk-text-center"},[e("button",{staticClass:"uk-button uk-modal-close uk-border-rounded",attrs:{type:"button"}},[t._v("Отмена")]),e("button",{staticClass:"js-save uk-button uk-button-primary uk-border-rounded",attrs:{disabled:t.saving,type:"button"},on:{click:t.download}},[t._v("Сохранить")])])])},n=[],l=a(3216),s=a(6182),r=a(4195),i=a(2643);function c(t,e,a){var o=new Blob([t],{type:e}),n=document.createElement("a");n.download=a,n.href=URL.createObjectURL(o),n.dataset.downloadurl=[e,n.download,n.href].join(":"),n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),setTimeout((function(){URL.revokeObjectURL(n.href)}),1500)}var d={name:"ExportDownload",components:{Loader:()=>a.e(8326).then(a.bind(a,1259)),Modal:()=>a.e(8362).then(a.bind(a,2215))},props:{docKindName:Object,exportTitle:String,xmlColumns:String,xmlFilter:String},data:()=>({format:"xlsx",maxRecords:"500",saving:!1}),computed:{formats(){return["xlsx","csv","xml"]}},methods:{async download(){this.saving=!0;try{let t=parseInt(this.maxRecords);if(!t||t<=0)throw new i.yo('"Максимум записей" задано некорректно');if("xml"===this.format)return void await this.downloadXml(this.xmlColumns,this.xmlFilter);let e=await l.vd.select("CRM_GET_XML_DOCQUERY_FIELDS_CS",{XML:this.xmlColumns},1e3),a=await(0,s.A)(e,this.xmlColumns,this.xmlFilter,null,t);"csv"===this.format?this.downloadCsv(e,a):"xlsx"===this.format&&this.downloadXlsx(e,a),this.saving=!1}finally{this.saving=!1}},downloadXlsx(t,e){let a="безымянный";this.exportTitle&&(a=this.exportTitle);let o=t.map((t=>({name:t.NAME_FIELD,title:t.DESCR_FIELD})));(0,r.l9)(a,o,e)},downloadCsv(t,e){function a(t){return t.map((t=>(null===t&&(t=""),t=""+t,'"'+t.replace("\r","").replace("\n"," ").replace('"','""')+'"'))).join(";")+"\r\n"}let o=a(t.map((t=>t.DESCR_FIELD)));for(let l of e)o+=a(t.map((t=>l[t.NAME_FIELD])));let n="безымянный";this.exportTitle&&(n=this.exportTitle),c(o,"text/csv",n+".csv")},async downloadXml(t,e){let a=await l.FH.gateway.serverHttp("POST","doc-data-importer/export-xml",{columnsXml:t,filterXml:e});c(a.xml,"text/csv",this.docKindName+"_data.xml")}}},u=d,m=a(1656),p=(0,m.A)(u,o,n,!1,null,null,null),f=p.exports},4195:function(t,e,a){a.d(e,{Bt:function(){return r},l9:function(){return s}});var o=a(3230);function n(t,e){return t?t.length>e?t.substring(0,e-3)+"...":t:""}function l(t){return t[0].map(((e,a)=>({wch:Math.max(...t.map((t=>t[a]?t[a].toString().length:0)))})))}function s(t,e,a){let o=[e.map((t=>t.title))];for(let n of a)o.push(e.map((t=>n[t.name])));r(t,o)}function r(t,e){let a=o.Wp.aoa_to_sheet(e);a["!cols"]=l(e);let s=n(t,30),r=o.Wp.book_new();o.Wp.book_append_sheet(r,a,s),o._h(r,t+".xlsx")}},6182:function(t,e,a){a.d(e,{A:function(){return r}});var o=a(9148),n=a.n(o),l=a(3216);function s(t,e){return n()(t,"DD.MM.YYYY HH:mm:ss").format(e)}async function r(t,e,a,o,n,r){let i=await l.vd.select("CRM_GET_VALUE_DATA_SEARCH_X_CS",{XML_FILTER:a,XML_VALUES:e,ORDER_BY:o},n,r);for(let l of i)for(let e of t){let t=l[e.NAME_FIELD];if(t){switch(e.TYPE_DESCR_FIELD){case"phone":t=t.split("^"),t="+"+t[0]+" ("+t[1]+") "+t[2];break;case"date":t=s(t,"DD.MM.YYYY");break;case"dateTime":t=s(t,"DD.MM.YYYY HH:mm");break;case"dateTimeSec":t=s(t,"DD.MM.YYYY HH:mm:ss");break;case"time":t=s(t,"HH:mm:ss");break;case"hourMinutes":t=s(t,"HH:mm");break;case"monthYear":t=s(t,"MM.YYYY");break}l[e.NAME_FIELD]=t}}return i}}}]);
//# sourceMappingURL=ExportDownload.1e2a084d.js.map