...
|
...
|
@@ -9,24 +9,54 @@ var Alert = Dialog.Alert; |
|
|
var $cartnewTips = $('.cartnew-tips'),
|
|
|
$payWapper = $('.pay-wapper'),
|
|
|
$cartnewSum = $('.cartnew-sum'),
|
|
|
selectArray = [],
|
|
|
hasPromotion = false,
|
|
|
countJSON;
|
|
|
|
|
|
CART_ITEM_DEL_URL = '/cart/index/remove',
|
|
|
CART_ITEM_FAV_URL = '/cart/index/fav',
|
|
|
selColorWinTpl = require('hbs/cart/select-color-panel.hbs');
|
|
|
|
|
|
// 关闭温馨提示
|
|
|
$cartnewTips.find('.btn_close').click(function() {
|
|
|
$cartnewTips.fadeOut();
|
|
|
});
|
|
|
|
|
|
// 滚动到第一个选中的商品
|
|
|
function scrollToFirst() {
|
|
|
var $selected = $payWapper.find('li[data-role="pitem"] .cart-item-check.cart-item-checked:eq(0)');
|
|
|
var top = 0;
|
|
|
|
|
|
if ($selected.length > 0) {
|
|
|
top = $selected.offset().top - 36;
|
|
|
$('html,body').scrollTop(top);
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
function toggleCheckAllPros() {
|
|
|
|
|
|
}
|
|
|
|
|
|
// checkbox提交ajax
|
|
|
function choiceOut(data) {
|
|
|
$.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: data,
|
|
|
data: {
|
|
|
skuList: JSON.stringify(skuList),
|
|
|
hasPromotion: hasPromotion
|
|
|
},
|
|
|
beforeSend: function() {
|
|
|
$('.loading').css({
|
|
|
top: $(document).scrollTop() + 200
|
...
|
...
|
@@ -40,123 +70,32 @@ function choiceOut(data) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
// 单选提交
|
|
|
$payWapper.one('click', 'li[data-role="pitem"] .cart-item-check', function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var selected = $this.hasClass('cart-item-checked') ? 'Y' : 'N';
|
|
|
var $pitem = $this.closest('li[data-role="pitem"]');
|
|
|
|
|
|
var item = {
|
|
|
product_sku: $pitem.data('id'),
|
|
|
selected: selected,
|
|
|
buy_number: $pitem.data('productnum'),
|
|
|
goods_type: $pitem.data('goodstype'),
|
|
|
promotion_id: $pitem.data('promotionid') ? $pitem.data('promotionid') : 0
|
|
|
};
|
|
|
|
|
|
if (item.promotion_id) {
|
|
|
hasPromotion = true;
|
|
|
} else {
|
|
|
hasPromotion = false;
|
|
|
}
|
|
|
|
|
|
selectArray.push(item);
|
|
|
var dataJSON = {
|
|
|
skuList: JSON.stringify(selectArray),
|
|
|
hasPromotion: hasPromotion
|
|
|
};
|
|
|
choiceOut(dataJSON);
|
|
|
});
|
|
|
|
|
|
|
|
|
// 全选提交
|
|
|
$cartnewSum.one('click', '.cart-item-check', function() {
|
|
|
var $this = $(this);
|
|
|
var dataJSON = {};
|
|
|
var selected = $this.hasClass('cart-item-checked') ? 'Y' : 'N';
|
|
|
|
|
|
$payWapper.find('.cart-item-check').each(function() {
|
|
|
var $t = $(this);
|
|
|
if ($t.data('promotionid')) {
|
|
|
hasPromotion = true;
|
|
|
}
|
|
|
|
|
|
if ($t.data('id')) {
|
|
|
selectArray.push({
|
|
|
product_sku: $t.data('id'),
|
|
|
selected: selected,
|
|
|
buy_number: $t.data('productnum'),
|
|
|
goods_type: $t.data('goodstype'),
|
|
|
promotion_id: $t.data('promotionid') ? $t.data('promotionid') : 0
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
dataJSON = {
|
|
|
skuList: JSON.stringify(selectArray),
|
|
|
hasPromotion: hasPromotion
|
|
|
};
|
|
|
choiceOut(dataJSON);
|
|
|
});
|
|
|
|
|
|
// 滚动到第一个选中的商品
|
|
|
function scrollToFirst() {
|
|
|
var $selected = $payWapper.find('li[data-role="pitem"] .cart-item-check.cart-item-checked:eq(0)');
|
|
|
var top = 0;
|
|
|
|
|
|
if ($selected.length > 0) {
|
|
|
top = $selected.offset().top - 36;
|
|
|
$('html,body').scrollTop(top);
|
|
|
}
|
|
|
/*
|
|
|
* 1. 删除购物车商品,把删除的商品移入cookie中
|
|
|
* 2. 移到收藏夹
|
|
|
* data: 数据
|
|
|
* tpe: true - 删除,默认 移入收藏夹
|
|
|
*/
|
|
|
function cartItemDel(items, type, cookieList) {
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
var selList = $.isArray(items) ? items: [items];
|
|
|
var hasPromotion = false;
|
|
|
|
|
|
/*
|
|
|
function isCheck(obj, className) {
|
|
|
selectArray = [];
|
|
|
dataJSON = {};
|
|
|
selected = obj.attr('checked') ? 'Y' : 'N';
|
|
|
$('.' + className).each(function() {
|
|
|
if ($(this).data('promotionid')) {
|
|
|
$.each(selList, function(idx, it){
|
|
|
if(it.promotion_id) {
|
|
|
hasPromotion = true;
|
|
|
} else {
|
|
|
hasPromotion = false;
|
|
|
}
|
|
|
if ($(this).data('id')) {
|
|
|
selectArray.push({
|
|
|
product_sku: $(this).data('id'),
|
|
|
selected: selected,
|
|
|
buy_number: $(this).data('productnum'),
|
|
|
goods_type: $(this).data('goodstype'),
|
|
|
promotion_id: $(this).data('promotionid') ? $(this).data('promotionid') : 0
|
|
|
});
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
dataJSON = {
|
|
|
skuList: JSON.stringify(selectArray),
|
|
|
hasPromotion: hasPromotion
|
|
|
};
|
|
|
choiceOut(dataJSON);
|
|
|
}*/
|
|
|
|
|
|
/* $('.per-list').on('click', 'input[type="checkbox"]', function() {
|
|
|
isCheck($(this), 'pre-sell-box');
|
|
|
});
|
|
|
|
|
|
$('.common-list').on('click', 'input[type="checkbox"]', function() {
|
|
|
isCheck($(this), 'common-sell-box');
|
|
|
});*/
|
|
|
|
|
|
|
|
|
// 删除购物车商品,把删除的商品移入cookie中
|
|
|
function cartItemDel(data, delUrl, cookieList) {
|
|
|
$.ajax({
|
|
|
return $.ajax({
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
url: delUrl,
|
|
|
data: dataJSON,
|
|
|
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
|
...
|
...
|
@@ -183,142 +122,531 @@ function cartItemDel(data, delUrl, cookieList) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
//购物车商品增减
|
|
|
var cartItemNumChg = (function(data) {
|
|
|
|
|
|
// 删除商品
|
|
|
$payWapper.on('click', '.cart-del-btn', function() {
|
|
|
var countBusy = false; // 保证一次只请求完成前不能再次发起
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $item = $this.closest('li[data-role="pitem"]');
|
|
|
var dataJSON = {};
|
|
|
var selectArray = [];
|
|
|
var promotionId = $item.data('promotionid') ? $item.data('promotionid') : 0;
|
|
|
|
|
|
selectArray.push({
|
|
|
product_sku: $item.data('id'),
|
|
|
buy_number: $item.data('productnum'),
|
|
|
promotion_id: promotionId
|
|
|
});
|
|
|
return function(data){
|
|
|
|
|
|
if (promotionId) {
|
|
|
hasPromotion = true;
|
|
|
} else {
|
|
|
hasPromotion = false;
|
|
|
if(countBusy) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
countBusy = true;
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
url: '/cart/index/modify',
|
|
|
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;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
dataJSON = {
|
|
|
skuList: JSON.stringify(selectArray),
|
|
|
hasPromotion: hasPromotion
|
|
|
};
|
|
|
content = '<div><span></span>删除商品</div><p>确定从购物车中删除此商品?</p>';
|
|
|
|
|
|
if (!$this.data('gift')) {
|
|
|
countJSON = {
|
|
|
productPrice: $item.find('.productPrice').text(),
|
|
|
productTitle: $item.find('.pay-pro-info a').text(),
|
|
|
link: $item.find('.pay-pro-info a').attr('href'),
|
|
|
productNum: $item.data('productnum'),
|
|
|
productSku: $item.data('id'),
|
|
|
promotionId: $item.data('promotionid')
|
|
|
};
|
|
|
//加入购物车,弹出框中加入购物车
|
|
|
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({
|
|
|
proId: res.id,
|
|
|
color: color.color,
|
|
|
sizes: color.sizes,
|
|
|
pic: color.thumbs[0],
|
|
|
selectable: color.total > 0,
|
|
|
rgb: color.rgb
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
delUrl = '/cart/index/remove';
|
|
|
new Confirm({
|
|
|
content: content,
|
|
|
cb: function() {
|
|
|
cartItemDel(dataJSON, delUrl, countJSON);
|
|
|
|
|
|
// 默认选中用户选择的sku,若已售罄或下架,则选中列表中第一个非售罄的sku
|
|
|
for (index = 0; index < filterSet.length; index++) {
|
|
|
curColor = filterSet[index];
|
|
|
if (!hasActiveColor && curColor.color === defaultInfo.color) {
|
|
|
curColor.active = true;
|
|
|
curColor.hasActiveColor = hasActiveColor = true;
|
|
|
|
|
|
defaultImg = curColor.pic;
|
|
|
}
|
|
|
}).show();
|
|
|
});
|
|
|
|
|
|
// 移入收藏夹
|
|
|
$payWapper.on('click', '.cart-remove-btn', function() {
|
|
|
curSize = curColor.sizes;
|
|
|
for (sizeIdx = 0; sizeIdx < curSize.length; sizeIdx++) {
|
|
|
if (curColor.hasActiveColor && curSize[sizeIdx].name === defaultInfo.size) {
|
|
|
curSize[sizeIdx].sizeFocus = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $item = $this.closest('li[data-role="pitem"]');
|
|
|
|
|
|
dataJSON = {};
|
|
|
selectArray = [];
|
|
|
var promotionId = $item.data('promotionid') ? $item.data('promotionid') : 0;
|
|
|
selectArray.push({
|
|
|
product_sku: $item.data('id'),
|
|
|
buy_number: $item.data('productnum'),
|
|
|
promotion_id: promotionId
|
|
|
});
|
|
|
// 若无对应颜色,则选中第一个颜色
|
|
|
if (!hasActiveColor) {
|
|
|
filterSet[0].active = true;
|
|
|
defaultColor = filterSet[0].color;
|
|
|
|
|
|
if (promotionId) {
|
|
|
hasPromotion = true;
|
|
|
} else {
|
|
|
hasPromotion = false;
|
|
|
defaultImg = filterSet[0].pic;
|
|
|
}
|
|
|
|
|
|
dataJSON = {
|
|
|
skuList: JSON.stringify(selectArray),
|
|
|
hasPromotion: hasPromotion
|
|
|
return {
|
|
|
colors: filterSet,
|
|
|
defaultColor: defaultColor,
|
|
|
defaultSize: defaultSize,
|
|
|
defaultImg: defaultImg
|
|
|
};
|
|
|
}
|
|
|
|
|
|
cartItemDel(dataJSON, '/cart/index/fav');
|
|
|
});
|
|
|
function renderAndShowSelWin($edit, pinfo) {
|
|
|
|
|
|
$edit.find('.goods-choose-box').remove();
|
|
|
var $selWin = selColorWinTpl(pinfo).appendTo($edit);
|
|
|
$selWin.show();
|
|
|
}
|
|
|
|
|
|
// 批量删除商品
|
|
|
$cartnewSum.on('click', '.delAll', function() {
|
|
|
dataJSON = {};
|
|
|
countJSON = {};
|
|
|
selectArray = [];
|
|
|
PromotionArray = [];
|
|
|
var Cart = {
|
|
|
addToCart: function(params){
|
|
|
|
|
|
$payWapper.find('.cart-item-check').each(function(){
|
|
|
},
|
|
|
toggleSelectOne: function() { // 单选
|
|
|
|
|
|
var $item = $(this);
|
|
|
var $chk = $item.find('.cart-item-check');
|
|
|
if($chk.hasClass('cart-item-checked')) {
|
|
|
var $this = $(this);
|
|
|
var $pitem = $this.closest('li[data-role="pitem"]');
|
|
|
var item = {
|
|
|
product_sku: $pitem.data('id'),
|
|
|
selected: $this.hasClass('cart-item-checked') ? 'Y' : 'N',
|
|
|
buy_number: $pitem.data('productnum'),
|
|
|
goods_type: $pitem.data('goodstype'),
|
|
|
promotion_id: $pitem.data('promotionid') ? $pitem.data('promotionid') : 0
|
|
|
};
|
|
|
|
|
|
var promotionId = $item.data('promotionid') ? $item.data('promotionid') : 0;
|
|
|
return choiceOut(item);
|
|
|
},
|
|
|
toggleSelectAll: function() { // 全选
|
|
|
|
|
|
if (promotionId) {
|
|
|
hasPromotion = true;
|
|
|
}
|
|
|
var $this = $(this);
|
|
|
var selected = $this.hasClass('cart-item-checked') ? 'Y' : 'N';
|
|
|
var selectArray = [];
|
|
|
|
|
|
if ($item.data('id')) {
|
|
|
$payWapper.find('.cart-item-check').each(function() {
|
|
|
var $t = $(this);
|
|
|
|
|
|
if ($t.data('id')) {
|
|
|
selectArray.push({
|
|
|
product_sku: $item.data('id'),
|
|
|
buy_number: $item.data('productnum'),
|
|
|
promotion_id: promotionId
|
|
|
product_sku: $t.data('id'),
|
|
|
selected: selected,
|
|
|
buy_number: $t.data('productnum'),
|
|
|
goods_type: $t.data('goodstype'),
|
|
|
promotion_id: $t.data('promotionid') || 0
|
|
|
});
|
|
|
|
|
|
countJSON = {
|
|
|
productPrice: $item.find('.productPrice').text(),
|
|
|
productTitle: $item.find('.pay-pro-info a').text(),
|
|
|
link: $item.find('.pay-pro-info a').attr('href'),
|
|
|
productNum: $item.data('productnum'),
|
|
|
productSku: $item.data('id'),
|
|
|
promotionId: $item.data('promotionid')
|
|
|
};
|
|
|
PromotionArray.push(countJSON);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
choiceOut(selectArray);
|
|
|
},
|
|
|
del: function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $item = $this.closest('li[data-role="pitem"]');
|
|
|
var selectArray = [];
|
|
|
var content = '<div><span></span>删除商品</div><p>确定从购物车中删除此商品?</p>';
|
|
|
var countJSON;
|
|
|
|
|
|
selectArray.push({
|
|
|
product_sku: $item.data('id'),
|
|
|
buy_number: $item.data('productnum'),
|
|
|
promotion_id: $item.data('promotionid') || 0
|
|
|
});
|
|
|
|
|
|
if (!$this.data('gift')) {
|
|
|
countJSON = {
|
|
|
productPrice: $item.find('.productPrice').text(),
|
|
|
productTitle: $item.find('.pay-pro-info a').text(),
|
|
|
link: $item.find('.pay-pro-info a').attr('href'),
|
|
|
productNum: $item.data('productnum'),
|
|
|
productSku: $item.data('id'),
|
|
|
promotionId: $item.data('promotionid')
|
|
|
};
|
|
|
}
|
|
|
});
|
|
|
|
|
|
delUrl = '/cart/index/remove';
|
|
|
content = '<div><span></span>删除商品</div><p>确定从购物车中删除所有选中商品?</p>';
|
|
|
dataJSON = {
|
|
|
skuList: JSON.stringify(selectArray),
|
|
|
hasPromotion: hasPromotion
|
|
|
};
|
|
|
|
|
|
if (!$.isEmptyObject(selectArray)) {
|
|
|
new Confirm({
|
|
|
content: content,
|
|
|
cb: function() {
|
|
|
cartitemDel(dataJSON, delUrl, PromotionArray);
|
|
|
cartItemDel(selectArray, true, countJSON);
|
|
|
}
|
|
|
}).show();
|
|
|
} else {
|
|
|
new Alert('请至少选择一件商品').show();
|
|
|
},
|
|
|
delAll: function() {
|
|
|
|
|
|
var selectArray = [];
|
|
|
var PromotionArray = [];
|
|
|
var content = '<div><span></span>删除商品</div><p>确定从购物车中删除所有选中商品?</p>';
|
|
|
|
|
|
$payWapper.find('.cart-item-check').each(function() {
|
|
|
|
|
|
var $item = $(this);
|
|
|
var $chk = $item.find('.cart-item-check');
|
|
|
if ($chk.hasClass('cart-item-checked')) {
|
|
|
|
|
|
if ($item.data('id')) {
|
|
|
|
|
|
selectArray.push({
|
|
|
product_sku: $item.data('id'),
|
|
|
buy_number: $item.data('productnum'),
|
|
|
promotion_id: $item.data('promotionid') || 0
|
|
|
});
|
|
|
|
|
|
PromotionArray.push({
|
|
|
productPrice: $item.find('.productPrice').text(),
|
|
|
productTitle: $item.find('.pay-pro-info a').text(),
|
|
|
link: $item.find('.pay-pro-info a').attr('href'),
|
|
|
productNum: $item.data('productnum'),
|
|
|
productSku: $item.data('id'),
|
|
|
promotionId: $item.data('promotionid')
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (!$.isEmptyObject(selectArray)) {
|
|
|
new Confirm({
|
|
|
content: content,
|
|
|
cb: function() {
|
|
|
cartItemDel(selectArray, true, PromotionArray);
|
|
|
}
|
|
|
}).show();
|
|
|
} else {
|
|
|
new Alert('请至少选择一件商品').show();
|
|
|
}
|
|
|
},
|
|
|
toFav: function () {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $item = $this.closest('li[data-role="pitem"]');
|
|
|
var item = {
|
|
|
product_sku: $item.data('id'),
|
|
|
buy_number: $item.data('productnum'),
|
|
|
promotion_id: $item.data('promotionid') ? $item.data('promotionid') : 0
|
|
|
};
|
|
|
|
|
|
cartItemDel(item);
|
|
|
},
|
|
|
toFavAll: function(){
|
|
|
|
|
|
var selectArray = [];
|
|
|
|
|
|
$payWapper.find('.cart-item-check').each(function() {
|
|
|
|
|
|
var $item = $(this);
|
|
|
var $chk = $item.find('.cart-item-check');
|
|
|
if ($chk.hasClass('cart-item-checked')) {
|
|
|
|
|
|
if ($item.data('id')) {
|
|
|
selectArray.push({
|
|
|
product_sku: $(this).data('id'),
|
|
|
buy_number: $(this).data('productnum'),
|
|
|
promotion_id: $item.data('promotionid') || 0
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (!$.isEmptyObject(selectArray)) {
|
|
|
cartItemDel(selectArray);
|
|
|
} else {
|
|
|
new Alert('请至少选择一件商品').show();
|
|
|
}
|
|
|
},
|
|
|
modNum: function() {
|
|
|
var $this = $(this);
|
|
|
var countJSON = {};
|
|
|
var oprType = $this.hasClass('minus') ? 'decreaseNum' : 'increaseNum';
|
|
|
|
|
|
countJSON[oprType] = 1;
|
|
|
if ($this.siblings('input').val() === '1' && $this.hasClass('minus')) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
cartItemNumChg($.extend(countJSON, {
|
|
|
sku: $this.closest('li[data-role="pitem"]').data('id')
|
|
|
}));
|
|
|
},
|
|
|
cleanAllDisable: function() {
|
|
|
var selectArray = [];
|
|
|
var PromotionArray = [];
|
|
|
var content = '<div><span></span>删除商品</div><p>确定从购物车中删除所有选中商品?</p>';
|
|
|
|
|
|
$payWapper.find('.cart-item-check').each(function() {
|
|
|
|
|
|
var $item = $(this);
|
|
|
var $chk = $item.find('.cart-item-check');
|
|
|
if ($chk.hasClass('cart-item-checked')) {
|
|
|
|
|
|
if ($item.data('id')) {
|
|
|
|
|
|
selectArray.push({
|
|
|
product_sku: $item.data('id'),
|
|
|
buy_number: $item.data('productnum'),
|
|
|
promotion_id: $item.data('promotionid') || 0
|
|
|
});
|
|
|
|
|
|
PromotionArray.push({
|
|
|
productPrice: $item.find('.productPrice').text(),
|
|
|
productTitle: $item.find('.pay-pro-info a').text(),
|
|
|
link: $item.find('.pay-pro-info a').attr('href'),
|
|
|
productNum: $item.data('productnum'),
|
|
|
productSku: $item.data('id'),
|
|
|
promotionId: $item.data('promotionid')
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (!$.isEmptyObject(selectArray)) {
|
|
|
new Confirm({
|
|
|
content: content,
|
|
|
cb: function() {
|
|
|
cartItemDel(selectArray, true, PromotionArray);
|
|
|
}
|
|
|
}).show();
|
|
|
} else {
|
|
|
new Alert('请至少选择一件商品').show();
|
|
|
}
|
|
|
},
|
|
|
showColorSizePanel: function(){
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $item = $this.closest('li[data-role="pitem"]');
|
|
|
var pinfo = $this.data('_p_info');
|
|
|
var $selWin = $this.find('.goods-choose-box');
|
|
|
var pid = $item.data('pid');
|
|
|
var skn = $item.data('skn');
|
|
|
var defaultInfo = {
|
|
|
color: $this.find('.default-color').text(),
|
|
|
size: $this.find('.default-size').text(),
|
|
|
pid: pid,
|
|
|
skn: skn
|
|
|
};
|
|
|
|
|
|
if($selWin && $selWin.length && $selWin.is(':visible')) {
|
|
|
$selWin.hide();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(!pinfo) {
|
|
|
getProductInfo(pid, skn).done(function(productInfo){
|
|
|
|
|
|
pinfo = parseProductInfo(productInfo, defaultInfo);
|
|
|
$this.data('_p_info', pinfo);
|
|
|
renderAndShowSelWin($this, pinfo);
|
|
|
}).fail(function(){
|
|
|
new Alert('此商品无法编辑颜色和尺寸').show();
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
renderAndShowSelWin($this, pinfo);
|
|
|
},
|
|
|
editColorOrSize: function(productId, skn, defaultColor, defaultSize, editTarget) {
|
|
|
|
|
|
},
|
|
|
submit: function() {
|
|
|
/*understock = '';
|
|
|
if ($('.pay-wapper input:checked').parents('tr').find('.tipNoStore').length > 0) {
|
|
|
shopName = $('.pay-wapper input:checked').parents('tr').find('.tipNoStore');
|
|
|
$.each(shopName.parents('tr').find('.pay-pro-info a'), function() {
|
|
|
understock += $(this).html();
|
|
|
});
|
|
|
new Alert(understock + '库存不足').show();
|
|
|
} else {
|
|
|
if ($('.zp').length > 0 && !$(this).attr('title')) {
|
|
|
$(this).attr('title', '1');
|
|
|
new Alert('您有赠品没有选择,请选择完再结算!').show();
|
|
|
} else {
|
|
|
if ($('input:checked').length > 0) {
|
|
|
|
|
|
// 添加埋点
|
|
|
var productId = [];
|
|
|
$('.pay-wapper input:checked').parents('tr').each(function() {
|
|
|
if ($(this).attr('data-pid')) {
|
|
|
productId.push($(this).attr('data-pid'));
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 结算点击埋点
|
|
|
window.addPoint('YB_SC_TOBUY_CLICK', {PRD_ID: productId.join(',')});
|
|
|
|
|
|
|
|
|
if ($('.pre-sell-box input:checked').length > 0) {
|
|
|
window.location.href = '/cart/index/orderEnsure?type=2';
|
|
|
} else {
|
|
|
window.location.href = '/cart/index/orderEnsure?type=1';
|
|
|
}
|
|
|
} else {
|
|
|
new Alert('请至少选择一件商品').show();
|
|
|
}
|
|
|
}
|
|
|
}*/
|
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports = Cart;
|
|
|
|
|
|
$payWapper.one('click', 'li[data-role="pitem"] .cart-item-check', Cart.toggleSelectOne); // 单选
|
|
|
$cartnewSum.one('click', '.cart-item-check', Cart.toggleSelectAll); // 全选
|
|
|
$payWapper.on('click', '.cart-del-btn', Cart.del); // 删除商品
|
|
|
$cartnewSum.on('click', '.delAll', Cart.delAll); // 批量删除商品
|
|
|
$payWapper.on('click', '.cart-remove-btn', Cart.toFav); // 移入收藏夹
|
|
|
$cartnewSum.on('click', '.removeAll', Cart.toFavAll); // 批量移入收藏夹商品
|
|
|
$payWapper.on('click', '.minus, .plus', Cart.modNum); // 修改购物车数量
|
|
|
$cartnewSum.on('click', '.clean-all-disable', Cart.cleanAllDisable);
|
|
|
$('.btn_account').on('click', Cart.submit); // 结算
|
|
|
|
|
|
$payWapper.on('click', 'li[data-role="pitem"] .pay-pro-detail', Cart.showColorSizePanel);
|
|
|
|
|
|
/// 绑定颜色尺码弹窗事件 begin
|
|
|
/*
|
|
|
oldProductSku = editTarget.find('.current').attr('data-sku');
|
|
|
|
|
|
// rebind events(Tips依赖接口数据,so 不能delegate)
|
|
|
editTarget.find('#confirm').click(function(e) {
|
|
|
e.preventDefault();
|
|
|
|
|
|
newProductSku = editTarget.find('.current-sizes .active').attr('data-sku');
|
|
|
|
|
|
// 没有重新选择颜色-尺码,则不用重新请求显示
|
|
|
if (!oldProductSku || !newProductSku || newProductSku === oldProductSku) {
|
|
|
editTarget.find('.edit-color-size').remove();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
Util.ajax({
|
|
|
url: '/shopping/cart/updateProduct',
|
|
|
type: 'PUT',
|
|
|
data: {
|
|
|
swapData: JSON.stringify([{
|
|
|
buy_number: '1',
|
|
|
selected: 'Y',
|
|
|
new_product_sku: newProductSku,
|
|
|
old_product_sku: oldProductSku
|
|
|
}])
|
|
|
},
|
|
|
success: function(newCartData) {
|
|
|
editTarget.find('.edit-color-size').remove();
|
|
|
Util.refreshCart(newCartData);
|
|
|
setEditable();
|
|
|
}
|
|
|
});
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
editTarget.find('#cancel').click(function(e) {
|
|
|
e.preventDefault();
|
|
|
editTarget.find('.edit-color-size').remove();
|
|
|
setEditable();
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
editTarget.find('.edit-color-size').click(function(e) {
|
|
|
e.preventDefault();
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
editTarget.find('.color-item').click(function(e) {
|
|
|
e.preventDefault();
|
|
|
selectColor = $(this);
|
|
|
if (!selectColor.hasClass('current-color')) {
|
|
|
selectColor.addClass('current-color').siblings().removeClass('current-color');
|
|
|
selectColor.parent().siblings('.current-sizes').hide().removeClass('current-sizes');
|
|
|
editTarget.find('#' + selectColor.attr('data-target')).show().addClass('current-sizes')
|
|
|
.end()
|
|
|
.find('.right img').attr({
|
|
|
src: selectColor.attr('data-imageurl'),
|
|
|
title: selectColor.attr('data-title')
|
|
|
})
|
|
|
.end()
|
|
|
.find('.selected-color').text(selectColor.attr('data-title'));
|
|
|
}
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
editTarget.find('.size-item').click(function() {
|
|
|
var $this = $(this);
|
|
|
|
|
|
if ($this.hasClass('active') || $this.hasClass('disabled')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$(this).addClass('active').siblings('.active').removeClass('active');
|
|
|
});
|
|
|
|
|
|
// 初始化size list选中项(其他颜色中第一个尺码)
|
|
|
editTarget.find('.sizes-list.mb10').each(function() {
|
|
|
if ($(this).find('.active').length === 0) {
|
|
|
$(this).find('.size-item:not(.disabled)').first().addClass('active');
|
|
|
}
|
|
|
});*/
|
|
|
|
|
|
/// 绑定颜色尺码弹窗事件 end
|
|
|
|
|
|
// 显示赠品
|
|
|
var giftBtn = '[data-role=gift-view-btn],[data-role=gift-resel-btn],[data-role=gift-sel-btn]';
|
|
|
|
...
|
...
|
|