Authored by 刘传洋

m

... ... @@ -3,13 +3,11 @@
*/
var $ = require('yoho-jquery'),
capi = require('./cart-api');
var rDialog = require('./rdialog');
var RConfirm = rDialog.RConfirm;
var RAlert = rDialog.RAlert;
var Cart;
rDialog = require('./rdialog'),
RConfirm = rDialog.RConfirm,
RAlert = rDialog.RAlert,
capi = require('./cart-api'),
Cart;
var $cartnewTips = $('.cartnew-tips'),
$cartListWrap = $('#Y_CartListWrap');
... ... @@ -417,4 +415,12 @@ $cartListWrap.on('click', '#Y_SubmitBtn', Cart.submit); // 结算
$cartListWrap.on('click', '#Y_delReselWrap [data-role=readd2cart]', Cart.reAdd2Cart);
$cartListWrap.on('click', '#Y_delReselWrap [data-role=reFav]', Cart.reFav);
// 商品子优惠显示和隐藏
$cartListWrap.on('mouseenter', '.sale-info', function(){
$(this).addClass('active').children('ul').removeClass('none');
});
$cartListWrap.on('mouseleave', '.sale-info', function(){
$(this).removeClass('active').children('ul').addClass('none');
});
module.exports = Cart;
... ...
... ... @@ -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
};
... ...
... ... @@ -5,103 +5,16 @@
*/
var $ = require('yoho-jquery'),
$sellBox = $('.cart-table .pre-sell-box');
capi = require('./cart-api');
require('../plugins/slider');
require('../common/center-slider');
require('../common');
require('../simple-header');
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 = [];
$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() {
var $itemChecked = $('[data-role=pitem] .cart-item-checked');
$('.bottom-tab .change').click(function() {
$('.img-brand-switch .next').trigger('click');
});
// 商品子优惠显示和隐藏
$('.sale-info').mouseenter(function() {
$(this).addClass('active').children('ul').removeClass('none');
}).mouseleave(function() {
$(this).removeClass('active').children('ul').addClass('none');
});
$('.side-img-dd').each(function() {
$(this).slider2({
shownum: 5,
isCircle: true
});
});
isCheckAll();
isCheckFav();
if ($itemChecked.length === 0) {
$('#Y_SubmitBtn').addClass('btn-account-disable');
}
});
require('./cart-action');
require('./cart-color-panel');
require('./cart-goods-win');
require('./cart-together');
$(capi.cartInit);
... ...