var $url="/wx/replyAdd",data=utils.init({siteId:utils.getQueryInt("siteId"),ruleId:utils.getQueryInt("ruleId"),tabName:utils.getQueryString("tabName"),success:!1,errorMessage:null,form:{ruleName:null,random:!0,messages:null},keywords:[],messages:[]}),methods={runLayerMessage:function(e){this.messages.push({materialType:"Message",materialId:e.id,items:e.items,lastModifiedDate:e.lastModifiedDate}),this.form.messages=!0},runLayerText:function(e,s){s?this.messages[parseInt(s)].text=e:this.messages.push({materialType:"Text",text:e}),this.form.messages=!0},runLayerImage:function(e){this.messages.push({materialType:"Image",materialId:e.id,image:e}),this.form.messages=!0},runLayerAudio:function(e){this.messages.push({materialType:"Audio",materialId:e.id,audio:e}),this.form.messages=!0},runLayerVideo:function(e){this.messages.push({materialType:"Video",materialId:e.id,video:e}),this.form.messages=!0},apiGet:function(){var e=this;utils.loading(this,!0),$api.get($url,{params:{siteId:this.siteId,ruleId:this.ruleId}}).then(function(s){var t=s.data;e.success=t.success,e.errorMessage=t.errorMessage,e.form.ruleName=t.ruleName,e.form.random=t.random,e.keywords=t.keywords||[{exact:!1,text:null}],e.messages=t.messages||[]}).catch(function(e){utils.error(e)}).then(function(){utils.loading(e,!1)})},apiSubmit:function(){var e=this;utils.loading(this,!0),$api.post($url,{siteId:this.siteId,ruleId:this.ruleId,ruleName:this.form.ruleName,random:this.form.random,keywords:this.keywords,messages:this.messages}).then(function(s){s.data;var t=utils.getTabVue(e.tabName);t&&t.apiGet(1),utils.success("关键词回复保存成功！"),utils.removeTab()}).catch(function(e){utils.error(e)}).then(function(){utils.loading(e,!1)})},btnSelectClick:function(e,s){utils.openLayer({title:"回复消息",url:utils.getWxUrl("layer"+e,{siteId:this.siteId,index:s||""})})},btnAppendClick:function(){this.keywords.push({id:0,exact:!1,text:null})},btnRemoveKeywordClick:function(e){this.keywords.splice(e,1)},btnRemoveMessageClick:function(e){this.messages.splice(e,1),this.form.messages=0!==this.messages.length||null},btnSubmitClick:function(){var e=this,s=[this.$refs.rule1,this.$refs.rule2,this.$refs.rule3];this.keywords.forEach(function(t,i){s.push(e.$refs.keywords[i])});var t=!0;s.forEach(function(e){e.validate(function(e){t=t&&e})}),t&&this.apiSubmit()},btnCloseClick:function(){utils.removeTab()}},$vue=new Vue({el:"#main",data:data,methods:methods,created:function(){this.apiGet()}});