gswz/SFHY/static/js/agent.js

362 lines
10 KiB
JavaScript
Raw Normal View History

2024-02-28 14:35:44 +08:00
// 节流函数
function throttle(handle, wait) {
let lastTime = 0;
return function (e) {
let nowTime = new Date().getTime()
if (nowTime - lastTime > wait) {
handle();
lastTime = nowTime;
}
}
}
/* ................... 防抖函数 ................... */
function debounce(func, delay) {
let timeout
return function () {
clearTimeout(timeout) // 如果持续触发,那么就清除定时器,定时器的回调就不会执行。
timeout = setTimeout(() => {
func.apply(this, arguments)
}, delay)
}
}
/* .................. 获取链接参数 .................. */
function getUrlData(name) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == name) {
return decodeURI(pair[1]);
}
}
return (false);
}
if (getUrlData("btn") && getUrlData("btn") === "index") {
sessionStorage.setItem("agent", "index");
}
var channel = "PC端";
if (window.navigator && (/Mobile|Android|webOS|iPhone|iPad|Phone/i.test(navigator.userAgent))) {
channel = "移动端";
}
// 按钮位置和当前链接
var btnPosition = "代理页面按钮";
var curLink = sessionStorage.getItem("currentLink") || tool.getCookie("currentLink");
if (curLink == "") {
curLink = link;
}
var vm = new Vue({
el: "#app",
data: {
tel: '',
i: 2,
aboutFix: "",
activeIndex: 2,
solveSwiper: "",
teleManaI: 2,
sscManaI: 1,
codeText: '获取验证码',
count: 30,
timer: null,
tel: "",
cityValue: "",
city: "",
com: "",
typec: "代理页面",
telCodeStatus: false,
codeStatus: false,
telTips: "",
codeTips: "",
comTips: "",
cityTips: "",
buttonAble: false,
code: "",
state: "0",
right: "",
imgScrollFlag: null,
},
mounted() {
if (screen.availWidth !== 1280 && window.devicePixelRatio !== 1.5) {
new WOW().init();
};
this.allSwiper()
window.addEventListener("scroll", this.aboutFixClass)
// this.imgScroll()
},
mixins: [mixins],
methods: {
aboutFixClass() {
if (
!!document.documentElement.scrollTop &&
document.documentElement.scrollTop > 200 || document.body.scrollTop > 200
) {
this.headerCss = false
this.aboutFix = "about-fix";
} else {
this.aboutFix = "";
}
},
imgScroll() {
let _this = this;
var dome = document.querySelector(".agent-industry-box");
var dome1 = document.querySelector(".agent-industry-box1");
var dome2 = document.querySelector(".agent-industry-box2");
var speed = 10;//设置向上轮动的速度
dome2.innerHTML = dome1.innerHTML;//复制节点
function moveTop() {
if (dome2.offsetWidth - dome.scrollLeft <= 0) {
dome.scrollLeft -= dome1.offsetWidth
} else {
dome.scrollLeft++;
}
}
this.imgScrollFlag = setInterval(moveTop, speed);
dome.onmouseover = function () {
clearInterval(_this.imgScrollFlag);
}
dome.onmouseout = function () {
_this.imgScrollFlag = setInterval(moveTop, speed);
}
},
solveTab(i) {
this.i = i;
var j = i - 1;
this.solveSwiper.slideTo(j, 1000, false);
},
teleMana(i) {
this.teleManaI = i;
},
sscTab(i) {
this.sscManaI = i;
},
allSwiper() {//swiper
if (screen.width <= 768) { //名企证言轮播
var comSwiper = new Swiper('.com-swiper', {
initialSlide: 1,//初始化时slide的索引
slidesPerView: 'auto',
slideToClickedSlide: true,
centeredSlides: true,
loop: true, // 循环模式选项
autoplay: {
delay: 3000,
disableOnInteraction: false
},
pagination: {
el: '.swiper-pagination',
clickable: true,
}
})
} else {
new Swiper('.com-swiper', {
// initialSlide: 1,//初始化时slide的索引
slidesPerView: 3,
// spaceBetween: 30,
slideToClickedSlide: true,
centeredSlides: true,
loop: true, // 循环模式选项
autoplay: {
delay: 3000,
disableOnInteraction: false
},
pagination: {
el: '.swiper-pagination',
clickable: true,
}
})
}
},
verifyTel: debounce(function () {
var RegExp = /^1[3-9][0-9]{9}$/;
if (vm.tel.trim() == "") {
vm.telTips = "请输入您的手机号";
vm.telCodeStatus = false;
} else if (!RegExp.test(vm.tel.trim())) {
vm.telTips = "请输入正确的手机号码";
vm.telCodeStatus = false;
} else {
vm.telTips = "";
vm.telCodeStatus = true;
}
}, 500),
getCode: throttle(function () {
btnPosition = "代理页面立即加入按钮"
var RegExp = /^1[3-9][0-9]{9}$/;
if (vm.tel.trim() == "") {
Swal.fire({
title: '请输入您的手机号',
showConfirmButton: false,
timer: 1500
})
return false
} else if (!RegExp.test(vm.tel.trim())) {
Swal.fire({
title: '请输入正确的手机号码',
showConfirmButton: false,
timer: 1500
})
} else {
vm.tips = "";// 验证通过
vm.timer = setInterval(() => {
if (vm.count > 0 && vm.count <= 30) {
vm.buttonAble = true
vm.count--
vm.codeText = vm.count + "秒后重新获取"
} else {
vm.buttonAble = false;
vm.codeText = "获取验证码"
clearInterval(vm.timer);
vm.timer = null;
vm.count = 30;
}
}, 1000);
$.ajax({
url: "/apply/apply-code.php",
type: "post",
data: {
tel: vm.tel,
btn: btnPosition,
curLink: curLink,
protype: vm.typec,
sourceLink: sourceUrl,
website_keywords: website_keywords,// 关键词
channel: channel
},
success: function (res) {
if (res == "toomuch") {
alert("请匆频繁提交!感谢您的理解和合作,可通过在线客服或电话与我们取得联系。")
return
}
console.log("第一步推送成功!");
}
});
vm.actionId = vm.tel + "-" + Math.floor(Math.random() * 1000000);
$.ajax({
url: "/api/sendMsg.php",
type: 'POST',
data: {
telNum: vm.tel,
actionId: vm.actionId,
info: 'holly.400',
time: new Date().getTime(),
actionName: "呼叫中心站试用申请",
verifyCode: ""
},
success: function (res) {
if (res.state == "sent") {//发送验证码成功并且成功写入数据库返回sent
return (vm.codeTips = "验证码已发送,请注意查收");
} else {//其他不成功的情况
return (vm.codeTips = "发送失败,请稍后再试");
}
}
});
}
}, 1500),
verifyCode: debounce(function (event) {
if (vm.tel == "") {
vm.codeStatus = false;
return (vm.telTips = "请输入手机号码");
} else if (event.target.value == "") {
vm.codeStatus = false;
return (vm.codeTips = "请输入验证码");
} else if (event.target.value.length != 4) {
vm.codeStatus = false;
return (vm.codeTips = "请输入正确的验证码");
} else {
vm.codeTips = ""
}
$.ajax({
url: "/api/verifyMsg.php",
type: 'post',
data: {
telNum: vm.tel,
actionId: vm.actionId,
actionName: "呼叫中心站试用申请",
code: vm.code
},
success: function (res) {
if (res.state == "vSucceed") {
$("#tel").attr({ readonly: "readonly" });
$("#getCode").attr({ disabled: "true" });
vm.$data.right = true;
vm.$data.codeTips = "验证码验证成功";
setTimeout(() => {
vm.$data.codeTips = "";
vm.codeStatus = true;
}, 500);
} else if (res.state == "vFail") {
event.target.focus();
vm.$data.right = false;
vm.codeStatus = false;
return (vm.$data.codeTips = "验证码错误,请重试");
}
}
});
}, 1500),
verifyCom: debounce(function () {
if (vm.com.trim() == "") {
vm.comTips = "请输入您的公司名称";
} else { vm.comTips = ""; }
}, 1500),
verify: function () {
btnPosition = "代理页面立即加入按钮"
var mobilePattern = /^1[3-9][0-9]{9}$/;
if (vm.tel.trim() == "") {
Swal.fire({
title: '请输入您的手机号',
showConfirmButton: false,
timer: 1500
})
return false;
} else if (!mobilePattern.test(vm.tel.trim())) {
Swal.fire({
title: '请输入正确的手机号码',
showConfirmButton: false,
timer: 1500
})
return false;
} else if (vm.code.trim() == "") {
Swal.fire({
title: '请输入验证码',
showConfirmButton: false,
timer: 1500
})
return false;
} else if (vm.code.trim().length != 4) {
Swal.fire({
title: '请输入正确的验证码',
showConfirmButton: false,
timer: 1500
})
return false;
} else if (!vm.right) {
Swal.fire({
title: '请输入正确的验证码',
showConfirmButton: false,
timer: 1500
})
return false;
} else if (vm.com.trim() == "") {
Swal.fire({
title: '请输入公司名',
showConfirmButton: false,
timer: 1500
})
return false;
}
else {
vm.tips = "";
tool.setCookie("applyTel", vm.tel, 1);
tool.setCookie("applyCom", vm.com, 1);
tool.setCookie("applyCity", vm.city, 1);
if (channel === "移动端") {
document.agent_mobile.submit();
} else {
document.agent.submit();
}
}
}
},
beforeDestroy() {
clearInterval(_this.imgScrollFlag);
},
});