var $url="/wx/menus",$urlActionsPull="/wx/menus/actions/pull",$urlActionsPush="/wx/menus/actions/push",data=utils.init({siteId:utils.getQueryInt("siteId"),menuTypes:null,wxMenus:null,firstMenuIds:null,expandRowKeys:[],wxMenu:null,defaultOpeneds:[],defaultActive:null}),methods={btnSideMenuOpen:function(t){var i=_.find(this.wxMenus,function(i){return i.id==t});this.wxMenu=_.assign({},i),this.defaultActive=t},btnSideMenuClick:function(t){for(var i=(t+"").split("/"),n=this.wxMenus,e=null,u=[],s=0;s<i.length;s++)n=(e=_.find(n,function(t){return t.id==i[s]})).children,u.push(e.id);this.defaultOpeneds=u,e&&this.btnMenuClick(e)},btnMenuClick:function(t){this.defaultActive=this.defaultOpeneds.join("/"),this.wxMenu=_.assign({},t)},getIndex:function(t,i,n){return n?t.id+"/"+i.id+"/"+n.id:i?t.id+"/"+i.id:t?t.id:""},apiGet:function(){var t=this;utils.loading(this,!0),$api.get($url,{params:{siteId:this.siteId}}).then(function(i){var n=i.data;t.menuTypes=n.menuTypes,t.wxMenus=t.getItems(n.wxMenus)}).catch(function(t){utils.error(t)}).then(function(){utils.loading(t,!1)})},apiDelete:function(t){var i=this;utils.loading(this,!0),$api.delete($url,{data:{siteId:this.siteId,id:t}}).then(function(t){var n=t.data;i.wxMenus=i.getItems(n.wxMenus),i.wxMenu=null}).catch(function(t){utils.error(t)}).then(function(){utils.loading(i,!1)})},apiSubmit:function(t){var i=this;utils.loading(this,!0),$api.post($url,{siteId:this.siteId,id:t.id,parentId:t.parentId,taxis:t.taxis,text:t.text,menuType:t.menuType,key:t.key,url:t.url,appId:t.appId,pagePath:t.pagePath,mediaId:t.mediaId}).then(function(n){var e=n.data;i.wxMenu=null,i.wxMenus=i.getItems(e.wxMenus),utils.success(0===t.id?"用户菜单新增成功！":"用户菜单修改成功！")}).catch(function(t){utils.error(t)}).then(function(){utils.loading(i,!1)})},apiPull:function(){var t=this;utils.loading(this,!0),$api.post($urlActionsPull,{siteId:this.siteId}).then(function(i){var n=i.data;utils.success("微信菜单拉取成功！"),t.wxMenu=null,t.wxMenus=t.getItems(n.wxMenus)}).catch(function(t){utils.error(t)}).then(function(){utils.loading(t,!1)})},apiPush:function(){var t=this;utils.loading(this,!0),$api.post($urlActionsPush,{siteId:this.siteId}).then(function(i){i.data;utils.success("微信菜单推送成功，需要24小时后或取消关注后重新关注才能看到效果！"),t.wxMenu=null}).catch(function(t){utils.error(t)}).then(function(){utils.loading(t,!1)})},getItems:function(t){for(var i=[],n=0;n<t.length;n++){0===(e=t[n]).parentId&&(e.children=[],i.push(e))}for(n=0;n<t.length;n++){var e;if((e=t[n]).parentId>0){var u=_.find(i,function(t){return t.id===e.parentId});u&&u.children.push(e)}}return this.firstMenuIds=_.map(i,function(t){return t.id}),i},getCardTitle:function(){return 0!==this.wxMenu.id?"修改菜单":this.wxMenu.parentId>0?"新增下级菜单":"新增一级菜单"},btnAddChildClick:function(){var t=this.wxMenu?this.wxMenu.id:0,i=0,n=null;if(t>0&&(n=this.wxMenus.find(function(i){return i.id===t})),n){if(n.children.length>=5)return utils.error("子菜单最多创建5个");_.forEach(n.children,function(t){t.taxis>i&&(i=t.taxis)})}else 0===t&&_.forEach(this.wxMenus,function(t){t.taxis>i&&(i=t.taxis)});this.wxMenu={id:0,parentId:t,taxis:i+1,text:"",menuType:"click",key:"",url:"",appId:"",pagePath:"",mediaId:""},this.defaultActive=null},btnAddFirstClick:function(){if(this.wxMenus.length>=3)return utils.error("主菜单最多创建3个");var t=0;_.forEach(this.wxMenus,function(i){i.taxis>t&&(t=i.taxis)}),this.wxMenu={id:0,siteId:this.siteId,parentId:0,taxis:t+1,text:"",menuType:"click",key:"",url:"",appId:"",pagePath:"",mediaId:""},this.defaultActive=null},btnPullClick:function(){var t=this;utils.alertDelete({title:"拉取微信菜单",text:"此操作将获取微信公众号的菜单，当前设置的菜单将被覆盖，确定吗？",button:"拉 取",callback:function(){t.apiPull()}})},btnPushClick:function(){var t=this;utils.alertDelete({title:"推送微信菜单",text:"此操作将推送当前菜单至微信公众号，确定吗？",button:"推 送",callback:function(){t.apiPush()}})},btnDeleteClick:function(){var t=this;utils.alertDelete({title:"删除用户菜单",text:"此操作将删除用户菜单及其下级菜单，确定吗？",callback:function(){t.apiDelete(t.wxMenu.id)}})},btnSubmitClick:function(){var t=this;this.$refs.wxMenu.validate(function(i){i&&t.apiSubmit(t.wxMenu)})},btnCancelClick:function(){this.wxMenu=null}},$vue=new Vue({el:"#main",data:data,methods:methods,created:function(){this.apiGet()}});