领取优惠券前端功能实现部分源码

<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<meta content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no” name=”viewport”>
<meta content=”telephone=no” name=”format-detection” />
<title></title>
<meta id=”description” name=”description” content=”免费领取10元全场通用优惠券” />
<link rel=”stylesheet” type=”text/css” href=”../../css/common2.css” />
<link rel=”stylesheet” href=”../../css/layer.css” />

<style>
html{
height: 100%;
}
body{
width: 100vw;
height: 100%;
background: #f6f9ff url(../../img/activity/winter_bg.png) no-repeat center;
background-size: 100%;
}
.content {
width: 100%;
height: 100%;
position: relative;
z-index: 1;
}
.titBox{
width: 82%;
height: 4.5rem;
margin: 0 auto;
background: url(../../img/activity/winter_tit.png) no-repeat center;
background-size: contain;
}
.concentBox{
width: 90%;
height: 1.5rem;
font-size: 0.45rem;
text-align: center;
color: rgb( 41, 57, 80 );
margin: 0 auto;
}
.concentBox .page_t{
width: 90%;
display: inline-block;
}

.concentBox p{
font-size: 0.3rem;
color: rgb( 76, 89, 122 );
font-family: “PingFangSC”;
}
.winterForm{
width: 80%;
height: 1.5rem;
margin: 0 auto;
}
input{
border: none;
}
.winterForm .winterTel{
width: 100%;
height: 0.7rem;
float: left;
border-radius: 6px;
text-indent: 20px;
font-size: 0.28rem;
background: url(../../img/activity/input_bg.png) repeat;
}
.identyfyVal{
width: 57%;
height: 0.7rem;
float: left;
border-radius: 6px;
text-indent: 20px;
font-size: 0.28rem;
margin-top: 0.2rem;
background: url(../../img/activity/input_bg.png) repeat;
}
.code1{
width: 40%;
height: 0.7rem;
line-height: 0.7rem;
float: right;
text-align: center;
border-radius: 6px;
font-size: 0.3rem;
margin-top: 0.2rem;
background: url(../../img/activity/yzmbtn.png) repeat;
color: rgb( 255, 255, 255 );
}
.demand{
width: 40%;
height: 0.9rem;line-height: 0.9rem;text-align: center;font-size: 0.35rem;
color: #000000;
margin: 30px auto;border-radius: 0.45rem;display: none;
background: -webkit-gradient(linear,0% 0%, 59% 0%, from(#F9DB74), to(#F8AA1B));
}
.getCouponIcon{
width: 40%;
height: 0.9rem;line-height: 0.9rem;text-align: center;font-size: 0.35rem;
color: #000000;
margin: 30px auto;border-radius: 0.45rem;
background: -webkit-gradient(linear,0% 0%, 59% 0%, from(#F9DB74), to(#F8AA1B));

}
.winterTx{
width: 100%;
padding-bottom: 1.5rem;
}
.error{
width: 100%;
height: 0.5rem;
margin-top: 0.2rem;
float: left;
font-size: 0.3rem;
color: red;
padding-left: 0.1rem;
display: none;
}
/*领取成功*/
.receiveSuccess{
width: 70%;
height: 2rem;
margin: 0 auto;
border-radius: 6px;padding: 0.1rem;
background: url(../../img/activity/input_bg.png) repeat;
}
.receiveSuccess .receiveCode{
text-align: center;
font-size: 0.4rem;
color: #F8AA1B;
width: 2.5rem;
display: block;
margin: 0.1rem auto;font-weight: 600;
}
.receiveSuccess p{
text-align: center;
font-size: 0.3rem;
color: #000000;
}
.downloadBox{
width: 40%;
height: 0.9rem;line-height: 0.9rem;text-align: center;font-size: 0.35rem;
color: #000000;
margin: 20px auto;border-radius: 0.45rem;
background: -webkit-gradient(linear,0% 0%, 59% 0%, from(#F9DB74), to(#F8AA1B));
}
.downLoad {
position: fixed;
width: 6.86rem;
padding: 0 0.32rem;
height: 60px;
left: 50%;
margin-left: -3.75rem;
bottom: 0;
background: #fff;
z-index: 999;
overflow: hidden;
border-bottom: 1px solid rgb(231,231,231);
}
.downLoad img {
float: left;
width: 139px;
height: 44px;
margin-top: 8px;
}
.downLoad .toDownload {
float: right;
width: 86px;
height: 32px;
line-height: 32px;
margin-top: 14px;
font-size: 14px;
color: #fff;
text-align: center;
border-radius: 4px;
background: rgb(15,15,15);
}
</style>
</head>
<body>
<div class=”content”>
<div class=”titBox”></div>
<div class=”concentBox”>
<img class=”page_t” src=”../../img/activity/yh.png”/>
<p>活动时间:2018.11.15-2018.12.15</p>
</div>
<form class=”winterForm” >
<input class=”from” name=”from” type=”hidden”/>
<input class=”crid” name=”crid” type=”hidden”/>
<input class=”winterTel tel phoneVal” type=”text” id=”mobile” name=”mobile” placeholder=”请输入有效手机号” />

<input class=”identyfyVal code” name=”code” type=”text” placeholder=”输入验证码”/>
<input class=”codeId” name=”code_id” type=”hidden”/>
<span class=”code1 getCode” id=”code-btn”>获取验证码</span>

</form>
<div class=”getCouponIcon” >领取优惠券</div>
<div class=”demand” >领取优惠券</div>
<!–领取成功–>
<div class=”receiveSuccess” style=”display: none;”>
<span class=”receiveCode”>领取成功</span>
<p>优惠券已放入<a class=”receivePhone” style=”color: #777879;”>138****000</a>的账号中</p>
<p style=”font-size: 0.25rem;color: #777879;margin-top: 0.2rem;”>可以到APP“我的-我的卡券”中查看</p>
</div>
<!–领取成功end–>
<div class=”downloadBox” style=”display: none;”>下载</div>
<img class=”winterTx” src=”../../img/activity/winter_tx.png”/>
<div class=”downLoad”>
<img src=”../../img/downLoadLogo.png” />
<div class=”toDownload”><a href=””>打开APP</a></div>
</div>
</div>
</body>
<script src=”../../js/layer.js”></script>
<script src=”../../js/jquery.min.js”></script>
<script src=”../../js/common.js?0.0.1″></script>
<script src=”../../js/md5.js”></script>
<script src=”//res.wx.qq.com/open/js/jweixin-1.0.0.js”></script>
<script src=”../../js/winter.js”></script>
<script>
$(function() {
var sFrom = oBath.GetQueryString(“from”);
var downAddress=”
switch(sFrom){

}
$(‘.downloadBox’).on(‘click’, function() {
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == “micromessenger”) {
layer.open({
content: “请在浏览器中打开下载app”,
skin: ‘msg’,
time: 2
});
}
else {
location.href = downAddress;
}
})

})</script>
<script>
var oCoupon={

process(){
var ssid = oBath.GetQueryString(‘ssid’);
if(ssid){
var obj = {
“status”: status,
“ssid”:ssid,
}
var signObj = oBath.Getsign(obj);
var sign = signObj[0];
var nonce = signObj[1];
var time = signObj[2];
$.ajax({
type:”get”,
url: “https://api1.百度.com:9500/user/accountInfo?sign=”+ sign+”&timestamp=”+time+”&nonce=”+nonce,
data:{
“status”:status,
“ssid”:ssid,
},

async:true,
success: function (result) {
if(result.status ==1){
$(‘.demand’).css(“display”,”block”);
$(‘.getCouponIcon’).css(“display”,”none”);
$(‘.winterForm’).css(“display”,”none”);
$(“.demand”).on(“click”,function(){
var sCrid = “124”;
var obj = {
“ssid”:ssid,
“crid”:sCrid,
}

var signObj = oBath.Getsign(obj);
var sign = signObj[0];
var nonce = signObj[1];
var time = signObj[2];
$.ajax({
type:”get”,
url: “https://api1.百度.com:9500/coupon/loginreceive?sign=”+ sign+”&timestamp=”+time+”&nonce=”+nonce,
data:{
“crid”:sCrid,
“ssid”:ssid,
},

async:true,
success: function (data) {
if(result.status ==1){
//var phoneN = phoneNum.substr(0, 3) + ‘****’ + phoneNum.substr(7, 11);//隐藏手机号中间4位
$(‘.winterForm’).css(“display”,”none”);
$(‘.demand’).css(“display”,”none”);
$(‘.downloadBox’).css(“display”,”block”);
$(‘.receiveSuccess’).css(“display”,”block”);
$(“.receivePhone”).text(result.content.mobile);
}
}
});
});

}else{
location.href = “page://action/login”;//跳转APP登录

$(‘.downloadBox’).css(“display”,”none”);
$(‘.demand’).css(“display”,”none”);

}
}
});
}else{
//发送验证码
$(“.getCode”).on(“click”,function(){
var phoneNum=$(“.phoneVal”).val();
var sCrid=”124″;
var type=”1″;
var obj = {
“mobile”: phoneNum,
“type”: type,
“crid”: sCrid,
}
var signObj = oBath.Getsign(obj);
var sign = signObj[0];
var nonce = signObj[1];
var time = signObj[2];
if($(“.getCode”).hasClass(“YzmDisabled”)){
return false;
}
if(!(/^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))\d{8}$/.test(phoneNum))){
layer.open({
content: ‘请输入正确的手机号格式’
,skin: ‘msg’
,time: 2
});
}else{
$(‘.getCode’).addClass(“YzmDisabled”);
$.ajax({
url: “https://api1.百度.com:9500/user/getcode?sign=”+ sign+”&timestamp=”+time+”&nonce=”+nonce,
type: ‘get’,
data: {
“mobile”: phoneNum,
“type”: type,
“crid”: sCrid,
},
success: function(data) {
console.log(data);
if(data.status == ‘1’) {
$(“.codeId”).val(data.content);
layer.open({
content: ‘已发送验证码’
,skin: ‘msg’
,time: 2
});
var num=61;
var timerYzm=window.setInterval(function(){
num–;
$(“.getCode”).text(num+”s重新获取”);
if(num==0){
$(“.getCode”).removeClass(“YzmDisabled”).text(“获取验证码”);
window.clearInterval(timerYzm);
}
},1000);
} else{
layer.open({
content: data.message
,skin: ‘msg’
,time: 2
});
$(“.getCode”).removeClass(“YzmDisabled”).text(“获取验证码”);
}
},
error:function(res){
console.log(res);
}
});
}
})
}
},

submitForm(){

var that=this;
$(“.getCouponIcon”).on(“click”,function(){
var phoneNum=$(“.phoneVal”).val();
var code=$(“.identyfyVal”).val();
var sCodeId=$(“.codeId”).val();
var sFrom=”109″;
var sCrid=”124″;
if(!(/^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))\d{8}$/.test(phoneNum))){
layer.open({content: “请输入正确的手机号格式”,skin: ‘msg’,time: 2 });
$(“.phoneVal”).focus();
return false;
}else if(code.length==0){
layer.open({
content: “验证码不能为空”
,skin: ‘msg’
,time: 2
});
$(“.identyfyVal”).focus();
return false;
}else{

var obj = {
“mobile”: phoneNum,
“code”:code,
“code_id”:sCodeId,
“from”:sFrom,
“crid”:sCrid,
}

var signObj = oBath.Getsign(obj);
var sign = signObj[0];
var nonce = signObj[1];
var time = signObj[2];
//console.log(obj)
// console.log(sign)
$.ajax({
url: “https://api1.百度.com:9500/coupon/quickreceive?sign=”+ sign+”&timestamp=”+time+”&nonce=”+nonce,
type: ‘get’,
data: {
“mobile”: phoneNum,
“code”:code,
“code_id”:sCodeId,
“from”:sFrom,
“crid”:sCrid,
},
success: function(data) {
//console.log(data)
if(data.status == 1) {
$(‘.getCouponIcon ‘).css(“display”,”none”);

$(‘.winterForm’).css(“display”,”none”);
$(‘.demand’).css(“display”,”none”);
$(‘.downloadBox’).css(“display”,”block”);
$(‘.receiveSuccess’).css(“display”,”block”);

var phoneN = phoneNum.substr(0, 3) + ‘****’ + phoneNum.substr(7, 11);
$(“.receivePhone”).text(phoneN);

$(“.getCouponIcon”).addClass(“YzmDisabled”);

} else {
layer.open({
content: data.message
,skin: ‘msg’
,time: 2
});
$(“.getCouponIcon”).removeClass(“layui-btn-disabled”);
}
},
error:function(res){
console.log(res);
}
});
}
return false;
})
},

init(){
this.submitForm();
this.process();
}
}

$(function(){
oCoupon.init();
})

</script>

</html>

原文链接:https://blog.csdn.net/jacksosion/article/details/85773835?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165277499316781685342111%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165277499316781685342111&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-18-85773835-null-null.nonecase&utm_term=%E4%BC%98%E6%83%A0

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
文明发言,共建和谐米科社区
提交
头像

昵称

取消
昵称表情图片

    暂无评论内容