$(function () { var prefix = ".demonstrate-page-box "; $(prefix + ".demonstrateName input").on("input", function () { $(prefix + ".demonstrateName").removeClass("error"); }); $(prefix + ".demonstrateCorpName input").on("input", function () { $(prefix + ".demonstrateCorpName").removeClass("error"); }); $(prefix + ".demonstratePhone input").on("input", function () { $(prefix + ".demonstratePhone").removeClass("error"); }); function checkName() { const userName = $(prefix + ".demonstrateName input").val(); if (!userName) { $(prefix + ".demonstrateName").addClass("error"); $(prefix + ".demonstrateName .demonstrate-item-error").html("请输入姓名"); return false; } return userName; } function checkCorp() { const corpName = $(prefix + ".demonstrateCorpName input").val(); if (!corpName) { $(prefix + ".demonstrateCorpName").addClass("error"); $(prefix + ".demonstrateCorpName .demonstrate-item-error").html( "请输入企业全称" ); return false; } return corpName; } function checkPhone() { const mobileNumber = $(prefix + ".demonstratePhone input").val(); if (!mobileNumber) { $(prefix + ".demonstratePhone").addClass("error"); $(prefix + ".demonstratePhone .demonstrate-item-error").html( "请输入手机号" ); return false; } else if (!/^1[23456789]\d{9}$/.test(mobileNumber)) { $(prefix + ".demonstratePhone").addClass("error"); $(prefix + ".demonstratePhone .demonstrate-item-error").html( "请输入正确的手机号" ); return false; } return mobileNumber; } $(prefix + ".demonstrateName input").blur(checkName); $(prefix + ".demonstrateCorpName input").blur(checkCorp); $(prefix + ".demonstratePhone input").blur(checkPhone); $(prefix + ".demonstrate-product-box .product-item").click(function (e) { $(prefix + ".demonstrate-product-box .product-item").removeClass("active"); e.currentTarget.className += " active"; }); $(prefix + ".demonstrateModalBtn").click(function () { const userName = checkName(); const corpName = checkCorp(); const mobileNumber = checkPhone(); let errorFlag = [userName, corpName, mobileNumber].some((v) => v === false); // 没有问题,通过 if (!errorFlag) { var leads = $( prefix + ".demonstrate-product-box .product-item.active" ).html(); var params = { userName, mobileNumber, corpName, type: 0, flowCrm: true, originType: "官网报名" + leads + "_ddw", }; $.ajax({ type: "POST", url: window.reqHost + "/home/open/saveVipInfo", data: JSON.stringify(params), contentType: "application/json", success: function () { try { document.documentElement.scrollTop = 0; } catch (error) {} $(prefix + ".demonstrate-page-right").css("display", "none"); $(prefix + ".demonstrate-page-right-ok").css("display", "block"); }, }); } }); });