"use strict";(self.webpackChunkatk=self.webpackChunkatk||[]).push([[507],{42973:(t,e,i)=>{i.r(e),i.d(e,{default:()=>o});i(67242),i(90170),i(42359),i(9228),i(42381),i(98590),i(58189),i(74916),i(46345),i(14098),i(29747),i(77572),i(35817),i(67124),i(14947),i(45712),i(5127),i(73988),i(79192),i(74238),i(96180);var n=i(21145),s=i.n(n);const o={template:'<div class="item" :style="itemMargin">\n <i :class="toggleIcon" @click="onToggleShow" v-show="!isRoot"></i>\n <i :class="getIcon" @click="onToggleSelect" v-show="!isRoot"></i>\n <div class="content" >\n <div @click="onToggleSelect" :style="itemCursor">{{title}}</div>\n <div class="list" v-show="open || isRoot" v-if="isParent" >\n <atk-tree-item-selector v-for="(item, index) in item.nodes" :key="item.id" :item="item" :values="values">\n </atk-tree-item-selector>\n </div>\n </div>\n </div>',props:{item:Object,values:Array},inject:["getRootData"],name:"atk-tree-item-selector",data:function(){return{open:!1,isRoot:"atk-root"===this.item.id,isInitialized:!1,id:this.item.id,nodes:this.item.nodes,icons:{single:{on:"circle",off:"circle outline",indeterminate:"dot circle outline"},multiple:{on:"check square outline",off:"square outline",indeterminate:"minus square outline"}}}},created:function(){this.getInitData()},mounted:function(){},computed:{itemMargin:function(){return{marginLeft:this.item.nodes&&this.item.nodes.length>0?this.open?"-13px":"-10px":null}},itemCursor:function(){return{cursor:this.isParent&&"single"===this.getRootData().options.mode?"default":"pointer"}},title:function(){return this.item.name},isParent:function(){return this.nodes&&this.nodes.length>0},toggleIcon:function(){return this.isParent?(this.open?"caret down":"caret right")+" icon":null},state:function(){let t="off";return this.isParent?t=this.hasAllFill(this.nodes)?"on":this.hasSomeFill(this.nodes)?"indeterminate":"off":this.isSelected(this.id)&&(t="on"),t},getIcon:function(){return this.icons[this.getRootData().options.mode][this.state]+" icon"}},methods:{isSelected:function(t){return this.values.filter((e=>e===t)).length>0},getInitData:function(){this.getRootData().item.isInitialized||(this.getRootData().values=this.getValues(),this.getRootData().item.isInitialized=!0)},getValues:function(){const t=JSON.parse(this.getInputElement().value);let e=[];return Array.isArray(t)?e=t:e.push(t),e},hasAllFill:function(t){let e=!0;for(let i=0;i<t.length;i++)if(t[i].nodes&&t[i].nodes.length>0){if(!this.hasAllFill(t[i].nodes)){e=!1;break}}else if(-1===this.values.findIndex((e=>e===t[i].id))){e=!1;break}return e},hasSomeFill:function(t){let e=!1;for(let i=0;i<t.length;i++){if(t[i].nodes&&t[i].nodes.length>0&&this.hasSomeFill(t[i].nodes)){e=!0;break}if(this.values.findIndex((e=>e===t[i].id))>-1){e=!0;break}}return e},onToggleShow:function(){this.isParent&&(this.open=!this.open)},onToggleSelect:function(){const{options:t}=this.getRootData();switch(t.mode){case"single":this.handleSingleSelect();break;case"multiple":this.handleMultipleSelect()}},mergeArrays:function(){let t=[];for(var e=arguments.length,i=new Array(e),n=0;n<e;n++)i[n]=arguments[n];return i.forEach((e=>{t=[...t,...e]})),[...new Set([...t])]},collectAllChildren:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return t.forEach((t=>{t.nodes&&t.nodes.length>0?e.concat(this.collectAllChildren(t.nodes,e)):e.push(t.id)})),e},remove:function(t,e){return t.filter((t=>t!==e))},handleSingleSelect:function(){"off"!==this.state||this.isParent||(this.getRootData().values=[this.item.id],this.setInput(this.item.id),this.getRootData().options.url&&this.postValue()),this.isParent&&(this.open=!this.open)},handleMultipleSelect:function(){let t;if(this.isParent){const e=this.collectAllChildren(this.nodes);if("off"===this.state||"indeterminate"===this.state)t=this.mergeArrays(this.values,e);else{let i=this.values;e.forEach((t=>{i=this.remove(i,t)})),t=i}}else"on"===this.state?t=this.remove(this.values,this.item.id):"off"===this.state&&(t=this.values,t.push(this.item.id));this.getRootData().values=[...t],this.setInput(JSON.stringify(t)),this.getRootData().options.url&&this.postValue()},setInput:function(t){this.getInputElement().value=t},getInputElement:function(){return document.getElementsByName(this.getRootData().field)[0]},postValue:function(){s()(this.$el).parents("."+this.getRootData().options.loader).api({on:"now",url:this.getRootData().options.url,method:"POST",data:{data:JSON.stringify(this.getRootData().values)}})}}}}}]);
//# sourceMappingURL=atk-vue-tree-item-selector.min.js.map
|