"use strict";(self["webpackChunkcarabi_x2"]=self["webpackChunkcarabi_x2"]||[]).push([[7390],{7667:function(e,s,t){t.r(s),t.d(s,{default:function(){return d}});var a=function(){var e=this,s=e._self._c;return s("Modal",{ref:"modal",attrs:{title:"Уведомления",large:!0,autoOpen:!0},on:{closed:function(s){return e.$emit("closed")}}},[s("div",{staticStyle:{"flex-grow":"1","min-height":"1px",position:"relative",display:"flex","flex-direction":"row"}},[s("div",{staticClass:"uk-visible@l",staticStyle:{"min-width":"250px",overflow:"auto",position:"relative"}},[null===e.categories?s("loader"):s("ul",{staticClass:"uk-nav uk-nav-default uk-padding-small"},[s("li",{class:{"uk-active":null===e.curCategory}},[s("a",{attrs:{href:"#"},on:{click:function(s){s.preventDefault(),e.curCategory=null}}},[e._v(" Все уведомления ")])]),e._l(e.categories,(function(t){return s("li",{key:t.MESSAGE_TYPE,class:{"uk-active":e.curCategory&&e.curCategory.MESSAGE_TYPE===t.MESSAGE_TYPE}},[s("a",{attrs:{href:"#"},on:{click:function(s){s.preventDefault(),e.curCategory=t}}},[e._v(" "+e._s(t.NAME_TYPE)+" "),t.UREAD_COUNT?s("span",[e._v(" ("+e._s(t.UREAD_COUNT)+")")]):e._e()])])}))],2)],1),s("div",{staticStyle:{"flex-grow":"1","min-width":"1px",display:"flex","flex-direction":"column",position:"relative"}},[!e.messages.length&&e.loading?s("loader"):e.messages.length?s("div",{ref:"messages",staticStyle:{"flex-grow":"1","min-height":"1px",overflow:"auto"},on:{scroll:e.messagesScroll}},[s("ul",{staticClass:"pos-list"},e._l(e.messages,(function(t){return s("list-item",{key:t.EVENT_ID,attrs:{emphasis:!t.READ_CONFIRM,footer:e.messageFooter(t),cover:!0,actions:e.msgActions(t)},on:{action:function(e){return e.run()}}},[s("div",{class:{"uk-text-muted":t.READ_CONFIRM}},[e._v(e._s(t.DOC_CONTENT))])])})),1)]):s("div",{staticClass:"uk-padding-small"},[s("h3",[e._v("Нет уведомлений")])]),s("div",{staticClass:"uk-padding-small uk-text-center"},[s("button",{staticClass:"uk-button uk-button-default uk-button-small",on:{click:function(s){return s.preventDefault(),e.markAllAsRead.apply(null,arguments)}}},[e._v(" Отметить все уведомления ")])])],1)])])},l=[],i=t(3216),n=t(5512),r=t(9148);var o={name:"ModalMessages",components:{Modal:()=>t.e(8362).then(t.bind(t,2215)),listItem:()=>t.e(8110).then(t.bind(t,6250)),Loader:()=>t.e(8326).then(t.bind(t,1259))},data(){return{categories:null,curCategory:null,messages:[],fetcher:!1,loading:!1,fetchCount:20}},computed:{},watch:{async curCategory(){await this.reloadMessages()}},mounted(){this.reload(),this.interval=setInterval((()=>{this.reload()}),6e4)},beforeDestroy(){this.interval&&(clearInterval(this.interval),this.interval=null)},methods:{async reloadCat(){this.categories=await i.vd.select("CRM_NOTIFICATION_CATEGORY_LIST_CS",{},100)},async reloadMessages(){this.fetcher=!0,this.loading=!1,this.messages=[],await this.loadMessages(),setTimeout((()=>{this.messagesScroll()}),0)},async loadMessages(){if(this.loading)return;this.loading=!0;let e=await i.vd.select("CRM_MSG_LIST_CS",{SEARCH:"",DOCKIND_NAMEVAR:this.curCategory?this.curCategory.MESSAGE_TYPE:""},this.fetchCount,this.messages.length);e=e.map((e=>({...e,SENT_DATE:i.vd.dateToIso(e.SENT_DATE),DOCFORMZ_ID:-1!==e.DOCFORMZ_ID?e.DOCFORMZ_ID:0}))),this.messages=[...this.messages,...e],e.length<this.fetchCount&&(this.fetcher=!1),this.loading=!1},async reload(){await Promise.all([this.reloadCat(),this.reloadMessages()])},async messagesScroll(){if(!this.$refs.messages||!this.fetcher)return;let e=this.$refs.messages;if(!e.clientHeight)return;let s=Math.ceil(e.scrollTop+2*e.clientHeight),t=Array.from(e.children).reduce(((e,s)=>e+s.offsetHeight),0);s<t||(console.log("messagesScroll",s,t,e.clientHeight),await this.loadMessages(),setTimeout((()=>{this.messagesScroll()}),0))},messageFooter(e){let s=[{name:"",value:r(e.SENT_DATE).format("DD.MM.YY HH:mm")},{name:"",value:e.DOCKIND_NAME},{name:"",value:e.SENT_USERNAME}];return s},async markAllAsRead(){let e=this.messages.filter((e=>0===e.READ_CONFIRM)),s=[];e.forEach((e=>{s.push(e.EVENT_ID)})),s=s.join(","),e.forEach((e=>{e.READ_CONFIRM=1})),console.log("unreadedIds",s),await i.vd.query("CRM_SET_MSGS_READ_CS",{event_list:s,settled:1})},msgActions(e){let s=[];return e.DOCFORMZ_ID&&s.push({run:()=>this.messageOpen(e),label:"Открыть"}),e.READ_CONFIRM||s.push({run:()=>this.messageRead(e),label:"Прочитано"}),s.push({run:()=>this.messageDel(e),label:"Удалить"}),s},messageOpen(e){this.messageRead(e),e.DOCFORMZ_ID&&(n.A.openDocument(e.DOCFORMZ_ID),this.$refs.modal.close())},messageRead(e){i.vd.query("CRM_SET_MSGS_READ_CS",{event_list:e.EVENT_ID,settled:1}).then(),e.READ_CONFIRM=1},messageDel(e){i.vd.query("CRM_DELETE_MSG_CS",{EVENT_ID:e.EVENT_ID}).then();let s=this.messages.findIndex((s=>s.EVENT_ID===e.EVENT_ID));console.log("!!!",s),-1!==s&&this.messages.splice(s,1)}}},c=o,u=t(1656),h=(0,u.A)(c,a,l,!1,null,null,null),d=h.exports}}]);
//# sourceMappingURL=ModalMessages.71b69bf7.js.map