Authored by htoooth

login

... ... @@ -188,6 +188,18 @@ function queryString() {
});
}());
function signinUrl() {
return '//www.yohobuy.com/signin.html?refer=' + window.location.href;
}
function registerUrl() {
return '//www.yohobuy.com/reg.html?refer=' + window.location.href;
}
function jumpUrl(url) {
window.location.href = url;
}
window.cookie = cookie;
window.setCookie = setCookie;
... ... @@ -202,5 +214,11 @@ window.getShoppingKey = getShoppingKey;
window.queryString = queryString;
window.signinUrl = signinUrl;
window.registerUrl = registerUrl;
window.jumpUrl = jumpUrl;
require('./header');
require('./footer');
... ...
... ... @@ -15,7 +15,7 @@ var $ = require('yoho-jquery'),
Handlebars = require('yoho-handlebars');
var bindEvent = $.Callbacks(); // eslint-disable-line
var clickMoreCouponEvent = $.Callbacks('unique'); // eslint-disable-line
var clickAcquireCouponEvent = $.Callbacks('unique'); // eslint-disable-line
var $main = $('.main'),
id = $main.data('id'),
... ... @@ -128,23 +128,27 @@ bindEvent.add(function() {
function getCouponAsync(cid) {
var uid = getUid(); // eslint-disable-line
if (!uid || !cid) {
return $.Deferred().reject().promise(); // eslint-disable-line
if (!uid) {
return $.Deferred().reject({refer: window.signinUrl()}).promise(); // eslint-disable-line
}
return $.getJSON('/product/detail/coupon', {
couponId: cid
}).then(function(result) {
var defer = $.Deferred(); //eslint-disable-line
result.code === 200 ? defer.resolve() : defer.reject();
if (result.code === 200) {
defer.resolve();
} else if (result.code === 400) {
defer.reject({refer: window.signinUrl()});
} else {
defer.reject();
}
return defer.promise();
});
}
function jumpUrl(url) {
window.location.href = url;
}
/**
* 获取当前选择的商品数目
* @return [Number]
... ... @@ -574,7 +578,7 @@ bindEvent.add(function() {
// 打开优惠券列表
$moreCoupon.on('click', openCouponDialog);
function clickMoreCoupon($ele) {
function acquireCoupon($ele) {
var couponId = $ele.data('id');
var status = $ele.data('status');
var i = $ele.data('i');
... ... @@ -587,15 +591,19 @@ bindEvent.add(function() {
$ele.find('.coupon-go').empty().append(oldtatus.html);
$item.data('status', 3);
}).fail(function(err) {
if (err.refer) {
return window.jumpUrl(err.refer);
}
});
break;
default:
jumpUrl(brandDomain);
window.jumpUrl(brandDomain);
}
}
// 增加事件
clickMoreCouponEvent.add(clickMoreCoupon);
clickAcquireCouponEvent.add(acquireCoupon);
});
// yas
... ... @@ -605,7 +613,7 @@ require('./detail/latest-walk'); // 最近浏览
// 优惠券的领取
$(document).on('click', '.status', function() {
clickMoreCouponEvent.fire($(this));
clickAcquireCouponEvent.fire($(this));
});
// 品牌收藏
... ...