var $url="/settings/homeMenus",data=utils.init({userMenus:null,groups:null,expandRowKeys:[],userMenu:null,defaultOpeneds:[],defaultActive:null}),methods={btnSideMenuOpen:function(t){var e=_.find(this.userMenus,function(e){return e.id==t});this.userMenu=_.assign({},e),this.userMenu.groupIds||(this.userMenu.groupIds=[]),this.defaultActive=t},btnSideMenuClick:function(t){for(var e=(t+"").split("/"),n=this.userMenus,i=null,u=[],s=0;s<e.length;s++)n=(i=_.find(n,function(t){return t.id==e[s]})).children,u.push(i.id);this.defaultOpeneds=u,i&&this.btnMenuClick(i)},btnMenuClick:function(t){this.defaultActive=this.defaultOpeneds.join("/"),this.userMenu=_.assign({},t),this.userMenu.groupIds||(this.userMenu.groupIds=[])},getIndex:function(t,e,n){return n?t.id+"/"+e.id+"/"+n.id:e?t.id+"/"+e.id:t?t.id:""},apiGet:function(){var t=this;utils.loading(this,!0),$api.get($url).then(function(e){var n=e.data;t.userMenus=t.getItems(n.userMenus),t.groups=n.groups}).catch(function(t){utils.error(t)}).then(function(){utils.loading(t,!1)})},apiDelete:function(t){var e=this;utils.loading(this,!0),$api.delete($url,{data:{id:t}}).then(function(t){var n=t.data;e.userMenus=e.getItems(n.userMenus),e.userMenu=null}).catch(function(t){utils.error(t)}).then(function(){utils.loading(e,!1)})},apiReset:function(){var t=this;utils.loading(this,!0),$api.post($url+"/actions/reset").then(function(e){var n=e.data;t.userMenus=t.getItems(n.userMenus),t.userMenu=null}).catch(function(t){utils.error(t)}).then(function(){utils.loading(t,!1)})},apiSubmit:function(t){var e=this;utils.loading(this,!0),$api.post($url,t).then(function(n){var i=n.data;e.userMenu=null,e.userMenus=e.getItems(i.userMenus),utils.success(0===t.id?"用户菜单新增成功！":"用户菜单修改成功！")}).catch(function(t){utils.error(t)}).then(function(){utils.loading(e,!1)})},getItems:function(t){for(var e=[],n=0;n<t.length;n++){0===(i=t[n]).parentId&&(i.children=[],e.push(i))}for(n=0;n<t.length;n++){var i;if((i=t[n]).parentId>0){var u=_.find(e,function(t){return t.id===i.parentId});u&&u.children.push(i)}}return e},getCardTitle:function(){return 0!==this.userMenu.id?"修改菜单":this.userMenu.parentId>0?"新增下级菜单":"新增一级菜单"},btnAddChildClick:function(){var t=this.userMenu?this.userMenu.id:0,e=0,n=null;t>0&&(n=this.userMenus.find(function(e){return e.id===t})),n?_.forEach(n.children,function(t){t.taxis>e&&(e=t.taxis)}):0===t&&_.forEach(this.userMenus,function(t){t.taxis>e&&(e=t.taxis)}),this.userMenu={id:0,disabled:!1,parentId:t,taxis:e+1,text:"",link:"",iconClass:"",target:"",isGroup:!1,groupIds:[]},this.defaultActive=null},btnAddFirstClick:function(){var t=0;_.forEach(this.userMenus,function(e){e.taxis>t&&(t=e.taxis)}),this.userMenu={id:0,disabled:!1,parentId:0,taxis:t+1,text:"",link:"",iconClass:"",target:"",isGroup:!1,groupIds:[]},this.defaultActive=null},btnResetClick:function(){var t=this;utils.alertDelete({title:"重置用户菜单",text:"此操作将把用户菜单恢复为系统默认值，确定吗？",button:"确认重置",callback:function(){t.apiReset()}})},btnDeleteClick:function(){var t=this;utils.alertDelete({title:"删除用户菜单",text:"此操作将删除用户菜单及其下级菜单，确定吗？",callback:function(){t.apiDelete(t.userMenu.id)}})},btnSubmitClick:function(){var t=this;this.$refs.userMenu.validate(function(e){e&&t.apiSubmit(t.userMenu)})},btnCancelClick:function(){this.userMenu=null}},$vue=new Vue({el:"#main",data:data,methods:methods,created:function(){this.apiGet()}});