"use strict";(self["webpackChunkcarabi_x2"]=self["webpackChunkcarabi_x2"]||[]).push([[3213],{9796:function(t,n,e){e.r(n),e.d(n,{default:function(){return m}});var i=function(){var t=this,n=t._self._c;return!t.loaded||t.actions.length>0?n("ButtonMenu",{attrs:{title:t.title,dropdownTitle:"Выберите действие",icon:'<img src="img/icons/icon__actions.svg" uk-svg width="12" height="12" style="margin-top: -3px" />',showArrow:!0,buttonClasses:["uk-button","uk-button-primary","uk-button-small"],showListIcons:!1,items:t.menuItems,disabled:t.running},on:{select:function(n){return t.runAction(n.action)}}},[t.openedAction?n("modal-action-params",{attrs:{documentIds:t.documentIds,action:t.openedAction,params:t.openedActionParams,isReport:!1,cardId:t.cardId,onBeforeAction:t.onBeforeAction},on:{closed:function(n){t.openedAction=null},submit:t.submit,"mark-nulls":function(n){return t.$emit("mark-null-fields",n)}}}):t._e()],1):t._e()},o=[],s=e(3216),r=e(2643),a=e(2779),l=e(4041)["A"],d={name:"DocumentActions",components:{ButtonMenu:()=>e.e(2466).then(e.bind(e,6433)),ModalActionParams:()=>e.e(4726).then(e.bind(e,8150))},props:{documentIds:{type:Array,default:()=>[]},defaultActions:{type:Array,default:()=>[]},onBeforeAction:{type:Function,default:()=>null},cardId:{type:Number,default:()=>null},showTitle:{type:Boolean,default:()=>!0}},data(){return{loaded:!1,running:!1,actions:[],openedAction:null,openedActionParams:null}},computed:{docIdsStr(){return this.documentIds.join(",")},title(){return this.showTitle?this.running?"Выполняется...":"Действия":""},menuItems(){return this.actions.map((t=>({id:t.ID,title:t.NAME,action:t})))}},watch:{documentIds(){this.load()}},created(){this.load()},methods:{async load(){if(0===this.documentIds.length)return this.loaded=!0,void(this.actions=this.defaultActions);this.loaded=!1;let t=await Promise.all([s.vd.select("CRM_GET_DOCS_BP_ACTIONS_CS",{ID_LIST:this.docIdsStr},1e3)]);this.actions=t[0],this.loaded=!0},async runAction(t){a.dropdown(this.$refs.dropdown).hide(!1),this.running=!0;let n=await s.vd.select("CRM_GET_ACTION_PARAMS_CS",{ACTION_ID:t.ID},1e3);n.length>0?(this.running=!1,this.openedAction=t,this.openedActionParams=n):await this.runActionsSimple(this.documentIds,t)},async runActionsSimple(t,n){this.running=!0;try{this.onBeforeAction&&await this.onBeforeAction();let i=null;try{i=await s.vd.query("CRM_SET_DOCS_PARAM_ACTION4_CS",{DOCLIST:t.join(","),BP_ACTION_ID:n.ID,PARAM_LIST:"",CARD_ID:this.cardId},1),i.not_nulls&&(i.NOT_NULLS=i.not_nulls),i.errmess&&(i.ERRMESS=i.errmess)}catch(e){i={ERRMESS:(0,r.CS)(e)}}if(i.NOT_NULLS){let t=null;try{t=JSON.parse(i.NOT_NULLS)}catch(e){console.error("NotNull parse",e,i.NOT_NULLS)}t&&this.$emit("mark-null-fields",t)}if(i.ERRMESS){let t=i.ERRMESS.replace(/(?:\r\n|\r|\n)/g,"<br/>");l.alert(t)}}finally{this.running=!1,this.$emit("reload")}},submit(){this.$emit("reload"),this.openedAction=null}}},u=d,c=e(1656),h=(0,c.A)(u,i,o,!1,null,null,null),m=h.exports}}]);
//# sourceMappingURL=DocumentActions.8f8631e1.js.map