coupon.js
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Created by Administrator on 2016/4/13.
*/
var $ = require('jquery'),
Swiper = require('yoho.iswiper'),
$receive = $('.main-right-receive'),
$mask = $('.floor-mask'),
$message = $('.floor-message'),
$tooltip = $('.floor-tooltip');
var bannerSwiper;
$receive.on('click', function() {
var $curDom = $(this);
$.ajax({
url: '/coupon/receiveCoupon',
dataType: 'json',
success: function(data) {
var msg = data.msg,
status = data.status;
if (data.noLogin === true) {
location.href = data.url + '?code=' + getUrlParam('code');
} else {
if (status) {
$curDom.hide();
$curDom.next().show();
$tooltip.show();
setTimeout(function() {
$tooltip.hide();
}, 3000);
} else {
$message.find('.coupon-message-content').text(msg);
$mask.show();
$message.show();
}
}
}
});
});
//获取url中的参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]); return null; //返回参数值
}
$('.coupon-floor a').on('click', function() {
if ($(this).attr('href').length <= 0) {
return false;
}
});
if ($('.banner-swiper').find('li').size() > 1) {
bannerSwiper = new Swiper('.banner-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.banner-top .pagination-inner'
});
}