} else { //如果选中的商品不等于所有商品
Shops.prop('checked', false).parent(".gwc_label").removeClass("gwc_active"); //店铺全选按钮不被选中
// 计算
TotalPrice();
}
});
// 点击店铺
$(".ShopCheck").change(function() {
if ($(this).prop("checked") == true) { //如果全选按钮被选中
$(".gwc_label").addClass("gwc_active");
$(".GoodsCheck").prop('checked', true).parent(".gwc_1").addClass("gwc_active"); //所有按钮都被选中
// 计算
TotalPrice()
} else {
$(".gwc_label").removeClass("gwc_active");
$(".GoodsCheck").prop('checked', false).parent(".gwc_1").removeClass("gwc_active"); //else所有按钮不全选
// 计算
TotalPrice();
}
});
//删除
$('.delete').click(function () {
$(".dfk_main input[type='checkbox']:checked").each(function() { // 遍历选中的checkbox
var goods = $(this).parents('.dfk_main').find(".GoodsCheck"); //获取本店铺的所有商品
var goodsC = $(this).parents('.dfk_main').find(".GoodsCheck:checked"); //获取本店铺所有被选中的商品
var Shops = $(".ShopCheck"); //获取本店铺的全选按钮
if (goods.length == goodsC.length) { //如果选中的商品等于所有商品
$('.dfk_main').html('<a href="#" rel="external nofollow" >购物车为空<br>点击去购买</a>').addClass('flex-center kong');
Shops.prop('checked', false).parent(".gwc_label").removeClass("gwc_active"); //店铺全选按钮不被选中
$('.gwc_sl,.ShopTotal').text(0.00);
TotalPrice();
} else { //如果选中的商品不等于所有商品
var n = $(this).parents('.gwc_dl').index(); // 获取checkbox所在行的顺序
$(".dfk_main").find(".gwc_dl:eq("+n+")").remove();
TotalPrice();
}
});
});
function TotalPrice() {
var oprice = 0; //店铺总价
var sl = 0;//数量
$(".dfk_main .gwc_dl .GoodsCheck").each(function () { //循环店铺里面的商品
if ($(this).is(":checked")) { //如果该商品被选中
var num = parseInt($(this).parents(".gwc_dl").find(".shuliang").val()); //得到商品的数量
// alert(num);
var price = parseFloat($(this).parents(".gwc_dl").find(".gwc_dd_p").text()); //得到商品的单价
var total = price * num; //计算单个商品的总价
oprice += parseFloat(total); //计算该店铺的总价
sl += parseInt(num);
}
$('.gwc_sl').text(sl);
$(".ShopTotal").text(oprice.toFixed(2)); //输出全部总价
});
}
});
// document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + 'px';
</script>
</body>
</html>










