shop-coupon.js
1.66 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
var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper'),
tip = require('../../plugin/tip');
var appVersion = $('input[name="app_version"]').val(),
uid = $('input[name="uid"]').val();
$('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function() {
var that = this,
code = $(this).data('id') || '';
if (that.isCouponClick === false) {
return false;
}
that.isCouponClick = false;
$.ajax({
method: 'GET',
url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
data: {
couponID: code,
app_version: appVersion,
uid: uid
},
xhrFields: {
withCredentials: true
},
success: function(data) {
that.isCouponClick = true;
if (data.code === 200) {
tip.show('领取成功');
$(that).find('.receive-btn').html('已领取');
return true;
} else if (data.code === 4401) {
$('#shop-login').remove();
$('body').append('<a href=\'' + data.url + '\'><span id="shop-login"><span></a>');
$('#shop-login').click();
} else if (data.code === 401) {
tip.show('已领取过');
} else {
tip.show(data.message);
}
},
error: function() {
tip.show('网络断开连接了~');
that.isCouponClick = true;
}
});
});
$(function() {
new Swiper('.coupon-content', {
slideElement: '.coupon-small',
slidesPerView: 'auto',
watchSlidesVisibility: true
});
});