"use strict";(self["webpackChunkcarabi_x2"]=self["webpackChunkcarabi_x2"]||[]).push([[432],{5526:function(e,t,r){r.r(t),r.d(t,{default:function(){return h}});var o=function(){var e=this,t=e._self._c;return t("div",{staticStyle:{padding:"0",flex:"1","min-height":"1px"}},[t("LiquorTree",{ref:"tree",staticStyle:{height:"100%"},attrs:{data:[],options:e.treeOptions},on:{"tree:mounted":e.treeMounted,"node:expanded":e.nodeExpanded,"node:selected":e.nodeSelected,"node:dblclick":e.nodeConfirm},scopedSlots:e._u([{key:"default",fn:function({node:r}){return t("div",{staticClass:"tree-text"},[t("img",{staticClass:"tree-text--icon",attrs:{src:"img/icons/icon__doc.svg","uk-svg":"",width:"16",height:"16"}}),t("span",{staticClass:"tree-text--content"},[e._v(" "+e._s(r.text))])])}}])})],1)},n=[],d=r(3020),i={name:"ClassificatorTree",components:{PanelHead:()=>r.e(3321).then(r.bind(r,547)),LiquorTree:d["default"]},props:{model:Object,writable:{type:Boolean,default:!1}},data(){return{treeData:[],curTreeNode:null,openingPath:!1}},computed:{curNode(){return this.model.data.curNode},modelData(){return this.model.data.tree},treeOptions(){return{}}},watch:{curNode(){this.syncTree()}},beforeDestroy(){this.model.onTreeChange=this.model.onTreeChange.filter((e=>e!==this.treeChange))},methods:{makeTree(){let e=this.$refs.tree.getRootNode();console.log("rootNodes",e,typeof e),e.id&&e.remove();let t=[];for(let r of this.model.data.tree)t.push(this.createNode(r));this.treeData={id:0,text:"Все записи",state:{expanded:!0},loaded:!0,data:{root:!0,RS_ID:0},children:t},this.$refs.tree.append(this.treeData),this.syncTree()},findNode(e,t){if(t||(t=this.$refs.tree.getRootNode()),!t.children)return null;for(let r in t.children){let o=t.children[r];if(o.data.row){if(o.data.row.RS_ID===e)return o;{let t=this.findNode(e,o);if(t)return t}}}return null},refreshNodeChildren(e){if(console.log("refreshNodeChildren",e,e?.data,e?.data?.children),e.children.length>0){for(let t in e.children)e.children[t].remove();e.children=[]}if(!e.data.children)return;let t=[];for(let r of e.data.children)t.push(this.createNode(r));e.append(t)},async treeMounted(){await this.makeTree(),this.treeChange=e=>{if(!e)return void this.makeTree();let t=this.findNode(e.row.RS_ID);console.log("treeChange",e,t),t&&this.refreshNodeChildren(t)},this.model.onTreeChange.push(this.treeChange)},createNode(e){let t={id:e.row.RS_ID,text:e.row.RES_NAME,data:e};return e.row.CHILDREN_COUNT>0&&(t.children=[{text:"Загрузка..."}]),t},syncTree(){if(this.curNode===this.curTreeNode?.data)return;if(null===this.curNode)return this.curTreeNode=this.$refs.tree.getRootNode(),void this.curTreeNode.select();let e=this.model.getCurPath();this.openPath(this.$refs.tree.getRootNode(),e).then()},async openPath(e,t){this.openingPath=!0,console.log("openPath",t),await this.model.loadChildren(e.data),e.expand();let r=e.children.find((e=>e.data.row.RES_CODE===t[0]));if(!r)return this.openingPath=!1,void console.error("Не найден элемент",t[0]);t.length<=1?(r.select(),this.openingPath=!1):await this.openPath(r,t.slice(1))},async nodeExpanded(e){console.log("nodeExpanded",e),await this.model.loadChildren(e.data)},nodeSelected(e){this.openingPath||(console.log("nodeSelected",e),this.curTreeNode=e,e.data.root?this.model.setCurNode(null):this.model.setCurNode(e.data))},nodeConfirm(e){this.$emit("confirm",e.data)}}},a=i,s=r(1656),l=(0,s.A)(a,o,n,!1,null,null,null),h=l.exports}}]);
//# sourceMappingURL=ClassificatorTree.178643e9.js.map