...
|
...
|
@@ -7,9 +7,92 @@ var $ = require('yoho-jquery'), |
|
|
Alert = dialog.Alert,
|
|
|
CART_ITEM_DEL_URL = '/cart/cart/remove',
|
|
|
CART_ITEM_FAV_URL = '/cart/cart/fav',
|
|
|
cartItemNumChg;
|
|
|
cartItemNumChg,
|
|
|
cartListTpl = require('mix/cart/cart-list.hbs');
|
|
|
|
|
|
var cartListTpl = require('mix/cart/cart-list.hbs');
|
|
|
// 设置全选按钮的状态
|
|
|
function isCheckAll() {
|
|
|
|
|
|
var isAllCheck = true;
|
|
|
|
|
|
$('[data-role=pitem] [data-role=cart-item-check]').each(function() {
|
|
|
|
|
|
var $chk = $(this);
|
|
|
|
|
|
// 有一个没选中,跳出循环
|
|
|
if (!$(this).hasClass('cart-item-checked') && !$chk.data('tipnostore')) {
|
|
|
isAllCheck = false;
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (isAllCheck) {
|
|
|
// 头部全选
|
|
|
$('.cart-title .cart-item-check').addClass('cart-item-checked');
|
|
|
|
|
|
// 底部全选
|
|
|
$('#cbSelAllGoods').addClass('cart-item-checked');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 判断商品是否已收藏,是否全选
|
|
|
function isCheckFav() {
|
|
|
var pidArray = [];
|
|
|
var $sellBox = $('.cart-table .pre-sell-box');
|
|
|
|
|
|
$sellBox.each(function() {
|
|
|
pidArray.push($(this).data('pid'));
|
|
|
});
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/cart/cart/checkFav',
|
|
|
data: {
|
|
|
pidList: pidArray.join(',')
|
|
|
}
|
|
|
}).done(function(result) {
|
|
|
$.each(result.data, function(pid, obj) {
|
|
|
|
|
|
if (obj.code !== 200) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (obj.data) {
|
|
|
$sellBox.each(function() {
|
|
|
if (String($(this).data('pid')) === String(pid)) {
|
|
|
$(this).find('.cart-col-btn').addClass('has-col-btn').html('已收藏');
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 初始化全选,是否收藏等
|
|
|
function cartInit() {
|
|
|
var $itemChecked = $('[data-role=pitem] .cart-item-checked');
|
|
|
|
|
|
if ($itemChecked.length === 0) {
|
|
|
$('#Y_SubmitBtn').addClass('btn-account-disable');
|
|
|
}
|
|
|
|
|
|
$('#Y_CartSelectDialog .side-img-dd').each(function() {
|
|
|
$(this).slider2({
|
|
|
shownum: 5,
|
|
|
isCircle: true
|
|
|
});
|
|
|
});
|
|
|
|
|
|
isCheckAll();
|
|
|
isCheckFav();
|
|
|
}
|
|
|
|
|
|
function refreshCart(data) {
|
|
|
$('#Y_CartListWrap').html(cartListTpl(data));
|
|
|
cartInit();
|
|
|
}
|
|
|
|
|
|
// checkbox提交ajax
|
|
|
function choiceOut(items) {
|
...
|
...
|
@@ -42,7 +125,7 @@ function choiceOut(items) { |
|
|
}).then(function(d) {
|
|
|
if (d.code === 200) {
|
|
|
// window.history.go(0);
|
|
|
$('#Y_CartListWrap').html(cartListTpl(d.data));
|
|
|
refreshCart(d.data);
|
|
|
}
|
|
|
}).always(function() {
|
|
|
$('.loading').hide();
|
...
|
...
|
@@ -91,7 +174,7 @@ function cartItemDel(items, type, cookieList) { |
|
|
});
|
|
|
}*/
|
|
|
// window.history.go(0);
|
|
|
$('#Y_CartListWrap').html(cartListTpl(d.data));
|
|
|
refreshCart(d.data);
|
|
|
} else if (d.code === 300) {
|
|
|
new Alert(d.message).show();
|
|
|
} else if (d.code === 403) {
|
...
|
...
|
@@ -125,7 +208,7 @@ cartItemNumChg = (function() { |
|
|
|
|
|
if (d.code === 200) {
|
|
|
// window.history.go(0);
|
|
|
$('#Y_CartListWrap').html(cartListTpl(d.data));
|
|
|
refreshCart(d.data);
|
|
|
} else {
|
|
|
new Alert(d.message === '' ? '加入购物车失败哦~~' : d.message).show();
|
|
|
}
|
...
|
...
|
@@ -156,7 +239,7 @@ function addcart(data, cookieList) { |
|
|
}).then(function(d) {
|
|
|
if (d.code === 200) {
|
|
|
// window.history.go(0);
|
|
|
$('#Y_CartListWrap').html(cartListTpl(d.data));
|
|
|
refreshCart(d.data);
|
|
|
if (cookieList) {
|
|
|
window.setCookie('cart-del-list', JSON.stringify(cookieList), {
|
|
|
domain: '.yohobuy.com',
|
...
|
...
|
@@ -433,5 +516,6 @@ module.exports = { |
|
|
getTogetherProduct: getTogetherProduct,
|
|
|
showMDialog: showMDialog,
|
|
|
hideMDialog: hideMDialog,
|
|
|
productCollect: productCollect
|
|
|
productCollect: productCollect,
|
|
|
cartInit: cartInit
|
|
|
}; |
...
|
...
|
|