this_obj.siblings("ul").find("li").length - 1) { nowIndex = 0; } } // 导航切换 $(".set-meal-cont").eq(0).show(); CombinationPrice = $('.original_price_one').eq(0).find('span').text();//默认主商品的市场价 PriceSaving = $('.original_price_one_collocations').eq(0).find('span').text();//默认主商品的优惠价 $('.Price-saving').eq(0).find('span').text(PriceSaving);//默认主商品的优惠价 eachIput($('.at-que').eq(0).find('input[type=checkbox]')); $('.Combination-price').eq(0).find('i').text(CombinationPrice); $('.Price-saving').eq(0).find('span').text(PriceSaving); $('.set-meal-slect').eq(0).find('span').text(num); $(".set-meal-nav li").click(function () { var index = $(this).index(); CombinationPrice = $('.original_price_one').eq(index).find('span').text(); PriceSaving = $('.original_price_one_collocations').eq(index).find('span').text(); $('.Price-saving').eq(index).find('span').text(PriceSaving); eachIput($('.at-que').eq(index).find('input[type=checkbox]')); $('.Combination-price').eq(index).find('i').text(CombinationPrice); $('.Price-saving').eq(index).find('span').text(PriceSaving); $('.set-meal-slect').eq(index).find('span').text(num); $(".set-meal-nav li").removeClass("meal-nav-li"); $(this).addClass("meal-nav-li"); $(".set-meal-cont").hide(); $(".set-meal-cont").eq(index).show() }) })(); } //遍历默认选中的 function eachIput(data) { num = 1; data.each(function (i) { var checked = $(this).context.checked; if (checked) { var val = $(this).parents(".meal-price").find('span').text(); var saving = $(this).parents(".meal-price").next().find('span').text(); CombinationPrice = (CombinationPrice - 0) + (val - 0); PriceSaving = (PriceSaving - 0) + (saving - 0); num++; } }); } //选中获取价格 function clickGetPrice(e, price, saving) { var parents = $(e).parents(".set-meal-cont"); var CombinationCount = parents.find('.Combination-price').find('i').text(); var PriceCount = parents.find('.Price-saving').find('span').text(); if ($(e).attr('checked')) { $(e).removeAttr('checked') parents.find('.Combination-price').find('i').text((CombinationCount - price).toFixed(2)); parents.find('.Price-saving').find('span').text((PriceCount - saving).toFixed(2)); num-- parents.find('.set-meal-slect').find('span').text(num); } else { $(e).attr('checked', 'checked') parents.find('.Combination-price').find('i').text((CombinationCount - 0 + price).toFixed(2)); parents.find('.Price-saving').find('span').text((PriceCount - 0 + saving).toFixed(2)); num++ parents.find('.set-meal-slect').find('span').text(num); } } function addCombinationShop(e,t) { var a = $(e).parents('.set-meal-cont').find('.at-que').find('input[type=checkbox]'); var n = 0; var arr = new Array(); var address = $('#dispatching_msg').attr('region_id'); var combination = {goods_id:$(e).parents('.set-meal-cont').find('.combination_goods_ids').val(),item_id:$(e).parents('.set-meal-cont').find('.combination_item_id').val(),'region_id':address}; arr.push(combination) ; var combination_id = $(e).parents('.set-meal-cont').find('.combination_id').val(); $.each(a,function (i,o) { var checked = $(this).context.checked; if (checked) { var combination_goods_ids = {goods_id:$(this).attr('data-id'),item_id:$(this).attr('data-item'),'region_id':address}; arr.push(combination_goods_ids) ; n++; } }); if(n==0){ alert('请至少勾选一个商品'); return false; }else{ $.ajax({ type: "Post", url: "/Home/Cart/addCombination.html", data: {combination_id: combination_id, combination_goods: arr,num:1}, dataType: "json", success: function (data) { if (data.status == 1) { if(t==1){ location.href = "/index.php?m=Home&c=Cart&a=index"; return false; }else{ layer.open({ type: 2, title: '温馨提示', skin: 'layui-layer-rim', //加上边框 area: ['490px', '386px'], //宽高 content: "/index.php?m=Home&c=Goods&a=open_add_cart" }); } }else{ layer.msg(data.msg, {icon: 2}); } } }); } }
登录晨欣云商城