|
|
1
|
+var $tip, tipItime;
|
|
|
2
|
+
|
|
|
3
|
+/* 领指定券 */
|
|
|
4
|
+var activityId = $('#coupon-container').attr('param');
|
|
|
5
|
+var userIsLogged = $('#coupon-container').attr('isLogged') === 'Y';
|
|
|
6
|
+var isApp = true;
|
|
|
7
|
+
|
|
|
8
|
+$('.get-coupon').click(function () {
|
|
|
9
|
+ var couponId = $(this).attr('param');
|
|
|
10
|
+ isApp = $(this).attr('href') !== 'javascript:;';
|
|
|
11
|
+ if (!isNaN(activityId) && !isNaN(couponId)) {
|
|
|
12
|
+ getNamedCoupon(activityId, couponId, isApp, userIsLogged);
|
|
|
13
|
+ }
|
|
|
14
|
+});
|
|
|
15
|
+/* 领所有券 */
|
|
|
16
|
+$('#get-all-coupon').click(function () {
|
|
|
17
|
+ var isApp = $(this).attr('href') !== 'javascript:;';
|
|
|
18
|
+ getAllCoupon(activityId, isApp);
|
|
|
19
|
+});
|
|
|
20
|
+
|
|
|
21
|
+/* 检查是否有在领取中的券,有则直接领取 */
|
|
|
22
|
+if (userIsLogged) {
|
|
|
23
|
+ var cookieCouponId = cookie('_Coupon' + activityId);
|
|
|
24
|
+ if (cookieCouponId && !isNaN(cookieCouponId)) {
|
|
|
25
|
+ getNamedCoupon(activityId, cookieCouponId, isApp, userIsLogged);
|
|
|
26
|
+ }
|
|
|
27
|
+}
|
|
|
28
|
+
|
|
|
29
|
+/**
|
|
|
30
|
+ * 微信分享
|
|
|
31
|
+ */
|
|
|
32
|
+(function ($) {
|
|
|
33
|
+ if (typeof (wx) == "undefined") {
|
|
|
34
|
+ return;
|
|
|
35
|
+ }
|
|
|
36
|
+ var _weChatInterface = 'http://www.yohoshow.com/api/wechat/getSignPackage';
|
|
|
37
|
+ $.getJSON(_weChatInterface + '?pageurl=' +
|
|
|
38
|
+ encodeURIComponent(location.href.split('#')[0]) + '&callback=?', function (json) {
|
|
|
39
|
+ var _appId, _timestamp, _nonceStr, _signature;
|
|
|
40
|
+ if (json !== undefined && json !== '') {
|
|
|
41
|
+ _appId = json.appId.toString();
|
|
|
42
|
+ _timestamp = json.timestamp;
|
|
|
43
|
+ _nonceStr = json.nonceStr.toString();
|
|
|
44
|
+ _signature = json.signature.toString();
|
|
|
45
|
+
|
|
|
46
|
+ wx.config({
|
|
|
47
|
+ debug: false,
|
|
|
48
|
+ appId: _appId,
|
|
|
49
|
+ timestamp: _timestamp,
|
|
|
50
|
+ nonceStr: _nonceStr,
|
|
|
51
|
+ signature: _signature,
|
|
|
52
|
+ jsApiList: [
|
|
|
53
|
+ 'checkJsApi',
|
|
|
54
|
+ 'onMenuShareTimeline',
|
|
|
55
|
+ 'onMenuShareAppMessage',
|
|
|
56
|
+ 'onMenuShareQQ',
|
|
|
57
|
+ 'onMenuShareWeibo',
|
|
|
58
|
+ 'hideMenuItems',
|
|
|
59
|
+ 'showMenuItems',
|
|
|
60
|
+ 'hideAllNonBaseMenuItem',
|
|
|
61
|
+ 'showAllNonBaseMenuItem',
|
|
|
62
|
+ 'translateVoice',
|
|
|
63
|
+ 'startRecord',
|
|
|
64
|
+ 'stopRecord',
|
|
|
65
|
+ 'onRecordEnd',
|
|
|
66
|
+ 'playVoice',
|
|
|
67
|
+ 'pauseVoice',
|
|
|
68
|
+ 'stopVoice',
|
|
|
69
|
+ 'uploadVoice',
|
|
|
70
|
+ 'downloadVoice',
|
|
|
71
|
+ 'chooseImage',
|
|
|
72
|
+ 'previewImage',
|
|
|
73
|
+ 'uploadImage',
|
|
|
74
|
+ 'downloadImage',
|
|
|
75
|
+ 'getNetworkType',
|
|
|
76
|
+ 'openLocation',
|
|
|
77
|
+ 'getLocation',
|
|
|
78
|
+ 'hideOptionMenu',
|
|
|
79
|
+ 'showOptionMenu',
|
|
|
80
|
+ 'closeWindow',
|
|
|
81
|
+ 'scanQRCode',
|
|
|
82
|
+ 'chooseWXPay',
|
|
|
83
|
+ 'openProductSpecificView',
|
|
|
84
|
+ 'addCard',
|
|
|
85
|
+ 'chooseCard',
|
|
|
86
|
+ 'openCard'
|
|
|
87
|
+ ]
|
|
|
88
|
+ });
|
|
|
89
|
+ }
|
|
|
90
|
+ });
|
|
|
91
|
+ wx.ready(function () {
|
|
|
92
|
+ var shareTitle = $('#shareTitle').val();
|
|
|
93
|
+ var shareImg = $('#shareImg').val();
|
|
|
94
|
+ var shareDesc = $('#shareDesc').val();
|
|
|
95
|
+ var shareLink = $('#shareLink').val();
|
|
|
96
|
+ var shareData = {
|
|
|
97
|
+ title: shareTitle,
|
|
|
98
|
+ desc: shareDesc,
|
|
|
99
|
+ imgUrl: shareImg,
|
|
|
100
|
+ link: shareLink
|
|
|
101
|
+ };
|
|
|
102
|
+ wx.onMenuShareAppMessage(shareData);
|
|
|
103
|
+ wx.onMenuShareTimeline(shareData);
|
|
|
104
|
+ wx.onMenuShareQQ(shareData);
|
|
|
105
|
+ wx.onMenuShareWeibo(shareData);
|
|
|
106
|
+ });
|
|
|
107
|
+}(jQuery));
|
|
|
108
|
+
|
|
|
109
|
+/**
|
|
|
110
|
+ * 初始化提示框
|
|
|
111
|
+ */
|
|
|
112
|
+(function () {
|
|
|
113
|
+ var tipHtml = '<div id="yoho-tip" class="yoho-tip"></div>';
|
|
|
114
|
+
|
|
|
115
|
+ //插入提示HTML
|
|
|
116
|
+ $('#coupon-container').append(tipHtml);
|
|
|
117
|
+
|
|
|
118
|
+ $tip = $('#yoho-tip');
|
|
|
119
|
+ $tip.on('touchend', function () {
|
|
|
120
|
+ $tip.hide();
|
|
|
121
|
+
|
|
|
122
|
+ //清除Timeout
|
|
|
123
|
+ clearTimeout(tipItime);
|
|
|
124
|
+ });
|
|
|
125
|
+}());
|
|
|
126
|
+
|
|
|
127
|
+function cookie(name) {
|
|
|
128
|
+ var cookies = document.cookie,
|
|
|
129
|
+ cookieVal,
|
|
|
130
|
+ offset;
|
|
|
131
|
+
|
|
|
132
|
+ if (document.cookie && document.cookie !== '') {
|
|
|
133
|
+ offset = cookies.indexOf(name + '=');
|
|
|
134
|
+ if (offset > -1) {
|
|
|
135
|
+ offset += name.length + 1;
|
|
|
136
|
+
|
|
|
137
|
+ cookieVal = decodeURIComponent($.trim(cookies.substring(offset, cookies.indexOf(';', offset))));
|
|
|
138
|
+ }
|
|
|
139
|
+ }
|
|
|
140
|
+
|
|
|
141
|
+ return cookieVal;
|
|
|
142
|
+}
|
|
|
143
|
+
|
|
|
144
|
+function setCookie(name, value, options) {
|
|
|
145
|
+ var expires = '',
|
|
|
146
|
+ path,
|
|
|
147
|
+ domain,
|
|
|
148
|
+ secure,
|
|
|
149
|
+ date;
|
|
|
150
|
+
|
|
|
151
|
+ if (typeof value !== 'undefined') {
|
|
|
152
|
+ options = options || {};
|
|
|
153
|
+ if (value === null) {
|
|
|
154
|
+ value = '';
|
|
|
155
|
+ options.expires = -1;
|
|
|
156
|
+ }
|
|
|
157
|
+
|
|
|
158
|
+ if (options.expires &&
|
|
|
159
|
+ (typeof options.expires === 'number' || options.expires.toUTCString)) {
|
|
|
160
|
+ if (typeof options.expires === 'number') {
|
|
|
161
|
+ date = new Date();
|
|
|
162
|
+ date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
|
|
|
163
|
+ } else {
|
|
|
164
|
+ date = options.expires;
|
|
|
165
|
+ }
|
|
|
166
|
+ expires = '; expires=' + date.toUTCString();
|
|
|
167
|
+ }
|
|
|
168
|
+ path = options.path ? '; path=' + options.path : '';
|
|
|
169
|
+ domain = options.domain ? '; domain=' + options.domain : '';
|
|
|
170
|
+ secure = options.secure ? '; secure' : '';
|
|
|
171
|
+ document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
|
|
172
|
+ }
|
|
|
173
|
+}
|
|
|
174
|
+
|
|
|
175
|
+/**
|
|
|
176
|
+ * 显示提示
|
|
|
177
|
+ */
|
|
|
178
|
+function showTip(con, dur) {
|
|
|
179
|
+ var content, duration;
|
|
|
180
|
+
|
|
|
181
|
+ if (typeof con === 'undefined') {
|
|
|
182
|
+ return;
|
|
|
183
|
+ }
|
|
|
184
|
+
|
|
|
185
|
+ content = con.toString();
|
|
|
186
|
+ duration = (dur && dur > 0) ? dur : 3000;
|
|
|
187
|
+
|
|
|
188
|
+ $tip.html(content).show();
|
|
|
189
|
+
|
|
|
190
|
+ tipItime = setTimeout(function () {
|
|
|
191
|
+ if ($tip.css('display') === 'block') {
|
|
|
192
|
+ $tip.hide();
|
|
|
193
|
+ }
|
|
|
194
|
+ }, duration);
|
|
|
195
|
+}
|
|
|
196
|
+
|
|
|
197
|
+/**
|
|
|
198
|
+ * 获取活动的指定优惠券
|
|
|
199
|
+ */
|
|
|
200
|
+function getNamedCoupon(activityId, couponId, isApp, userIsLogged)
|
|
|
201
|
+{
|
|
|
202
|
+ $.ajax({
|
|
|
203
|
+ type: 'POST',
|
|
|
204
|
+ url: '/cuxiao/coupon/getnamed',
|
|
|
205
|
+ data: 'activityId=' + activityId + '&couponId=' + couponId,
|
|
|
206
|
+ success: function (data) {
|
|
|
207
|
+ setCookie('_Coupon' + activityId, null, {
|
|
|
208
|
+ expires: -2,
|
|
|
209
|
+ domain: '.m.yohobuy.com'
|
|
|
210
|
+ });
|
|
|
211
|
+ if (isApp && !userIsLogged) {
|
|
|
212
|
+ return;
|
|
|
213
|
+ }
|
|
|
214
|
+ if (data.code == 200) {
|
|
|
215
|
+ showTip('恭喜您成功领取优惠券!<br><br>稍后即会到账,请耐心等待。');
|
|
|
216
|
+ }
|
|
|
217
|
+ else if (data.code == 201) {
|
|
|
218
|
+ showTip('您已领取过品牌优惠券<br><br>快去选购心仪的商品吧!');
|
|
|
219
|
+ }
|
|
|
220
|
+ else if (data.code == 400) {
|
|
|
221
|
+ setCookie('_Coupon' + activityId, couponId, {
|
|
|
222
|
+ expires: 1,
|
|
|
223
|
+ domain: '.m.yohobuy.com'
|
|
|
224
|
+ });
|
|
|
225
|
+ if (isApp) {
|
|
|
226
|
+ //showTip('请先登录!');
|
|
|
227
|
+ } else {
|
|
|
228
|
+ location.href = decodeURIComponent(data.data);
|
|
|
229
|
+ }
|
|
|
230
|
+ }
|
|
|
231
|
+ else if (data.message) {
|
|
|
232
|
+ //showTip(data.message);
|
|
|
233
|
+ if (data.message == '新用户才可领取') {
|
|
|
234
|
+ showTip('Sorry,新客券只有新客才能领取呦!');
|
|
|
235
|
+ } else {
|
|
|
236
|
+ showTip('领取失败<br><br>请稍候再试');
|
|
|
237
|
+ }
|
|
|
238
|
+ setCookie('_Coupon' + activityId, null);
|
|
|
239
|
+ }
|
|
|
240
|
+
|
|
|
241
|
+ },
|
|
|
242
|
+ error: function () {
|
|
|
243
|
+ showTip('网络断开连接啦~');
|
|
|
244
|
+ }
|
|
|
245
|
+ });
|
|
|
246
|
+}
|
|
|
247
|
+
|
|
|
248
|
+/**
|
|
|
249
|
+ * 获取活动所有的优惠券
|
|
|
250
|
+ */
|
|
|
251
|
+function getAllCoupon(activityId, isApp)
|
|
|
252
|
+{
|
|
|
253
|
+ $.ajax({
|
|
|
254
|
+ type: 'POST',
|
|
|
255
|
+ url: '/cuxiao/coupon/getall',
|
|
|
256
|
+ data: 'activityId=' + activityId,
|
|
|
257
|
+ dataType: 'json',
|
|
|
258
|
+ success: function (data) {
|
|
|
259
|
+ if (data.code == 200) {
|
|
|
260
|
+ showTip('恭喜您,成功领取');
|
|
|
261
|
+ }
|
|
|
262
|
+ else if (data.code == 201) {
|
|
|
263
|
+ showTip('对不起,您已经领取过');
|
|
|
264
|
+ }
|
|
|
265
|
+ else if (data.code == 400) {
|
|
|
266
|
+ if (isApp) {
|
|
|
267
|
+ showTip('请先登录!');
|
|
|
268
|
+ } else {
|
|
|
269
|
+ location.href = decodeURIComponent(data.data);
|
|
|
270
|
+ }
|
|
|
271
|
+ }
|
|
|
272
|
+ else if (data.message) {
|
|
|
273
|
+ //showTip(data.message);
|
|
|
274
|
+ showTip('系统繁忙,请稍候再试!');
|
|
|
275
|
+ }
|
|
|
276
|
+ },
|
|
|
277
|
+ error: function () {
|
|
|
278
|
+ showTip('网络断开连接啦~');
|
|
|
279
|
+ }
|
|
|
280
|
+ });
|
|
|
281
|
+} |