coupon.mobile.js
4.96 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
var $tip, tipItime;
/* 领指定券 */
var activityId = $('#coupon-container').attr('param');
$('.get-coupon').click(function() {
var couponId = $(this).attr('param');
if (!isNaN(activityId) && !isNaN(couponId)) {
getNamedCoupon(activityId, couponId);
}
});
/* 领所有券 */
$('#get-all-coupon').click(function() {
getAllCoupon(activityId);
});
/**
* 微信分享
*/
(function($) {
if (!wx) {
return;
}
var _weChatInterface = 'http://www.yohoshow.com/api/wechat/getSignPackage';
$.getJSON(_weChatInterface + '?pageurl=' +
encodeURIComponent(location.href.split('#')[0]) + '&callback=?', function(json) {
var _appId, _timestamp, _nonceStr, _signature;
if (json !== undefined && json !== '') {
_appId = json.appId.toString();
_timestamp = json.timestamp;
_nonceStr = json.nonceStr.toString();
_signature = json.signature.toString();
wx.config({
debug: false,
appId: _appId,
timestamp: _timestamp,
nonceStr: _nonceStr,
signature: _signature,
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'showMenuItems',
'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
]
});
}
});
wx.ready(function() {
var shareTitle = $('#shareTitle').val();
var shareImg = $('#shareImg').val();
var shareDesc = $('#shareDesc').val();
var shareLink = $('#shareLink').val();
var shareData = {
title: shareTitle,
desc: shareDesc,
imgUrl: shareImg,
link: shareLink
};
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareTimeline(shareData);
wx.onMenuShareQQ(shareData);
wx.onMenuShareWeibo(shareData);
});
}(jQuery));
/**
* 初始化提示框
*/
(function() {
var tipHtml = '<div id="yoho-tip" class="yoho-tip"></div>';
//插入提示HTML
$('#coupon-container').append(tipHtml);
$tip = $('#yoho-tip');
$tip.on('touchend', function() {
$tip.hide();
//清除Timeout
clearTimeout(tipItime);
});
}());
/**
* 显示提示
*/
function showTip(con, dur) {
var content, duration;
if (typeof con === 'undefined') {
return;
}
content = con.toString();
duration = (dur && dur > 0) ? dur : 2000;
$tip.text(content).show();
tipItime = setTimeout(function() {
if ($tip.css('display') === 'block') {
$tip.hide();
}
}, duration);
}
/**
* 获取活动的指定优惠券
*/
function getNamedCoupon(activityId, couponId)
{
$.ajax({
type: 'POST',
url: '/cuxiao/coupon/getnamed',
data: 'activityId=' + activityId + '&couponId=' + couponId,
success: function(data) {
if (data.code == 200) {
showTip('领取成功');
}
else if (data.code == 400) {
location.href = data.data;
}
else if (data.message) {
showTip('领取失败');
}
},
error: function() {
showTip('网络断开连接啦~');
}
});
}
/**
* 获取活动所有的优惠券
*/
function getAllCoupon(activityId)
{
$.ajax({
type: 'POST',
url: '/cuxiao/coupon/getall',
data: 'activityId=' + activityId,
dataType: 'json',
success: function(data) {
if (data.code == 200) {
showTip('领取成功');
}
else if (data.code == 400) {
location.href = data.data;
}
else if (data.message) {
showTip('领取失败');
}
},
error: function() {
showErrTip('网络断开连接啦~');
}
});
}