Authored by htoooth

add

... ... @@ -124,7 +124,8 @@
</div>
{{/if}}
{{#if size}}<div class="description-material-tab info-block getnav" id="sizeMessage" data-id="1">
{{#if size.tbody}}<div class="description-material-tab info-block getnav" id="sizeMessage" data-id="1">
<p class="block-title" id="sizeTitle">
<span class="title-head"> <span class="title cur">尺码信息</span> </span>
</p>
... ...
... ... @@ -23,6 +23,7 @@ var bindEvent = $.Callbacks(); // eslint-disable-line
var cartEvent = new EventProxy();
var Dialog = require('../common/dialog').Dialog;
var Alert = require('../common/dialog').Alert;
var yasAtHead = require('./yas-head');
var yasAtBottom = require('./yas-bottom');
var $main = $('.main'),
... ... @@ -83,21 +84,76 @@ function isEmpty(el) {
function showSellOut() {
$shoppingCarBtn.addClass('disable')
.find('i').html('&#xe61c;').end()
.data('gocart', 0)
.find('span').html('已售罄');
}
function showAddCart() {
$shoppingCarBtn.removeClass('disable')
.data('gocart', 0)
.find('i').html('&#xe600;').end()
.find('span').html('加入购物车');
}
function showHasAddCart() {
$shoppingCarBtn.removeClass('disable')
.data('gocart', 1)
.find('i').html('&#xe600;').end()
.find('span').html('去购物车结算');
}
cartEvent.on('selling', showAddCart);
cartEvent.on('sellout', showSellOut);
cartEvent.on('gocart', showHasAddCart);
require('../plugins/slider');
require('../common/center-slider');
// 获取当前选择的商品数目
function getNum() {
return +$('#num').text();
}
function getSku() {
return $('.size:not(.hide) li.focus').data('sku');
}
function addCart() {
return $.ajax({
type: 'POST',
url: '/cart/index/add',
data: {
productSku: getSku(),
buyNumber: getNum()
}
}).then(function(data) {
var code = data.code;
var alert;
if (code === 200) {
$('#type-chose').slideUp(SLIDETIME);
$('#balance').slideDown(SLIDETIME);
$('#cart-num').text(data.data.goods_count); // 更新数目
return $.Deferred().resolve().promise();
} else if (code === 500) {
if (deposit) {
alert = new Alert('定金预售商品只能在APP端购买');
alert.show();
}
if (secKill) {
alert = new Alert('秒杀商品只能在APP端购买');
alert.show();
}
}
return $.Deferred().reject().promise();
});
}
bindEvent.add(function() {
var $imgShow = $('#img-show'),
$thumbs = $('#thumbs > .thumb-wrap');
... ... @@ -128,8 +184,6 @@ bindEvent.add(function() {
var brandDomain = $('.home').attr('href');
var Alert = require('../common/dialog').Alert;
/** 优惠券开始 **/
var $moreCoupon = $('.more-coupon'),
$couponItem = $('.coupon-item');
... ... @@ -235,10 +289,6 @@ bindEvent.add(function() {
/** 优惠券结束 **/
function getSku() {
return $('.size:not(.hide) li.focus').data('sku');
}
function imgShow(src) {
$imgShow.attr('src', src);
}
... ... @@ -328,11 +378,6 @@ bindEvent.add(function() {
}
});
// 获取当前选择的商品数目
function getNum() {
return +$num.text();
}
// 是否能:量贩购买,量贩小于库存才能购买
function canBundleBuy() {
return goodsBaseNum < maxStock;
... ... @@ -407,9 +452,11 @@ bindEvent.add(function() {
if (sellout()) {
$itemBuy.addClass('hide');
$soldOut.removeClass('hide');
cartEvent.emit('sellout');
} else {
$itemBuy.removeClass('hide');
$soldOut.addClass('hide');
cartEvent.emit('selling');
}
// 尺码选中的状态
... ... @@ -417,9 +464,11 @@ bindEvent.add(function() {
if (canBundleBuy()) {
$itemBuy.removeClass('hide');
$soldOut.addClass('hide');
cartEvent.emit('gocart');
} else {
$itemBuy.addClass('hide');
$soldOut.removeClass('hide');
cartEvent.emit('sellout');
}
}
... ... @@ -431,10 +480,17 @@ bindEvent.add(function() {
if (maxStock === 0 || ($color && ~~$color.data('total') === 0)) {
$itemBuy.addClass('hide'); // 隐藏加入购物车、即将开售、立即购买等相同位置的按钮
$soldOut.removeClass('hide');
cartEvent.emit('sellout');
} else {
// 包括默认的-1情况下
$itemBuy.removeClass('hide');
$soldOut.addClass('hide');
if (maxStock === -1) {
cartEvent.emit('selling');
} else {
cartEvent.emit('gocart');
}
}
}
... ... @@ -773,34 +829,7 @@ bindEvent.add(function() {
PRD_SKU: getSku()
});
$.ajax({
type: 'POST',
url: '/cart/index/add',
data: {
productSku: getSku(),
buyNumber: getNum()
}
}).then(function(data) {
var code = data.code;
var alert;
if (code === 200) {
$('#type-chose').slideUp(SLIDETIME);
$('#balance').slideDown(SLIDETIME);
$('#cart-num').text(data.data.goods_count); // 更新数目
} else if (code === 500) {
if (deposit) {
alert = new Alert('定金预售商品只能在APP端购买');
alert.show();
}
if (secKill) {
alert = new Alert('秒杀商品只能在APP端购买');
alert.show();
}
}
});
addCart();
});
// 收藏
... ... @@ -1832,8 +1861,23 @@ $('.shoppingCar').on('click', '.option', function(e) {
});
$('.shoppingCar-btn').on('click', function() {
var $this = $(this);
if ($this.hasClass('disable')) {
return;
}
if ($this.data('gocart') === 1) {
addCart().then(function() {
window.jumpUrl($('.go-cart').attr('href'));
});
return;
}
var $addToCart = $('#add-to-cart');
var sc = $(document);
sc.scrollTop(200);
if (maxStock === -1) {
... ...