var c = new Com(); //表单弹窗模块交互 var showModel = (function(form_data){ //不带表面积弹框提交线索后的信息完善弹框 function noAreaUpdateInfoFn(form_data,customer_cnum){ $(".no_area_update_model").addClass("show"); $(".no_area_update_model .receive_perfect_con").addClass("show"); $(".no_area_update_model_btn").unbind("click").on("click",function(){ form_data.like_style = $(".no_area_update_model .receive_style").val() === "请选择您喜欢的别墅风格" ? "" : $(".no_area_update_model .receive_style").val(); form_data.from = $(".no_area_update_model .receive_floor") .val() .trim(); ClueTemplate.prototype.updateClue(form_data,customer_cnum).then((r)=>{ if(r){ $(".no_area_update_model .receive_perfect_con").removeClass("show"); $(".no_area_update_model .receive_wx_con").addClass("show"); }else{ $(".no_area_receive_modal_cover").removeClass("show"); $(".no_area_perfect_con").removeClass("show"); console.log("修改失败") } }); }); $(".receive_wx_close").click(function(){ $(".no_area_update_model").removeClass("show"); $(".no_area_update_model .receive_wx_con").removeClass("show"); }); $(".receive_perfect_close").click(function(){ $(".no_area_update_model").removeClass("show"); $(".no_area_update_model .receive_perfect_con").removeClass("show"); }); }; //带面积的弹窗 var areaModel = function (form_data,customer_cnum){ $(".area_modal_cover").css("display", "block"); $(".area-con").css("display", "block"); $(".area-con-submit").unbind("click").on("click",function(){ var like_style = $(".form-style").val() === "请选择您喜欢的别墅风格" ? "" : $(".form-style").val(); var from = $(".form-floor").val().trim(); form_data.like_style = like_style; form_data.from = from; ClueTemplate.prototype.updateClue(form_data,customer_cnum); $(".area-con").css("display", "none"); $(".wx-con").css("display", "block"); }) } //设计师预约弹窗 var designerNoAreaMOdel = function(form_data,customer_cnum){ $(".reservation_modal_cover").removeClass("show"); $(".reservation_area-con").removeClass("show"); noAreaUpdateInfoFn(form_data,customer_cnum); } //不带表面积弹框提交线索后的信息完善弹框 var noAreaUpdateModel = function(form_data,customer_cnum){ noAreaUpdateInfoFn(form_data,customer_cnum); } //不带面积弹窗 var NoAreaModel = function(form_data,customer_cnum){ $(".no_area_receive_modal_cover").removeClass("show"); $(".no_area_receive_area_con").removeClass("show"); // $(".no_area_perfect_con").addClass("show"); $(".close").click(function(){ $(".no_data_receive_modal_cover").removeClass("show") $(".no_area_receive_area_con").removeClass("show"); }); $(".receive_perfect_close").click(function(){ $(".no_area_perfect_con").removeClass("show"); $(".no_area_receive_modal_cover").removeClass("show"); }); noAreaUpdateInfoFn(form_data,customer_cnum); } //限时领取设计院弹窗 var receiveNoAreaModel = function(form_data,customer_cnum){ $(".receive_perfect_con").css("display", "block"); $(".receive_area_con").css("display", "none"); $(".receive_perfect_btn").unbind("click").on("click", function () { form_data.like_style = $(".receive_style").val() === "请选择您喜欢的别墅风格" ? "" : $(".receive_style").val(); form_data.from = $(".receive_floor") .val() .trim(); ClueTemplate.prototype.updateClue(form_data,customer_cnum).then((r)=>{ if(r){ $(".receive_perfect_con").css("display", "none"); $(".receive_wx_con").css("display", "block"); }else{ $(".no_area_receive_modal_cover").removeClass("show"); $(".no_area_perfect_con").removeClass("show"); console.log("修改失败") } }); }); } var other =function(){ ClueTemplate.prototype.showSuccessModel(); } return { areaModel:areaModel, NoAreaModel:NoAreaModel, receiveNoAreaModel:receiveNoAreaModel, designerNoAreaMOdel:designerNoAreaMOdel, noAreaUpdateModel:noAreaUpdateModel, other:other } })() //提交表单模板 var ClueTemplate = function(data){ this.customer_cnum = ""; this.form_data = data.form_data; this.model_type = data.model_type; this.over_bool = true; if (c.getCookie("spread") && c.getCookie("spread_token")) { this.form_data.code = c.getCookie("spread"); this.form_data.code_token = c.getCookie("spread_token"); } this.form_data.first_page = c.getCookie("first_page"); this.form_data.current_page = c.getCookie("current_page"); }; //装修计算器 报价的接口 ClueTemplate.prototype.checkLimite = function(){ var ct_this = this; var form_data = this.form_data; $.ajaxSettings.async = false; var _url = '/index.php?g=Addons&m=GuestBook&a=add&typeId=1'; if(form_data['name']) _url = _url + '&name=' + form_data['name']; if(form_data['phone']) _url = _url + '&shouji=' + form_data['phone']; var _introduce = ''; if(form_data['like_style']) _introduce = '类型:' + form_data['like_style']; if(form_data['city']) _introduce = '城市:' + form_data['city']; if(_introduce) _url = _url + '&introduce=' + _introduce; form_data['shouji'] = form_data['phone']; form_data['typeId'] = 1; form_data['introduce'] = _introduce; $.ajax({ type:"POST", url:_url, data:form_data, success:function(msg){ if(msg){ var data = JSON.parse(msg); if(data.status == 1){ ClueTemplate.prototype.overLimit(); ct_this.over_bool = false; }else{ console.log("提交失败") } } // console.log(msg) // return } }); }; ClueTemplate.prototype.addClue = function(){ if(this.over_bool){ var ct_this = this; var form_data = this.form_data; $.ajaxSettings.async = false; $.get( "/api?url=" + encodeURIComponent("mk/anon/enroll") + "&data=" + encodeURIComponent(JSON.stringify(form_data)), function (result) { ct_this.customer_cnum = result.res.customer_cnum || ""; if(result.res.customer_cnum){ ClueTemplate.prototype.clearInput(); showModel[ct_this.model_type](form_data,ct_this.customer_cnum); }else{ console.log("提交失败") } } ); } }; //喜欢哪个样式的风格 ClueTemplate.prototype.updateClue = function(form_data,customer_cnum){ var ct_this = this; return new Promise((resolve,reject)=>{ $.ajaxSettings.async = false; $.get( "/api?url=" + encodeURIComponent("mk/anon/update_customer") + "&data=" + encodeURIComponent( JSON.stringify({ cnum:customer_cnum, form_data: form_data }) ), function (result) { resolve(result.res.res_customer.cnum ||""); } ); }) }; ClueTemplate.prototype.overLimit = function(){ $(".over_model_box").removeClass("hide") $(".ok_btn,.close").click(function(){ $(".over_model_box").addClass("hide"); c.defaultPlaceholder(); }); } ClueTemplate.prototype.clearInput = function(){ $("input").val(""); } ClueTemplate.prototype.showSuccessModel = function(){ $(".submit_model_box").removeClass("hide") $(".ok_btn,.close").click(function(){ $(".submit_model_box").addClass("hide"); }); c.defaultPlaceholder(); } ClueTemplate.prototype.Init = function(){ this.checkLimite(); this.addClue(); };