isplay','none'); $('[data-keytop='+key+']').css('display','block'); }) //选择规格属性 $('.pctoll-name-item .spec_item').each(function(k,v){ if(!$(this).hasClass('nosold')){ $(this).click(function(){ $(this).siblings().children('span').removeClass('active'); $(this).siblings().children('input').prop('checked',false); $(this).children('input').prop('checked',true); $(this).children('span').addClass('active'); var data_name = $(this).attr('data-name'); var val = $(this).children('input').val(); $('.pcul').css('display','block'); switch(data_name){ case '品牌': $('.spec_item').each(function(k,v){ $(v).removeClass('hide_spec'); $(v).addClass('show_spec'); }) var type = ''; var data = Enumerable.From([]).Where(function (x) { return x.key.indexOf(val+"_")==0 }).ToArray(); setSpecItem(data); break; case '车型': $('.spec_item').each(function(k,v){ $(v).removeClass('hide_spec'); $(v).addClass('show_spec'); }) var type = ''; var data = Enumerable.From([]).Where(function (x) { return x.key.indexOf('_'+val+"_")!=-1 }).ToArray(); setSpecItem(data); break; case '发动机': $('.spec_item').each(function(k,v){ $(v).removeClass('hide_spec'); $(v).addClass('show_spec'); }) $('[data-name=变速箱]').each(function(){ $(this).children('input').prop('checked',false); $(this).children('span').removeClass('active'); }) $('[data-name=其它]').each(function(){ $(this).children('input').prop('checked',false); $(this).children('span').removeClass('active'); }) var type = 1; var data = Enumerable.From([]).Where(function (x) { return x.key.endWith('_'+val)==true }).ToArray(); setSpecItem(data); break; case '变速箱': $('.spec_item').each(function(k,v){ $(v).removeClass('hide_spec'); $(v).addClass('show_spec'); }) $('[data-name=发动机]').each(function(){ $(this).children('input').prop('checked',false); $(this).children('span').removeClass('active'); }) $('[data-name=其它]').each(function(){ $(this).children('input').prop('checked',false); $(this).children('span').removeClass('active'); }) var type = 2; var data = Enumerable.From([]).Where(function (x) { return x.key.endWith('_'+val)==true }).ToArray(); setSpecItem(data); break; case '其它': $('[data-name=发动机]').each(function(){ $(this).children('input').prop('checked',false); $(this).children('span').removeClass('active'); }) $('[data-name=变速箱]').each(function(){ $(this).children('input').prop('checked',false); $(this).children('span').removeClass('active'); }) $('.spec_item').each(function(k,v){ $(v).removeClass('hide_spec'); $(v).addClass('show_spec'); }) var type = 3; var data = Enumerable.From([]).Where(function (x) { return x.key.endWith('_'+val)==true }).ToArray(); setSpecItem(data); break; } get_goods_price(type); }) } }) // 处理规格按钮的隐藏 function setSpecItem(data){ var brand_id = []; var car_id = []; var engine_id = []; var gearbox_id = []; var other_id = []; for(var i in data){ let arr = data[i]['key'].split('_'); brand_id.push(arr[0]); car_id.push(arr[1]); switch(data[i]['type']){ case '1': engine_id.push(arr[2]); break; case '2': gearbox_id.push(arr[2]); break; case '3': other_id.push(arr[2]); break; } } brand_id = Array.from(new Set(brand_id)); car_id = Array.from(new Set(car_id)); engine_id = Array.from(new Set(engine_id)); gearbox_id = Array.from(new Set(gearbox_id)); other_id = Array.from(new Set(other_id)); // $('input[name="goods_spec[品牌]"]').each(function(k,v){ // if(brand_id.indexOf($(v).val())==-1){ // $(v).parent().css('display','none'); // } // }) $('input[name="goods_spec[车型]"]').each(function(k,v){ if(car_id.indexOf($(v).val())==-1){ $(v).parent().removeClass('show_spec'); $(v).parent().addClass('hide_spec'); } }) $('input[name="goods_spec[发动机]"]').each(function(k,v){ if(engine_id.indexOf($(v).val())==-1){ $(v).parent().removeClass('show_spec'); $(v).parent().addClass('hide_spec'); } }) $('input[name="goods_spec[变速箱]"]').each(function(k,v){ if(gearbox_id.indexOf($(v).val())==-1){ $(v).parent().removeClass('show_spec'); $(v).parent().addClass('hide_spec'); } }) $('input[name="goods_spec[其它]"]').each(function(k,v){ if(other_id.indexOf($(v).val())==-1){ $(v).parent().removeClass('show_spec'); $(v).parent().addClass('hide_spec'); } }) $('.pcul').each(function(k,v){ if($(v).find('.show_spec').length==0){ $(v).css('display','none'); } }) } /*** 查询商品价格*/ var spec_content = ''; function get_goods_price(type){ // var goods_price = 0.00; // 商品起始价 var spec_goods_price = []; // 规格 对应 价格 库存表 //alert(spec_goods_price['28_100']['price']); // console.log(spec_goods_price) // 如果有属性选择项 if(spec_goods_price != null){ var goods_spec_arr = []; // var type = ''; $("input[name^='goods_spec']").each(function(){ if($(this).prop('checked')){ goods_spec_arr.push($(this).val()); // type = $(this).attr('data-type'); } }); if(goods_spec_arr.length == 3){ var spec_key = goods_spec_arr.join('_'); //排序后组合成 key $.each(spec_goods_price,function(k,v){ if(v.type==type && v.key==spec_key){ $('.pctoolfootright-head div b').css('opacity','0'); $('.pctoolfootright-head').children('div').eq(0).find('b').css('opacity','1'); if(v.content.indexOf('iframe')){ var iframe_src = $(v.content).find('iframe').attr('src'); v.content = $(v.content).find('iframe').attr('src',iframe_src); } $('.pctoolfootright-content').html(v.content); spec_content = v.content; //根据所选的规格去查询相应的配套工具 $.post('GetGongJu',{'key':spec_key,'type':v.type,'goods_id':v.goods_id},function(res){ if(res){ var html = ''; $.each(res,function(k,v){ if(k==0){ html += '
'; }else{ html += '