var $url="/cms/material/message",$urlActionsDeleteGroup="/cms/material/message/actions/deleteGroup",$urlActionsPull="/cms/material/message/actions/pull",data=utils.init({siteId:utils.getQueryInt("siteId"),showType:"card",groups:null,count:null,messages: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.messages=e.messages,i.siteType=e.siteType,i.urlList=_.map(i.messages,function(t){return t.thumbUrl})}).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)})},getEditorUrl:function(){return utils.getCmsUrl("materialEditor",{siteId:this.siteId,groupId:this.form.groupId,page:this.form.page,tabName:utils.getTabName()})},getGroupName:function(){var t=this;return this.form.groupId>0?_.find(this.groups,function(i){return i.id===t.form.groupId}).groupName:""},getUploadUrl:function(){return $apiUrl+$url+"?siteId="+this.siteId+"&groupId="+this.form.groupId},btnCreateClick:function(){utils.addTab("创建图文消息",this.getEditorUrl())},btnUpdateClick:function(t){utils.addTab("修改图文消息",this.getEditorUrl()+"&messageId="+t.id)},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}).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.messages=e.messages,i.urlList=_.map(i.messages,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:"Message"}),width:400,height:260})},btnGroupEditClick:function(){utils.openLayer({title:"编辑分组",url:utils.getCmsUrl("materialLayerGroupAdd",{siteId:this.siteId,groupId:this.form.groupId,materialType:"Message"}),width:400,height:260})},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)},uploadBefore:t=>!!/(\.docx)$/i.exec(t.name)||(utils.error("文件只能是以.docx结尾的 Word 格式，请选择有效的文件上传!"),!1),uploadProgress:function(){utils.loading(this,!0)},uploadSuccess:function(t){this.apiList(1),utils.loading(this,!1)},uploadError:function(t){utils.loading(this,!1);var i=JSON.parse(t.message);utils.error(i.message)},getFriendlyContent:function(t){if(1===t.items.length)return t.items[0].title;var i=1;return t.items.map(function(t){return i+++". "+t.title}).join("<br />")}},$vue=new Vue({el:"#main",data:data,methods:methods,created:function(){this.apiList(1)}});