var $url="/cms/material/video",$urlActionsDeleteGroup="/cms/material/video/actions/deleteGroup",$urlActionsPull="/cms/material/video/actions/pull",$urlActionsDownload="/cms/material/video/actions/download",data=utils.init({siteId:utils.getQueryInt("siteId"),groups:null,count:null,items:null,siteType:null,urlList:null,renameId:0,renameTitle:"",deleteId:0,selectedGroupId:0,form:{siteId:utils.getQueryInt("siteId"),keyword:"",groupId:-utils.getQueryInt("siteId"),page:1,perPage:24}}),methods={runUpdateGroups:function(t){this.groups=t},apiList:function(t){var i=this;this.form.page=t,utils.loading(this,!0),$api.get($url,{params:this.form}).then(function(t){var e=t.data;i.groups=e.groups,i.count=e.count,i.items=e.items,i.siteType=e.siteType,i.urlList=_.map(i.items,function(t){return t.url})}).catch(function(t){utils.error(t)}).then(function(){utils.loading(i,!1)})},apiDeleteGroup:function(){var t=this;utils.loading(this,!0),$api.delete($urlActionsDeleteGroup,{data:{siteId:this.siteId,id:this.form.groupId}}).then(function(i){i.data;t.form.groupId=0,t.apiList(1)}).catch(function(t){utils.error(t)})},apiDelete:function(t){var i=this;utils.loading(this,!0),$api.delete($url,{data:{siteId:this.siteId,id:t.id}}).then(function(t){t.data;utils.success("视频素材删除成功！"),i.apiList(1)}).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,groupId:this.form.groupId}).then(function(i){i.data;utils.success("公众号视频素材拉取成功！"),t.apiList(1)}).catch(function(t){utils.error(t)}).then(function(){utils.loading(t,!1)})},getLinkUrl:function(t){return utils.getCmsUrl("material"+t,{siteId:this.siteId})},getUploadUrl:function(){return $apiUrl+$url+"?siteId="+this.siteId+"&groupId="+this.form.groupId},btnTitleClick:function(t){var i=this;this.renameId=t.id,this.renameTitle=t.title,setTimeout(function(){var e=i.$refs["renameInput"+t.id][0];e&&(e.focus(),e.select())},100)},btnSelectGroupClick:function(t){this.selectedGroupId=this.selectedGroupId===t?0:t},btnSelectGroupSubmit:function(t){var i=this;utils.loading(this,!0),$api.put($url,{id:t.id,siteId:this.siteId,groupId:this.selectedGroupId,title:t.title}).then(function(e){e.data;utils.success("转移分组成功"),t.groupId=i.selectedGroupId,t.isSelectGroups=!1,i.selectedGroupId!==i.form.groupId&&0!==i.form.groupId&&i.btnSearchClick()}).catch(function(t){utils.error(t)}).then(function(){utils.loading(i,!1)})},btnRenameClick:function(t){var i=this;if(0!==this.renameId)return this.renameTitle?(this.renameId=0,t.title!==this.renameTitle&&(utils.loading(this,!0),$api.put($url,{id:t.id,siteId:this.siteId,groupId:t.groupId,title:this.renameTitle}).then(function(e){e.data;utils.success("编辑名称成功"),t.title=i.renameTitle}).catch(function(t){utils.error(t)}).then(function(){utils.loading(i,!1)}),!1)):(utils.error("名称不能为空"),!1)},btnGroupClick:function(t){var i=this;this.form.groupId=t,this.form.page=1,utils.loading(this,!0),$api.get($url,{params:this.form}).then(function(t){var e=t.data;i.groups=e.groups,i.count=e.count,i.items=e.items,i.urlList=_.map(i.items,function(t){return t.url})}).catch(function(t){utils.error(t)}).then(function(){utils.loading(i,!1)})},btnPullClick:function(){var t=this;utils.alertWarning({title:"拉取公众号视频素材",text:"此操作将拉取公众号视频素材，确认吗？",callback:function(){t.apiPull()}})},btnGroupAddClick:function(){utils.openLayer({title:"新建分组",url:utils.getCmsUrl("materialLayerGroupAdd",{siteId:this.siteId,materialType:"Video"}),width:400,height:260})},btnGroupEditClick:function(){utils.openLayer({title:"编辑分组",url:utils.getCmsUrl("materialLayerGroupAdd",{siteId:this.siteId,groupId:this.form.groupId,materialType:"Video"}),width:400,height:260})},btnDownloadClick:function(t){window.open($apiUrl+$urlActionsDownload+"?siteId="+this.siteId+"&id="+t.id+"&access_token="+$token)},btnGroupDeleteClick:function(){var t=this;utils.alertDelete({title:"删除分组",text:"仅删除分组，不删除视频，组内视频将自动归入未分组",callback:function(){t.apiDeleteGroup()}})},btnDeleteClick:function(t){var i=this;utils.alertDelete({title:"删除素材",text:"确定删除此素材吗？",callback:function(){i.apiDelete(t)}})},btnSearchClick(){utils.loading(this,!0),this.apiList(1)},btnPageClick:function(t){utils.loading(this,!0),this.apiList(t)},uploadProgress:function(){utils.loading(this,!0)},uploadSuccess:function(t){this.items.splice(0,0,t),this.count++,utils.loading(this,!1)},uploadError:function(t){utils.loading(this,!1);var i=JSON.parse(t.message);utils.error(i.message)}},$vue=new Vue({el:"#main",data:data,methods:methods,created:function(){this.apiList(1)}});