|
@@ -15,7 +15,7 @@ var $ = require('yoho-jquery'), |
|
@@ -15,7 +15,7 @@ var $ = require('yoho-jquery'), |
15
|
Handlebars = require('yoho-handlebars');
|
15
|
Handlebars = require('yoho-handlebars');
|
16
|
|
16
|
|
17
|
var bindEvent = $.Callbacks(); // eslint-disable-line
|
17
|
var bindEvent = $.Callbacks(); // eslint-disable-line
|
18
|
-var clickMoreCouponEvent = $.Callbacks('unique'); // eslint-disable-line
|
18
|
+var clickAcquireCouponEvent = $.Callbacks('unique'); // eslint-disable-line
|
19
|
|
19
|
|
20
|
var $main = $('.main'),
|
20
|
var $main = $('.main'),
|
21
|
id = $main.data('id'),
|
21
|
id = $main.data('id'),
|
|
@@ -128,23 +128,27 @@ bindEvent.add(function() { |
|
@@ -128,23 +128,27 @@ bindEvent.add(function() { |
128
|
function getCouponAsync(cid) {
|
128
|
function getCouponAsync(cid) {
|
129
|
var uid = getUid(); // eslint-disable-line
|
129
|
var uid = getUid(); // eslint-disable-line
|
130
|
|
130
|
|
131
|
- if (!uid || !cid) {
|
|
|
132
|
- return $.Deferred().reject().promise(); // eslint-disable-line
|
131
|
+ if (!uid) {
|
|
|
132
|
+ return $.Deferred().reject({refer: window.signinUrl()}).promise(); // eslint-disable-line
|
133
|
}
|
133
|
}
|
134
|
|
134
|
|
135
|
return $.getJSON('/product/detail/coupon', {
|
135
|
return $.getJSON('/product/detail/coupon', {
|
136
|
couponId: cid
|
136
|
couponId: cid
|
137
|
}).then(function(result) {
|
137
|
}).then(function(result) {
|
138
|
var defer = $.Deferred(); //eslint-disable-line
|
138
|
var defer = $.Deferred(); //eslint-disable-line
|
139
|
- result.code === 200 ? defer.resolve() : defer.reject();
|
139
|
+
|
|
|
140
|
+ if (result.code === 200) {
|
|
|
141
|
+ defer.resolve();
|
|
|
142
|
+ } else if (result.code === 400) {
|
|
|
143
|
+ defer.reject({refer: window.signinUrl()});
|
|
|
144
|
+ } else {
|
|
|
145
|
+ defer.reject();
|
|
|
146
|
+ }
|
|
|
147
|
+
|
140
|
return defer.promise();
|
148
|
return defer.promise();
|
141
|
});
|
149
|
});
|
142
|
}
|
150
|
}
|
143
|
|
151
|
|
144
|
- function jumpUrl(url) {
|
|
|
145
|
- window.location.href = url;
|
|
|
146
|
- }
|
|
|
147
|
-
|
|
|
148
|
/**
|
152
|
/**
|
149
|
* 获取当前选择的商品数目
|
153
|
* 获取当前选择的商品数目
|
150
|
* @return [Number]
|
154
|
* @return [Number]
|
|
@@ -574,7 +578,7 @@ bindEvent.add(function() { |
|
@@ -574,7 +578,7 @@ bindEvent.add(function() { |
574
|
// 打开优惠券列表
|
578
|
// 打开优惠券列表
|
575
|
$moreCoupon.on('click', openCouponDialog);
|
579
|
$moreCoupon.on('click', openCouponDialog);
|
576
|
|
580
|
|
577
|
- function clickMoreCoupon($ele) {
|
581
|
+ function acquireCoupon($ele) {
|
578
|
var couponId = $ele.data('id');
|
582
|
var couponId = $ele.data('id');
|
579
|
var status = $ele.data('status');
|
583
|
var status = $ele.data('status');
|
580
|
var i = $ele.data('i');
|
584
|
var i = $ele.data('i');
|
|
@@ -587,15 +591,19 @@ bindEvent.add(function() { |
|
@@ -587,15 +591,19 @@ bindEvent.add(function() { |
587
|
$ele.find('.coupon-go').empty().append(oldtatus.html);
|
591
|
$ele.find('.coupon-go').empty().append(oldtatus.html);
|
588
|
|
592
|
|
589
|
$item.data('status', 3);
|
593
|
$item.data('status', 3);
|
|
|
594
|
+ }).fail(function(err) {
|
|
|
595
|
+ if (err.refer) {
|
|
|
596
|
+ return window.jumpUrl(err.refer);
|
|
|
597
|
+ }
|
590
|
});
|
598
|
});
|
591
|
break;
|
599
|
break;
|
592
|
default:
|
600
|
default:
|
593
|
- jumpUrl(brandDomain);
|
601
|
+ window.jumpUrl(brandDomain);
|
594
|
}
|
602
|
}
|
595
|
}
|
603
|
}
|
596
|
|
604
|
|
597
|
// 增加事件
|
605
|
// 增加事件
|
598
|
- clickMoreCouponEvent.add(clickMoreCoupon);
|
606
|
+ clickAcquireCouponEvent.add(acquireCoupon);
|
599
|
});
|
607
|
});
|
600
|
|
608
|
|
601
|
// yas
|
609
|
// yas
|
|
@@ -605,7 +613,7 @@ require('./detail/latest-walk'); // 最近浏览 |
|
@@ -605,7 +613,7 @@ require('./detail/latest-walk'); // 最近浏览 |
605
|
|
613
|
|
606
|
// 优惠券的领取
|
614
|
// 优惠券的领取
|
607
|
$(document).on('click', '.status', function() {
|
615
|
$(document).on('click', '.status', function() {
|
608
|
- clickMoreCouponEvent.fire($(this));
|
616
|
+ clickAcquireCouponEvent.fire($(this));
|
609
|
});
|
617
|
});
|
610
|
|
618
|
|
611
|
// 品牌收藏
|
619
|
// 品牌收藏
|