Authored by htoooth

login

@@ -188,6 +188,18 @@ function queryString() { @@ -188,6 +188,18 @@ function queryString() {
188 }); 188 });
189 }()); 189 }());
190 190
  191 +function signinUrl() {
  192 + return '//www.yohobuy.com/signin.html?refer=' + window.location.href;
  193 +}
  194 +
  195 +function registerUrl() {
  196 + return '//www.yohobuy.com/reg.html?refer=' + window.location.href;
  197 +}
  198 +
  199 +function jumpUrl(url) {
  200 + window.location.href = url;
  201 +}
  202 +
191 window.cookie = cookie; 203 window.cookie = cookie;
192 204
193 window.setCookie = setCookie; 205 window.setCookie = setCookie;
@@ -202,5 +214,11 @@ window.getShoppingKey = getShoppingKey; @@ -202,5 +214,11 @@ window.getShoppingKey = getShoppingKey;
202 214
203 window.queryString = queryString; 215 window.queryString = queryString;
204 216
  217 +window.signinUrl = signinUrl;
  218 +
  219 +window.registerUrl = registerUrl;
  220 +
  221 +window.jumpUrl = jumpUrl;
  222 +
205 require('./header'); 223 require('./header');
206 require('./footer'); 224 require('./footer');
@@ -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 // 品牌收藏