coupon.js
3.11 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* 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'),
tip = require('../plugin/tip');
var bannerSwiper;
// 获取url中的参数
function getUrlParam(name) {
// 构造一个含有目标参数的正则表达式对象
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
// 匹配目标参数
var r = window.location.search.substr(1).match(reg);
// 返回参数值
if (r != null) {
return r[2];
}
return null;
}
$receive.on('click', function() {
var $curDom = $(this),
req = '';
if (getUrlParam('app_version')) {
req += '&app_version=' + getUrlParam('app_version');
}
if (getUrlParam('uid')) {
req += '&uid=' + getUrlParam('uid');
}
$.ajax({
url: '//m.yohobuy.com/coupon/receiveCoupon?code=' + getUrlParam('code') + req,
data: {
couponID: $curDom.parents('.coupon-floor').attr('coupon-id')
},
dataType: 'json',
success: function(data) {
var msg = data.msg,
status = data.status,
newUrl = data.url + '?code=' + getUrlParam('code');
if (data.isApp === true) {
newUrl = data.url;
}
if (data.noLogin === true) {
if ($('#intimacy-link').length <= 0) {
$('body').append('<a href=\'' + newUrl + '\' style="display:none;" id="intimacy-link">' +
'<span class="intimacy-link"></span></a>');
}
$('.intimacy-link').click();
} 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();
}
}
},
error: function() {
tip.show('网络异常!');
}
});
});
$('.coupon-floor a, .banner-top a').on('click', function() {
if ($(this).attr('href').length <= 0 || $(this).attr('href') === '#') {
return false;
}
});
if ($('.banner-swiper').find('li').length > 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'
});
}
$('.coupon-message-op-rel').on('click', function() {
location.reload();
});
if ($('#noData').length > 0) {
if (location.href.indexOf('?openby:yohobuy=') <= 0) {
tip.show('网络异常!');
}
}
$mask.on('click', function() {
$mask.hide();
$message.hide();
});