"use strict";(self["webpackChunkcarabi_x2"]=self["webpackChunkcarabi_x2"]||[]).push([[177],{3257:function(e,t,a){var i=a(6848),l=a(3216);class s{constructor(){this.rootId=0,this.rootName="",this.doclistId=0,this.dockindId=0,this.onTreeChange=[],this.data=i.Ay.observable({loaded:!1,tree:[],curNode:null,hasTree:!1})}clear(){}async fetchBranch(e){let t=[];return this.doclistId?t=await l.FH.queries.select("APPL_BP_CS.GET_RES_TREE_LEVEL",{CARABI_DOCLIST_ID:this.doclistId,START_NODE:e?e.row.RES_CODE:""},1e4):this.dockindId?t=await l.FH.queries.select("APPL_BP_CS.GET_REF_RES_TREE_LEVEL",{DOCKIND_ID:this.dockindId,START_NODE:e?e.row.RES_CODE:""},1e4):this.rootName&&(t=await l.FH.queries.select("APPL_BP_CS.GET_RES_TREE_LEVEL2",{START_NODE:e?e.row.RES_CODE:this.rootName},1e4)),t.map((t=>({row:t,parent:e,loading:!1,children:null})))}async reloadChildren(e){console.log("reloadChildren",e,this.data.curNode);let t=e?e.children:this.data.tree,a=this.data.curNode?.row.RES_ID;if(e?(e.loading=!0,e.children=await this.fetchBranch(e),t=e.children):(this.data.tree=await this.fetchBranch(null),t=this.data.tree),console.log("newChidren",t,"curCode",a),a){let e=t.find((e=>e.row.RES_ID===a));e&&(this.data.curNode=e)}this.trigTreeChange(e)}async loadChildren(e){null!==e.children||e.loading||(e.loading=!0,e.children=await this.fetchBranch(e),this.trigTreeChange(e))}async reload(){this.data.tree=await this.fetchBranch(null),this.data.hasTree=this.data.tree.length>0,this.data.loaded=!0}getCurPath(){if(!this.data.curNode)return[];let e=[this.data.curNode.row.RES_CODE],t=this.data.curNode.parent;while(null!==t)e.push(t.row.RES_CODE),t=t.parent;return e=e.reverse(),e}async setByPathNode(e,t){console.log("setByPathNode",e,t),console.log("openPath",t),await this.loadChildren(e);let a=e.children.find((e=>e.row.RES_CODE===t[0]));a?t.length<=1?this.setCurNode(a):await this.setByPathNode(a,t.slice(1)):console.error("Не найден элемент",t[0])}async setByPath(e){if(console.log("setByPath",e),0===e.length)return void this.setCurNode(null);let t=this.data.tree.find((t=>t.row.RES_CODE===e[0]));t?e.length<=1?this.setCurNode(t):await this.setByPathNode(t,e.slice(1)):console.error("Не найден элемент",e[0])}setCurNode(e){this.data.curNode=e}trigTreeChange(e){this.onTreeChange.forEach((t=>t(e)))}}t.A=s},8776:function(e,t,a){a.r(t),a.d(t,{default:function(){return c}});var i=function(){var e=this,t=e._self._c;return t("modal",{ref:"modal",attrs:{title:e.field.DOCPROP_NAME,fullHeight:!0,large:!1,autoOpen:!0},on:{closed:e.closed}},[t("div",{staticClass:"uk-flex uk-flex-column",staticStyle:{flex:"1","min-height":"1px"}},[e.loaded?t("classificator-tree",{attrs:{model:e.model,writable:!e.field.DOCPROP_READONY},on:{"reload-tree":function(t){return e.model.reloadTree(t)},confirm:function(t){return e.nodeConfirm(t)}}}):e._e()],1),t("div",{staticClass:"uk-padding-small uk-text-center",staticStyle:{"border-top":"1px solid #d5e1e6"}},[t("button",{staticClass:"uk-modal-close uk-button"},[t("i",{staticClass:"uk-icon-close"}),e._v(" Отмена ")]),t("button",{staticClass:"uk-button uk-button-primary uk-margin-small-left",on:{click:e.save}},[t("i",{staticClass:"uk-icon-floppy-o"}),e._v(" Применить ")])])])},l=[],s=a(3216),o=a(3257),r={name:"fieldClassifModal",components:{Modal:()=>a.e(8362).then(a.bind(a,2215)),ClassificatorTree:()=>Promise.all([a.e(5607),a.e(432)]).then(a.bind(a,5526))},props:{field:Object,value:{type:[String,Array],default:null}},data:()=>({model:new o.A,newValue:null}),computed:{curClassif(){let e=this.model.data.curNode;return console.log("curNode",e),!e||e.root?null:e.row},loaded(){return this.model.data.loaded}},async mounted(){if(this.model.rootName=this.field.DOCPROP_SQL,await this.model.reload(),this.value&&"string"===typeof this.value){let e=await s.FH.queries.select("APPL_BP_CS.GET_REF_RES_TREE_LEVEL_PATH",{RES_CODE:this.value},100);e=e.map((e=>e.RES_CODE));let t=e.findIndex((e=>e===this.field.DOCPROP_SQL));e=e.slice(t+1),await this.model.setByPath(e)}},methods:{async nodeConfirm(e){console.log("nodeConfirm",e),e.root?this.model.setCurNode(null):this.model.setCurNode(e),await this.$nextTick(),console.log("newVal",this.curClassif?.RES_CODE),this.save()},save(){let e=this.curClassif?.RES_CODE;this.field.DOCPROP_MULTI&&(e=e?[e]:[]),this.newValue={value:e,display:this.curClassif?.RES_NAME},this.$refs.modal.close()},closed(){this.newValue?this.$emit("change",this.newValue):this.$emit("close")}}},n=r,d=a(1656),h=(0,d.A)(n,i,l,!1,null,null,null),c=h.exports}}]);
//# sourceMappingURL=FieldClassifModal.529f67c0.js.map