function ProductConfig(prodId, productConfig, productStatus) { // 初始化数据 var standards = productConfig.standards; var mainShow = productConfig.mainShow; if (mainShow == null) { var mainConfigs = []; mainShow = {}; } else { var mainConfigs = mainShow.configs; } var subShow = productConfig.subShow; var mainConfigMap={}, standardMap={}; for (var i=0; i0 && srcPrice!=srcDiscountPrice); calGroupPrice(); priceSet = false; } function showDiscount(show) { if (show) { jQuery("*#showDiscount").show(); } else { jQuery("*#showDiscount").hide(); } } // 重置sku function resetSku() { jQuery("#sku").html(srcSku); skuSet = true; } function resetAll() { setStockNum(srcStockNum); resetImage(); resetPrice(); resetSku(); } // 缓存库存 for(i=0; i"); } // 主属性数据 if (mainShow.showType=='color') { //mainUl.addClass("small_swatches"); } for(i=0; i"+ ""+config.attribute.value+""+ ""+ ""); } // 从属性数据 if (subShow != null && subShow.configs != null) { for(i=0; i'+config.attribute.value+'');; } } // 单击主属性事件 mainUl.find("label").each(function(i,o){ jQuery(o).click(function(){ var config = jQuery(o); if (config.attr("class")=="active") { resetAll(); config.removeClass("active"); return; } mainUl.find("label[class='active']").removeClass("active"); // 清除主属性选择 subUl.find("a").hide(); var mainId = config.attr("mainId"); var subConfs = mainConfigMap[mainId].subConfigs; for (var i=0; i0) { subConfig = subUl.find("label.active"); if (subConfig.length>0) { subId = subConfig.attr("subId"); changeSkuPrice(mainId, subId); } //resetAll(); } else { changeSkuPrice(mainId, subId); } }); }); //if (mainUl.find("a:visible").length == 1) { // mainUl.find("label:visible:first").click(); //} resetImage(); // 单击从属性事件 subUl.find("a").each(function(i,o){ jQuery(o).click(function(){ var config = jQuery(o); if (config.attr("class")=="choose") { setStockNum(srcStockNum); resetPrice(); //resetSku(); config.removeClass("choose"); return; } subUl.find("a[class='choose']").removeClass("choose"); // 清除从属性选择 jQuery(o).addClass("choose"); // 选择从属性 mainConfig = mainUl.find("a[class='choose']"); if (mainConfigs.length==0 || mainConfig.length>0) { if (mainConfig.length>0) { var mainId = mainConfig.attr("mainId"); } else { var mainId = 0; } var subId = jQuery(this).attr("subId"); changeSkuPrice(mainId, subId); } }); }); //if (subUl.find("a:visible").length==1) { subUl.find("a:visible:first").click(); //} function changeQuantity() { var quantity = $("#quantity").val(); if (quantity <=0 ) { quantity = 1; $("#quantity").val(quantity); } var mainId = mainUl.find(".choose").attr("mainId"); var subId = subUl.find(".choose").attr("subId"); if ((mainId == null && mainUl.find("a").length>0) || (subId == null && subUl.find("a").length>0)) { resetPrice(); return; } var standard = standardMap[mainId + "." + subId]; var discountPrice = standard.discountPrice; var price = standard.price; var discountPriceShow = standard.discountPriceShow; var priceShow = standard.priceShow; var save = standard.save wholesalePrices = standard.wholesalePrices; for (var i=0; i= startCount) { discountPrice = wholesalePrice.discountPrice; price = wholesalePrice.price; discountPriceShow = wholesalePrice.discountPriceShow; priceShow = wholesalePrice.priceShow; save = wholesalePrice.save; } } priceSet = true; jQuery("#currDiscountPrice").val(discountPrice); jQuery("#currDiscountPriceShow").html(discountPriceShow); jQuery("#currPrice").val(price); jQuery("#currPriceShow").html(priceShow); jQuery("#discount").html(standard.priceBean.discount); jQuery("#savePrice").html(standard.save); showDiscount(standard.priceBean.discount>0 && price!=discountPrice); calGroupPrice(); } // 数量改变事件 $("#quantity").change(changeQuantity); $("#quantity").next().click(function(){ var quantity = $("#quantity").val(); quantity++; $("#quantity").val(quantity); changeQuantity(); this.blur(); }); $("#quantity").prev().click(function(){ var quantity = $("#quantity").val(); quantity--; if (quantity > 0) { $("#quantity").val(quantity); changeQuantity(); } this.blur(); }); function changeSkuPrice(mainId, subId) { var standard = standardMap[mainId + "." + subId]; if (standard.length == 0) { standard = standardMap[subId + "." + mainId]; } if (standard == null) { resetPrice(); return; } var substock = standard.productStandardBean.stock; // 判断库存 setStockNum(substock); // 更新库存显示 var discountPrice = standard.discountPrice; var price = standard.price; var discountPriceShow = standard.discountPriceShow; var priceShow = standard.priceShow; var save = standard.save var quantity = $("#quantity").val(); if (quantity <=0 ) { quantity = 1; } // 价格更换 wholesalePrices = standard.wholesalePrices; for (var i=0; i= startCount) { discountPrice = wholesalePrice.discountPrice; price = wholesalePrice.price; discountPriceShow = wholesalePrice.discountPriceShow; priceShow = wholesalePrice.priceShow; save = wholesalePrice.save; } } if (discountPrice > 0) { priceSet = true; jQuery("*#currDiscountPrice").val(discountPrice); jQuery("*#currDiscountPriceShow").html(discountPriceShow); jQuery("*#currPrice").val(price); jQuery("*#currPriceShow").html(priceShow); jQuery("*#discount").html(standard.priceBean.discount); jQuery("*#savePrice").html(standard.save); showDiscount(standard.priceBean.discount>0 && price!=discountPrice); calGroupPrice(); } else { if (priceSet) { resetPrice(); } } } // 更新图片显示 function changeGroupPhoto(o) { var mainId = jQuery(o).attr("mainId"); var imgUrl = mainConfigMap[mainId].imageUrl; if (imgUrl != null && imgUrl != "") { imgUrl = imgUrl.replace(/\.[mts]\./ig, ".b."); $("#mainImg").attr("src", imgUrl); imgUrl = imgUrl.replace(/\.b\./ig, "."); $("#zoomContent img").attr("src", imgUrl); } } // 更新从属性显示 function changeSubConfig(o) { var subIds = jQuery(o).attr("subId"); if (subIds == "") { subIds = "0"; } subIds = subIds.split(","); var mainId = jQuery(o).attr("mainId"); subUl.find("li").each(function(){jQuery(this).hide()}); // 先隐藏所有,后显示私有 var stock = 0; for(i=0; i 0) { stock += substock; // 累加库存 } } setStockNum(stock); } function setStockNum(stock) { if (productStatus == null) { productStatus = 1; } if (stock > 0 && productStatus == 1) { jQuery("#addCartDiv").show(); jQuery("#outStockDiv").hide(); } else if (stock == 0) { jQuery("#addCartDiv").hide(); jQuery("#outStockDiv").show(); } jQuery("#stockNumber").html(stock); } }