Authored by 刘传洋

m

... ... @@ -856,6 +856,7 @@ const queryUserPromotionGift = (promotionId, uid, shoppingKey) => {
if (promotionGifts.data.goodsList && promotionGifts.data.goodsList.length) {
currentProduct = promotionGifts.data.goodsList[0];
currentProduct.active = true;
}
// 处理是否选中状态
... ...
... ... @@ -364,8 +364,11 @@
<div class="loading"><span></span>请稍后...</div>
<div id="Y_goodsSelectWin" class="goods-select-win">
<div class="goods-select-content"></div>
<div id="Y_goodsSelectWin" class="goods-select-win yoho-dialog cart-togetherGoods" style="top:50px;display:none;">
<div class="close">
<i class="iconfont">&#xe60d;</i>
</div>
<div class="content goods-select-content"></div>
</div>
</div>
... ...
... ... @@ -12,7 +12,7 @@
<div class="side-img-dd">
<ul class="img-list">
{{#each goodsList}}
<li class="img-item"
<li class="img-item {{#if active}}active{{/if}}"
data-id="{{id}}"
data-skn="{{skn}}"
data-ispricegift="{{isPriceGift}}"
... ...
... ... @@ -71,7 +71,8 @@
{{#each colors}}
<div class="showSizeBox size-row">
{{#each size}}
<span data-sku="{{sku}}" data-num="{{num}}">{{name}}</span>
<span data-sku="{{sku}}" data-num="{{num}}"
{{#unless num}}class="disabled"{{/unless}}>{{name}}</span>
{{/each}}
</div>
{{/each}}
... ...
... ... @@ -15,7 +15,8 @@ var $cartnewTips = $('.cartnew-tips'),
CART_ITEM_FAV_URL = '/cart/index/fav',
selColorWinTpl = require('hbs/cart/select-color-panel.hbs'),
giftsWinTpl = require('hbs/cart/cart-gifts-win-tpl.hbs'),
productInfoTpl = require('hbs/cart/cart-product-info-tpl.hbs');
productInfoTpl = require('hbs/cart/cart-product-info-tpl.hbs'),
$goodsSelWin = $('#Y_goodsSelectWin');
// 关闭温馨提示
$cartnewTips.find('.btn_close').click(function() {
... ... @@ -386,194 +387,19 @@ function getProductByPromotionId(promotionId) {
});
}
function bindGiftWinAction($el) {
$el.on('click', '.slide-img .img-list .img-item', function() {
var id = $(this).data('id');
var skn = $(this).data('skn');
getProductInfo(id, skn).then(res => {
$el.find('.product-detail-info').empty().append(productInfoTpl(res));
});
});
$el.on('click', '.piclist li', function() {
var $this = $(this);
var idx = $(this).index();
$el.find('.detail-bigpic:not(.none) .piclist li').removeClass('active');
$this.addClass('active');
$el.find('.detail-bigpic:not(.none) .bigpic').hide().eq(idx).show();
});
$el.on('click', '.pre, .next', function() {
var $this = $(this);
var $detailBigpic = $this.closest('.detail-bigpic');
var curIndex = Number($detailBigpic.data('_index') || 0);
var $lis = $this.siblings('.con').find('li');
if ($this.hasClass('next')) {
if (curIndex >= $lis.length - 1) {
return false;
}
curIndex++;
} else {
if (curIndex < 1) {
return false;
}
curIndex--;
}
$detailBigpic.data('_index', curIndex);
$lis.removeClass('active').eq(curIndex).addClass('active');
$detailBigpic.find('.bigpic').hide().eq(curIndex).show();
});
$el.on('click', '[data-role=colors] .color', function() {
var $this = $(this);
var idx = $this.index();
var $detail = $this.closest('.detail-goods');
var $sizes = $detail.find('[data-role=sizes] .size-row');
var $detailBigpic = $detail.find('.detail-bigpic');
var $curSize = $sizes.eq(idx);
var $curDetailBig = $detailBigpic.eq(idx);
var bigPicIndex = 0; // 默认显示大图中的第一个图
$curDetailBig.data('_index', bigPicIndex);
$this.siblings('.color').find('p').removeClass('active');
$this.find('p').addClass('active');
$sizes.addClass('none');
$curSize.removeClass('none');
if ($curSize.find('span').length < 2) {
$curSize.find('span:first').addClass('active');
}
$detailBigpic.addClass('none');
$curDetailBig.removeClass('active');
$curDetailBig.find('.bigpic').hide();
$curDetailBig.find('.bigpic').eq(bigPicIndex).show();
$curDetailBig.find('.con li').removeClass('active');
$curDetailBig.find('.con li').eq(bigPicIndex).addClass('active');
$sizes.eq(idx).find('span').each(function() {
if ($(this).hasClass('null-atcivec')) {
$el.find('.addcart').addClass('none');
$el.find('.btn_sellout').removeClass('none');
} else {
$el.find('.addcart').removeClass('none');
$el.find('.btn_sellout').addClass('none');
return false;
}
});
});
$el.on('click', '[data-role=sizes] .size-row span', function() {
var $this = $(this);
var idx = $this.index();
var shopNumAll = $this.data('num');
$this.siblings('span').removeClass('active');
$this.addClass('active');
if (shopNumAll > 0) {
$el.find('.addcart').removeClass('none');
$el.find('.btn_sellout').addClass('none');
} else {
$el.find('.addcart').addClass('none');
$el.find('.btn_sellout').removeClass('none');
}
});
$el.on('click', '.cut, .add', function() {
var $this = $(this);
var $pinfo = $this.closest('.product-detail-info');
// var count = $this.hasClass('minus') ? 'decreaseNum' : 'increaseNum';
var promotionId = $pinfo.data('promotionid');
var $num = $el.find('#num');
var shopNum = Number($num.val() || 1);
if (promotionId) {
if ($this.hasClass('cut')) {
new Alert('-_-,已经是最后一件,不能再减了!').show();
} else {
new Alert('最多只能购买一件,您好像购买的太多了!').show();
}
} else {
if ($this.hasClass('add')) {
shopNum++;
} else {
shopNum--;
}
if (shopNum < 1) {
new Alert('-_-,已经是最后一件,不能在减了!').show();
shopNum = 1;
return false;
}
$num.val(shopNum);
}
});
$el.on('click', '.addcart', function() {
var $this = $(this);
var $curSize = $el.find('[data-role=sizes] .size-row:not(.none) .active');
var $num = $el.find('#num');
var allNum = $curSize.data('num');
var sku = $curSize.data('sku');
var promotionId = $this.closest('.product-detail-info').data('promotionid') || 0;
var isSwap = $this.closest('.product-detail-info').data('swap');
if ($curSize.length <= 0) {
new Alert('请选择尺码').show();
return false;
}
if ($num.val() > allNum) {
new Alert('库存不足,目前还有' + allNum + '个库存').show();
} else {
/* if (Number($('#addToCart').val()) === 1) {
addcart(dataJSON);
} else {
new Alert('该商品无法加入购物车').show();
}*/
// 替换促销商品
if (isSwap) {
updateCartGiftItem(promotionId, newSkn, sku);
} else {
addcart({
productSku: sku,
buyNumber: $num.val(),
promotionId: promotionId
});
}
}
});
}
function renderAndShowGiftWin(plist) {
var d = new Dialog({
$goodsSelWin.find('.content').empty().html(giftsWinTpl(plist));
$goodsSelWin.show();
/* var d = new Dialog({
content: giftsWinTpl(plist),
className: 'cart-togetherGoods'
});
d.show();
d.show();*/
bindGiftWinAction(d.$el);
// bindGiftWinAction(d.$el);
}
var Cart = {
... ... @@ -1002,3 +828,194 @@ $('.shop-cart').on('click', giftBtn.join(','), function() {
$('.shop-cart').on('click', '[data-role="cart-gift-win"] .close', function() {
$(this).closest('[data-role="cart-gift-win"]').hide();
});*/
var GoodsWinAction = {
closeWin: function() {
// console.log($goodsSelWin);
$goodsSelWin.hide();
},
changeGoods: function() {
var $this = $(this);
var id = $this.data('id');
var skn = $this.data('skn');
$this.sibling('li').removeClass('active');
$this.addClass('active');
getProductInfo(id, skn).then(res => {
$goodsSelWin.find('.product-detail-info').empty().append(productInfoTpl(res));
});
},
selThumb: function() {
var $this = $(this);
var idx = $(this).index();
$goodsSelWin.find('.detail-bigpic:not(.none) .piclist li').removeClass('active');
$this.addClass('active');
$goodsSelWin.find('.detail-bigpic:not(.none) .bigpic').hide().eq(idx).show();
},
selThumbPrevNext: function() {
var $this = $(this);
var $detailBigpic = $this.closest('.detail-bigpic');
var curIndex = Number($detailBigpic.data('_index') || 0);
var $lis = $this.siblings('.con').find('li');
if ($this.hasClass('next')) {
if (curIndex >= $lis.length - 1) {
return false;
}
curIndex++;
} else {
if (curIndex < 1) {
return false;
}
curIndex--;
}
$detailBigpic.data('_index', curIndex);
$lis.removeClass('active').eq(curIndex).addClass('active');
$detailBigpic.find('.bigpic').hide().eq(curIndex).show();
},
selColor: function() {
var $this = $(this);
var idx = $this.index();
var $detail = $this.closest('.detail-goods');
var $sizes = $detail.find('[data-role=sizes] .size-row');
var $detailBigpic = $detail.find('.detail-bigpic');
var $curSize = $sizes.eq(idx);
var $curDetailBig = $detailBigpic.eq(idx);
var bigPicIndex = 0; // 默认显示大图中的第一个图
$curDetailBig.data('_index', bigPicIndex);
$this.siblings('.color').find('p').removeClass('active');
$this.find('p').addClass('active');
$sizes.addClass('none');
$curSize.removeClass('none');
if ($curSize.find('span').length < 2) {
$curSize.find('span:first').addClass('active');
}
$detailBigpic.addClass('none');
$curDetailBig.removeClass('none');
$curDetailBig.find('.bigpic').hide();
$curDetailBig.find('.bigpic').eq(bigPicIndex).show();
$curDetailBig.find('.con li').removeClass('active');
$curDetailBig.find('.con li').eq(bigPicIndex).addClass('active');
$sizes.eq(idx).find('span').each(function() {
if ($(this).hasClass('null-atcivec')) {
$goodsSelWin.find('.addcart').addClass('none');
$goodsSelWin.find('.btn_sellout').removeClass('none');
} else {
$goodsSelWin.find('.addcart').removeClass('none');
$goodsSelWin.find('.btn_sellout').addClass('none');
return false;
}
});
},
selSize: function() {
var $this = $(this);
// var idx = $this.index();
var shopNumAll = $this.data('num');
$this.siblings('span').removeClass('active');
$this.addClass('active');
if (shopNumAll > 0) {
$goodsSelWin.find('.addcart').removeClass('none');
$goodsSelWin.find('.btn_sellout').addClass('none');
} else {
$goodsSelWin.find('.addcart').addClass('none');
$goodsSelWin.find('.btn_sellout').removeClass('none');
}
},
changeNum: function() {
var $this = $(this);
var $pinfo = $this.closest('.product-detail-info');
// var count = $this.hasClass('minus') ? 'decreaseNum' : 'increaseNum';
var promotionId = $pinfo.data('promotionid');
var $num = $goodsSelWin.find('#num');
var shopNum = Number($num.val() || 1);
if (promotionId) {
if ($this.hasClass('cut')) {
new Alert('-_-,已经是最后一件,不能再减了!').show();
} else {
new Alert('最多只能购买一件,您好像购买的太多了!').show();
}
} else {
if ($this.hasClass('add')) {
shopNum++;
} else {
shopNum--;
}
if (shopNum < 1) {
new Alert('-_-,已经是最后一件,不能在减了!').show();
shopNum = 1;
return false;
}
$num.val(shopNum);
}
},
add2Cart: function() {
var $this = $(this);
var $curSize = $goodsSelWin.find('[data-role=sizes] .size-row:not(.none) .active');
var $num = $goodsSelWin.find('#num');
var allNum = $curSize.data('num');
var sku = $curSize.data('sku');
var promotionId = $this.closest('.product-detail-info').data('promotionid') || 0;
var isSwap = $this.closest('.product-detail-info').data('swap');
if ($curSize.length <= 0) {
new Alert('请选择尺码').show();
return false;
}
if ($num.val() > allNum) {
new Alert('库存不足,目前还有' + allNum + '个库存').show();
} else {
/* if (Number($('#addToCart').val()) === 1) {
addcart(dataJSON);
} else {
new Alert('该商品无法加入购物车').show();
}*/
// 替换促销商品
if (isSwap) {
updateCartGiftItem(promotionId, newSkn, sku);
} else {
addcart({
productSku: sku,
buyNumber: $num.val(),
promotionId: promotionId
});
}
}
}
};
/** 弹窗事件绑定 **/
$goodsSelWin.on('click', '.close', GoodsWinAction.closeWin);
$goodsSelWin.on('click', '.slide-img .img-list .img-item', GoodsWinAction.changeGoods);
$goodsSelWin.on('click', '.piclist li', GoodsWinAction.selThumb);
$goodsSelWin.on('click', '.pre, .next', GoodsWinAction.selThumbPrevNext);
$goodsSelWin.on('click', '[data-role=colors] .color', GoodsWinAction.selColor);
$goodsSelWin.on('click', '[data-role=sizes] .size-row span', GoodsWinAction.selSize);
$goodsSelWin.on('click', '.cut, .add', GoodsWinAction.changeNum);
$goodsSelWin.on('click', '.addcart', GoodsWinAction.add2Cart);
... ...
/**
* Created by yoho on 2017-01-05.
*/
var $ = require('yoho-jquery');
var dialog = require('../common/dialog');
var Alert = dialog.Alert,
CART_ITEM_DEL_URL = '/cart/index/remove',
CART_ITEM_FAV_URL = '/cart/index/fav';
// checkbox提交ajax
function choiceOut(items) {
var skuList = $.isArray(items) ? items : [items];
var hasPromotion = false;
$.each(skuList, function(idx, it) {
if (it.promotion_id) {
hasPromotion = true;
return false;
}
});
return $.ajax({
type: 'POST',
dataType: 'json',
url: '/cart/index/select',
data: {
skuList: JSON.stringify(skuList),
hasPromotion: hasPromotion
},
beforeSend: function() {
$('.loading').css({
top: $(document).scrollTop() + 200
});
$('.loading').show();
}
}).then(function(d) {
if (d.code === 200) {
window.history.go(0);
}
});
}
/*
* 1. 删除购物车商品,把删除的商品移入cookie中
* 2. 移到收藏夹
* data: 数据
* tpe: true - 删除,默认 移入收藏夹
*/
function cartItemDel(items, type, cookieList) {
var selList = $.isArray(items) ? items : [items];
var hasPromotion = false;
$.each(selList, function(idx, it) {
if (it.promotion_id) {
hasPromotion = true;
return false;
}
});
return $.ajax({
type: 'POST',
dataType: 'json',
url: type === true ? CART_ITEM_DEL_URL : CART_ITEM_FAV_URL,
data: {
skuList: JSON.stringify(selList),
hasPromotion: hasPromotion
},
beforeSend: function() {
$('.loading').css({
top: $(document).scrollTop() + 200
});
$('.loading').show();
}
}).then(function(d) {
if (d.code === 200) {
if (cookieList) {
window.setCookie('cart-del-list', JSON.stringify(cookieList), {
domain: '.yohobuy.com',
path: '/'
});
}
window.history.go(0);
} else if (d.code === 300) {
$('.loading').hide();
new Alert(d.message).show();
} else if (d.code === 403) {
if (d.data.url) {
window.location = d.data.url;
}
}
});
}
// 购物车商品增减
var cartItemNumChg = (function() {
var countBusy = false; // 保证一次只请求完成前不能再次发起
return function(data) {
if (countBusy) {
return;
}
countBusy = true;
$.ajax({
type: 'POST',
dataType: 'json',
url: '/cart/index/modifyNum',
data: data
}).then(function(d) {
if (d.code === 200) {
window.history.go(0);
} else {
new Alert(d.message === '' ? '加入购物车失败哦~~' : d.message).show();
}
countBusy = false;
});
};
})();
function getProductInfo(pid, skn) {
return $.ajax({
type: 'GET',
url: '/cart/index/getProductData', // '/product/item/getProductInfo',
data: {
productId: pid,
skn: skn
}
}).done(function(res) {
return res;
});
}
// 加入购物车,弹出框中加入购物车
function addcart(data, cookieList) {
$.ajax({
type: 'POST',
url: '/cart/index/add',
data: data
}).then(function(d) {
if (d.code === 200) {
window.history.go(0);
if (cookieList) {
window.setCookie('cart-del-list', JSON.stringify(cookieList), {
domain: '.yohobuy.com',
path: '/'
});
}
} else {
new Alert(d.message === '' ? '加入购物车失败哦~~' : d.message).show();
}
});
}
function parseProductInfo(productInfo, defaultInfo) {
var index = 0;
var colors;
var colorsLen;
var color;
// 前端处理后的集合
var filterSet = [];
var sizeIdx;
var curColor;
var curSize;
var hasActiveColor = false;
var defaultColor = defaultInfo.color;
var defaultSize = defaultInfo.size;
var defaultImg;
// 没有res.code
if (productInfo.colors) {
// 获取成功
colors = productInfo.colors;
colorsLen = colors.length;
for (index; index < colorsLen; index++) {
color = colors[index];
// 迭代每一种颜色
filterSet.push({
pid: productInfo.productId,
skn: productInfo.skn,
name: color.name,
src: color.src,
focus: color.focus,
title: color.title,
sizes: color.size,
pic: color.thumbs[0].shower,
selectable: color.total > 0
});
}
}
// 默认选中用户选择的sku,若已售罄或下架,则选中列表中第一个非售罄的sku
for (index = 0; index < filterSet.length; index++) {
curColor = filterSet[index];
if (!hasActiveColor && String(curColor.name) === String(defaultInfo.color)) {
curColor.active = true;
curColor.hasActiveColor = hasActiveColor = true;
defaultImg = curColor.pic;
}
curSize = curColor.sizes;
for (sizeIdx = 0; sizeIdx < curSize.length; sizeIdx++) {
if (curColor.hasActiveColor && curSize[sizeIdx].sku === defaultInfo.sku) {
// console.log(curSize[sizeIdx]);
curSize[sizeIdx].sizeActive = true;
break;
}
}
}
// 若无对应颜色,则选中第一个颜色
if (!hasActiveColor) {
filterSet[0].active = true;
defaultColor = filterSet[0].color;
defaultImg = filterSet[0].pic;
}
return {
skn: productInfo.skn,
colors: filterSet,
defaultColor: defaultColor,
defaultSize: defaultSize,
defaultImg: defaultImg
};
}
function updateCartItem(newSku, oldSku) {
$.ajax({
type: 'POST',
url: '/cart/index/updateProduct',
data: {
swapData: JSON.stringify([{
buy_number: '1',
selected: 'Y',
new_product_sku: newSku,
old_product_sku: oldSku
}])
}
}).then(function(d) {
if (d.code === 200) {
window.history.go(0);
} else {
new Alert(d.message === '' ? '修改商品失败哦~~' : d.message).show();
}
});
}
function updateCartGiftItem(promotionId, newSkn, newSku) {
$.ajax({
type: 'POST',
url: '/cart/index/swapGift',
data: {
promotionId: promotionId,
newSkn: newSkn,
newSku: newSku
}
}).then(function(d) {
if (d.code === 200) {
window.history.go(0);
} else {
new Alert(d.message === '' ? '修改商品失败哦~~' : d.message).show();
}
});
}
function getProductByPromotionId(promotionId) {
return $.ajax({
type: 'GET',
url: '/cart/index/queryPromotionGift',
data: {
promotionId: promotionId
}
}).done(function(res) {
return res;
});
}
module.exports = {
addcart: addcart,
getProductInfo: getProductInfo,
choiceOut: choiceOut,
cartItemDel: cartItemDel,
cartItemNumChg: cartItemNumChg,
parseProductInfo: parseProductInfo,
updateCartItem: updateCartItem,
updateCartGiftItem: updateCartGiftItem,
getProductByPromotionId: getProductByPromotionId
};
... ...
/**
* Created by yoho on 2017-01-05.
*/
var $ = require('yoho-jquery');
var dialog = require('../common/dialog');
var Alert = dialog.Alert;
var $payWapper = $('.pay-wapper'),
giftsWinTpl = require('hbs/cart/cart-gifts-win-tpl.hbs'),
productInfoTpl = require('hbs/cart/cart-product-info-tpl.hbs'),
$goodsSelWin = $('#Y_goodsSelectWin');
var capi = require('./cart-api');
function renderAndShowGiftWin(plist) {
$goodsSelWin.find('.content').empty().html(giftsWinTpl(plist));
$goodsSelWin.show();
}
/** 赠品加价购弹窗 **/
var GoodsWinAction = {
showGiftWin: function() {
var $this = $(this);
var $wrap = $this.closest('[data-role="promotion-wrap"]');
var promotionid = $wrap.data('promotionid');
var promotionInfo = $wrap.data('_promotionInfo');
var role = $this.data('role');
var isSwap = role === 'pg-resel-btn' || role === 'gift-resel-btn';
if (!promotionInfo) {
capi.getProductByPromotionId(promotionid).done(function(pinfo) {
if (!pinfo && pinfo.code !== 200) {
return new Alert('获取商品失败,请稍后再试!').show();
}
promotionInfo = pinfo.data;
promotionInfo.isSwap = isSwap;
$wrap.data('_promotionInfo', promotionInfo);
renderAndShowGiftWin(promotionInfo);
}).fail(function() {
new Alert('获取商品失败,请稍后再试!').show();
});
return;
}
renderAndShowGiftWin(promotionInfo);
},
closeWin: function() {
$goodsSelWin.hide();
},
changeGoods: function() {
var $this = $(this);
var id = $this.data('id');
var skn = $this.data('skn');
$this.sibling('li').removeClass('active');
$this.addClass('active');
capi.getProductInfo(id, skn).then(res => {
$goodsSelWin.find('.product-detail-info').empty().append(productInfoTpl(res));
});
},
selThumb: function() {
var $this = $(this);
var idx = $(this).index();
$goodsSelWin.find('.detail-bigpic:not(.none) .piclist li').removeClass('active');
$this.addClass('active');
$goodsSelWin.find('.detail-bigpic:not(.none) .bigpic').hide().eq(idx).show();
},
selThumbPrevNext: function() {
var $this = $(this);
var $detailBigpic = $this.closest('.detail-bigpic');
var curIndex = Number($detailBigpic.data('_index') || 0);
var $lis = $this.siblings('.con').find('li');
if ($this.hasClass('next')) {
if (curIndex >= $lis.length - 1) {
return false;
}
curIndex++;
} else {
if (curIndex < 1) {
return false;
}
curIndex--;
}
$detailBigpic.data('_index', curIndex);
$lis.removeClass('active').eq(curIndex).addClass('active');
$detailBigpic.find('.bigpic').hide().eq(curIndex).show();
},
selColor: function() {
var $this = $(this);
var idx = $this.index();
var $detail = $this.closest('.detail-goods');
var $sizes = $detail.find('[data-role=sizes] .size-row');
var $detailBigpic = $detail.find('.detail-bigpic');
var $curSize = $sizes.eq(idx);
var $curDetailBig = $detailBigpic.eq(idx);
var bigPicIndex = 0; // 默认显示大图中的第一个图
$curDetailBig.data('_index', bigPicIndex);
$this.siblings('.color').find('p').removeClass('active');
$this.find('p').addClass('active');
$sizes.addClass('none');
$curSize.removeClass('none');
if ($curSize.find('span').length < 2) {
$curSize.find('span:first').addClass('active');
}
$detailBigpic.addClass('none');
$curDetailBig.removeClass('none');
$curDetailBig.find('.bigpic').hide();
$curDetailBig.find('.bigpic').eq(bigPicIndex).show();
$curDetailBig.find('.con li').removeClass('active');
$curDetailBig.find('.con li').eq(bigPicIndex).addClass('active');
$sizes.eq(idx).find('span').each(function() {
if ($(this).hasClass('null-atcivec')) {
$goodsSelWin.find('.addcart').addClass('none');
$goodsSelWin.find('.btn_sellout').removeClass('none');
} else {
$goodsSelWin.find('.addcart').removeClass('none');
$goodsSelWin.find('.btn_sellout').addClass('none');
return false;
}
});
},
selSize: function() {
var $this = $(this);
// var idx = $this.index();
var shopNumAll = $this.data('num');
$this.siblings('span').removeClass('active');
$this.addClass('active');
if (shopNumAll > 0) {
$goodsSelWin.find('.addcart').removeClass('none');
$goodsSelWin.find('.btn_sellout').addClass('none');
} else {
$goodsSelWin.find('.addcart').addClass('none');
$goodsSelWin.find('.btn_sellout').removeClass('none');
}
},
changeNum: function() {
var $this = $(this);
var $pinfo = $this.closest('.product-detail-info');
// var count = $this.hasClass('minus') ? 'decreaseNum' : 'increaseNum';
var promotionId = $pinfo.data('promotionid');
var $num = $goodsSelWin.find('#num');
var shopNum = Number($num.val() || 1);
if (promotionId) {
if ($this.hasClass('cut')) {
new Alert('-_-,已经是最后一件,不能再减了!').show();
} else {
new Alert('最多只能购买一件,您好像购买的太多了!').show();
}
} else {
if ($this.hasClass('add')) {
shopNum++;
} else {
shopNum--;
}
if (shopNum < 1) {
new Alert('-_-,已经是最后一件,不能在减了!').show();
shopNum = 1;
return false;
}
$num.val(shopNum);
}
},
add2Cart: function() {
var $this = $(this);
var $curSize = $goodsSelWin.find('[data-role=sizes] .size-row:not(.none) .active');
var $num = $goodsSelWin.find('#num');
var allNum = $curSize.data('num');
var sku = $curSize.data('sku');
var promotionId = $this.closest('.product-detail-info').data('promotionid') || 0;
var isSwap = $this.closest('.product-detail-info').data('swap');
if ($curSize.length <= 0) {
new Alert('请选择尺码').show();
return false;
}
if ($num.val() > allNum) {
new Alert('库存不足,目前还有' + allNum + '个库存').show();
} else {
/* if (Number($('#addToCart').val()) === 1) {
addcart(dataJSON);
} else {
new Alert('该商品无法加入购物车').show();
}*/
// 替换促销商品
if (isSwap) {
capi.updateCartGiftItem(promotionId, newSkn, sku);
} else {
capi.addcart({
productSku: sku,
buyNumber: $num.val(),
promotionId: promotionId
});
}
}
}
};
/** 弹窗事件绑定 **/
// 显示赠品
var giftBtn = ['[data-role=gift-view-btn]',
'[data-role=gift-resel-btn]',
'[data-role=gift-sel-btn]',
'[data-role=pg-sel-btn]',
'[data-role=pg-resel-btn]'];
$payWapper./* find('li[data-role="pitem"]').*/on('click', giftBtn.join(','), GoodsWinAction.showGiftWin);
$goodsSelWin.on('click', '.close', GoodsWinAction.closeWin);
$goodsSelWin.on('click', '.slide-img .img-list .img-item', GoodsWinAction.changeGoods);
$goodsSelWin.on('click', '.piclist li', GoodsWinAction.selThumb);
$goodsSelWin.on('click', '.pre, .next', GoodsWinAction.selThumbPrevNext);
$goodsSelWin.on('click', '[data-role=colors] .color', GoodsWinAction.selColor);
$goodsSelWin.on('click', '[data-role=sizes] .size-row span', GoodsWinAction.selSize);
$goodsSelWin.on('click', '.cut, .add', GoodsWinAction.changeNum);
$goodsSelWin.on('click', '.addcart', GoodsWinAction.add2Cart);
module.exports = GoodsWinAction;
... ...
... ... @@ -512,4 +512,5 @@ $('.shop-cart').on('click', '[data-role="cart-gift-win"] .close', function() {
$(this).closest('[data-role="cart-gift-win"]').hide();
});
require('./cart-action');
// require('./cart-action');
require('./cart-goods-win');
... ...