var $url="/wx/send",$urlUpload="/wx/send/actions/upload",$urlPreview="/wx/send/actions/preview",data=utils.init({siteId:utils.getQueryInt("siteId"),messageId:utils.getQueryInt("messageId"),previewDialog:!1,previewForm:{wxNames:null},success:!1,errorMessage:null,tags:null,message:null,image:null,audio:null,video:null,form:{siteId:utils.getQueryInt("siteId"),materialType:"Message",materialId:0,text:null,isToAll:!0,tagId:0,isTiming:!1,isToday:!0,hour:0,minute:0},hours:[],minutes:[],editEditor:null,sended:!1}),methods={runLayerMessage:function(i){this.form.materialId=i.id,this.message=i},runLayerImage:function(i){this.form.materialId=i.id,this.image=i},runLayerAudio:function(i){this.form.materialId=i.id,this.audio=i},runLayerVideo:function(i){this.form.materialId=i.id,this.video=i},apiGet:function(){var i=this;utils.loading(this,!0),$api.get($url,{params:{siteId:this.siteId,messageId:this.messageId}}).then(function(t){var e=t.data;i.success=e.success,i.errorMessage=e.errorMessage,i.tags=e.tags,i.message=e.message,i.form.materialId=i.messageId}).catch(function(i){utils.error(i)}).then(function(){utils.loading(i,!1)})},apiSubmit:function(){var i=this;utils.loading(this,!0),$api.post($url,this.form).then(function(t){t.data;i.sended=!0}).catch(function(i){utils.error(i)}).then(function(){utils.loading(i,!1)})},apiPreview:function(){var i=this;utils.loading(this,!0),$api.post($urlPreview,{siteId:this.siteId,materialType:this.form.materialType,materialId:this.form.materialId,text:this.form.text,WxNames:this.previewForm.wxNames}).then(function(t){t.data;i.previewDialog=!1,utils.success("预览图文消息已发送至微信，请进入微信查看！")}).catch(function(i){utils.error(i)}).then(function(){utils.loading(i,!1)})},loadEditor:function(){var i=this,t=window.wangEditor;this.editEditor=new t("#text1","#text2"),this.editEditor.customConfig.menus=["head","bold","fontSize","fontName","italic","underline","strikeThrough","foreColor","backColor","link","list","justify","quote","table","undo","redo"],this.editEditor.customConfig.onchange=function(t){i.form.text=t},this.editEditor.create(),this.editEditor.txt.html(this.form.text)},btnTabClick:function(i){var t=this;this.form.materialType=i.name,"Text"===this.form.materialType&&setTimeout(function(){t.loadEditor()},100)},btnSelectClick:function(){utils.openLayer({title:"选择素材",url:utils.getWxUrl("layer"+this.form.materialType,{siteId:this.siteId})})},loadTiming:function(){var i=new Date,t=i.getHours(),e=i.getMinutes()+5;this.form.isToday&&(this.form.hour<t&&(this.form.hour=t),this.form.hour===t&&this.form.minute<e&&(this.form.minute=e)),this.hours=[],this.minutes=[];for(var s=0;s<24;s++)this.form.isToday&&s<t||this.hours.push({value:s,label:utils.pad(s)});for(s=0;s<60;s++)this.form.isToday&&this.form.hour===t&&s<e||this.minutes.push({value:s,label:utils.pad(s)})},isSubmit:function(){return"Text"===this.form.materialType?this.form.text&&this.form.text.length>0:this.form.materialId>0},btnPreviewClick:function(){this.isSubmit()?this.previewDialog=!0:utils.error("请选择或输入需要发送的消息!")},btnSubmitClick:function(){if(this.isSubmit()){var i=this;this.$refs.form.validate(function(t){t&&i.apiSubmit()})}else utils.error("请选择或输入需要发送的消息!")},btnPreviewSubmitClick:function(){var i=this;this.$refs.previewForm.validate(function(t){t&&i.apiPreview()})},btnRemoveClick:function(){this.form.materialId=0},getUploadUrl:function(){return $apiUrl+$urlUpload+"?siteId="+this.siteId+"&materialType="+this.form.materialType},uploadProgress:function(){utils.loading(this,!0)},uploadSuccess:function(i){"Image"===this.form.materialType?(this.form.materialId=i.image.id,this.image=i.image):"Audio"===this.form.materialType?(this.form.materialId=i.audio.id,this.audio=i.audio):"Video"===this.form.materialType&&(this.form.materialId=i.video.id,this.video=i.video),utils.loading(this,!1)},uploadError:function(i){utils.loading(this,!1);var t=JSON.parse(i.message);utils.error(t.message)}},$vue=new Vue({el:"#main",data:data,computed:{wxNamesCount:function(i,t){return this.previewForm.wxNames?this.previewForm.wxNames.split("\n").length:1}},methods:methods,created:function(){this.apiGet()}});