var vmfooter = new Vue({ el:'#yy', created: function () { this.initPageElem() }, data:{ contactName:'', contactTel:'', contactEmail:'', message:'', soluList:[], prodList:[] }, methods: { contact: function () { var name= this.contactName; var telpone=this.contactTel; var contactEmail=this.contactEmail; var message=this.message; // console.info(name + ", "+telpone); if(!name){ alert("请输入姓名"); return false; } else if((telpone==null||telpone=="")&&(contactEmail==null||contactEmail=="")){ alert("手机与邮箱必须填一个,请输入"); return false; }else{ if(telpone){ if(!(/^1(3|4|5|7|8)\d{9}$/.test(telpone))){ alert("手机号码格式不正确,请重填"); return false; } } if(contactEmail){ if(!(/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(contactEmail))){ alert("邮箱格式不正确,请重填"); return false; } } $.ajax({ type: "post", dataType: "json", url: "/app/contact/save", data:JSON.stringify({"contactName":name,"contactTel":telpone,"contactEmail":contactEmail,"message":message}), contentType: "application/json;charset=utf-8", success: function (res) { if(res.code==200){ alert('提交成功'); vmfooter.contactName = ''; vmfooter.contactTel = ''; vmfooter.contactEmail=''; vmfooter.message = ''; }else{ alert('内部出错,请联系管理员'); } } }); } }, add: function () { vmfooter.title="新增"; vmfooter.showList = false; vmfooter.contact = {isNewRecord:true}; }, initPageElem: function(){ this.initProdList(); this.initSoluList(); }, initProdList: function(){ $.ajax({ type: "get", dataType: "json", url: "/app/product/getAllProducts", success: function (res) { if(res.code==200){ vmfooter.prodList = res.productList; }else{ alert('内部出错,请联系管理员'); } } }); }, initSoluList: function(){ $.ajax({ type: "get", dataType: "json", url: "/app/solution/getAllSolutions", success: function (res) { if(res.code==200){ vmfooter.soluList = res.solutionList; }else{ alert('内部出错,请联系管理员'); } } }); }, clickMe: function(type,index){ if(type == 'prod'){ sessionStorage.setItem("prodInd",index); }else{ sessionStorage.setItem("soluInd",index); } } } }); //验证手机号 function checkPhone(){ var phone = document.getElementById('phone').value; if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){ alert("手机号码有误,请重填"); return false; } }