shop_coupon.js
1.69 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
var $ = require('jquery'),
IScroll = require('iscroll/iscroll-probe'),
Swiper = require('yoho.iswiper'),
tip = require('../plugin/tip');
var isCouponClick = true,
appVersion = $('input[name="app_version"]').val();
$(".coupon-content .receive-btn").on('touchstart', function(e) {
var that = this,
code = $(this).closest('.swiper-slide').data('id') || '';
if (isCouponClick === false) {
return false;
}
isCouponClick = false;
$.ajax({
method: 'POST',
// url: '/product/index/userCoupon',
url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
data: {
couponID: code,
app_version: appVersion
},
xhrFields: {
withCredentials: true
},
success: function(data) {
isCouponClick = true;
if (data.code === 200) {
tip.show('领取成功');
$(that).addClass('padding-20').html('已领取');
$(that).unbind('touchstart');//移除绑定事件
return true;
} else if (data.code === 4401) {
$('body').append('<a href=\'' + data.url + '\'><span id="jump-login"><span></a>');
$('#jump-login').click();
} else {
tip.show(data.message);
}
},
error: function() {
tip.show('网络断开连接了~');
isCouponClick = true;
}
});
});
$(function() {
new Swiper('.coupon-content', {
slideElement: '.coupon-small',
slidesPerView: 'auto',
watchSlidesVisibility: true
})
})