' + o.price + ''; }); $('#price_ladder_html').empty().html(price_ladder_html); if (price_ladder.length > 3) { $('.price_ladder_more').show(); } else { $('.price_ladder_more').hide(); } $('.pre_sell_div').show(); }}//商品价格库存显示function goods_activity_theme() { $('.pre_sell_div').hide(); var goods_prom_type = $('input[name="goods_prom_type"]').attr('value'); var activity_is_on = $('input[name="activity_is_on"]').attr('value'); if (activity_is_on == 0) { setNormalGoodsPrice(); } else { if (goods_prom_type == 0 || goods_prom_type == 6) { //普通商品 setNormalGoodsPrice(); } else if (goods_prom_type == 1) { //抢购 setFlashSaleGoodsPrice(); } else if (goods_prom_type == 2) { //团购 setGroupByGoodsPrice(); } else if (goods_prom_type == 3) { //优惠促销 setPromGoodsPrice(); } else { } } var buy_num = parseInt($('#number').val()); //购买数 var store = parseInt($('input[name="store_count"]').val()); //实际库存数量 if (store <= 0) { $('.buy_button').addClass('buy_bt_disable'); } else { $('.buy_button').removeClass('buy_bt_disable'); } if (buy_num > store) { $('.buyNum').val(store); }}//普通商品库存和价格function setNormalGoodsPrice() { var goods_price, store_count; //商品价,商品库存 var market_price = $("input[name='market_price']").attr('value'); // 商品市场价 var exchange_integral = $("input[name='exchange_integral']").attr('value'); // 兑换积分 var point_rate = $("input[name='point_rate']").attr('value'); // 积分金额比 // 如果有属性选择项 if (!$.isEmptyObject(spec_goods_price)) { var goods_spec_arr = []; $("input[name^='goods_spec']").each(function () { if ($(this).attr('checked') == 'checked') { goods_spec_arr.push($(this).val()); } }); var spec_key = goods_spec_arr.sort(sortNumber).join('_'); //排序后组合成 key goods_price = spec_goods_price[spec_key]['price']; // 找到对应规格的价格 store_count = spec_goods_price[spec_key]['store_count']; // 找到对应规格的库存 market_price = spec_goods_price[spec_key]['market_price']; // 找到对应规格的市场价 $("input[name='shop_price']").attr('value', goods_price); $("input[name='store_count']").attr('value', store_count); $("input[name='market_price']").attr('value', market_price); } else { priceLadderShow(); } goods_price = $("input[name='shop_price']").attr('value'); // 商品本店价 store_count = $("input[name='store_count']").attr('value'); // 商品库存 $('#market_price_title').empty().html('市场价:'); $('#market_price').empty().html(market_price); $("#goods_price").html("¥" + goods_price); //变动价格显示 var integral = round(goods_price - (exchange_integral / point_rate), 2); $("#integral").html(integral + '+' + exchange_integral + '积分'); //积分显示 $('#spec_store_count').html(store_count); $('.presale-time').hide(); $('#number').attr('max', store_count);}//秒杀商品库存和价格function setFlashSaleGoodsPrice() { var flash_sale_price = $("input[name='shop_price']").attr('value'); var flash_sale_count = $("input[name='store_count']").attr('value'); var market_price = $("input[name='market_price']").attr('value'); var start_time = $("input[name='start_time']").attr('value'); var end_time = $("input[name='end_time']").attr('value'); var activity_title = $("input[name='activity_title']").attr('value'); $("#goods_price").html("¥" + flash_sale_price); //变动价格显示 $('#spec_store_count').html(flash_sale_count); $('#goods_price_title').html('抢购价:'); $('#market_price_title').empty().html('原 价:'); $('#activity_label').empty().html('抢 购:'); $('#activity_title').empty().html(activity_title); $('#activity_title_div').show(); $('#market_price').empty().html(market_price); $('.presale-time').show(); $('#prom_detail').hide(); $('#number').attr('max', flash_sale_count); setInterval(activityTime, 1000);}//团购商品库存和价格function setGroupByGoodsPrice() { var group_by_price = $("input[name='shop_price']").attr('value'); var group_by_count = $("input[name='store_count']").attr('value'); var market_price = $("input[name='market_price']").attr('value'); var start_time = $("input[name='start_time']").attr('value'); var end_time = $("input[name='end_time']").attr('value'); var activity_title = $("input[name='activity_title']").attr('value'); $("#goods_price").empty().html("¥" + group_by_price); //变动价格显示 $('#spec_store_count').empty().html(group_by_count); $('#activity_type').empty().html('团购'); $('#goods_price_title').empty().html('团购价:'); $('#market_price_title').empty().html('原 价:'); $('#activity_label').empty().html('团 购:'); $('#activity_title').empty().html(activity_title); $('#activity_title_div').show(); $('#market_price').empty().html(market_price); $('.presale-time').show(); $('#prom_detail').hide(); $('#number').attr('max', group_by_count); setInterval(activityTime, 1000);}//促销商品库存和价格function setPromGoodsPrice() { var prom_goods_price = $("input[name='shop_price']").attr('value'); var prom_goods_count = $("input[name='store_count']").attr('value'); var market_price = $("input[name='market_price']").attr('value'); var start_time = $("input[name='start_time']").attr('value'); var end_time = $("input[name='end_time']").attr('value'); var activity_title = $("input[name='activity_title']").attr('value'); var prom_detail = $("input[name='prom_detail']").attr('value'); $("#goods_price").empty().html("¥" + prom_goods_price); //变动价格显示 $('#spec_store_count').empty().html(prom_goods_count); $('#activity_type').empty().html('促销'); $('.presale-time').show(); $('#prom_detail').empty().html(prom_detail).show(); $('#activity_time').hide(); $('#goods_price_title').empty().html('促销价:'); $('#market_price_title').empty().html('原 价:'); $('#activity_label').empty().html('促 销:'); $('#activity_title').empty().html(activity_title); $('#activity_title_div').show(); $('#market_price').empty().html(market_price); $('#number').attr('max', prom_goods_count);}// 倒计时function activityTime() { var end_time = parseInt($("input[name='end_time']").attr('value')); var timestamp = Date.parse(new Date()); var now = timestamp / 1000; var end_time_date = formatDate(end_time * 1000); var text = GetRTime(end_time_date); //活动时间到了就刷新页面重新载入 if (now > end_time) { layer.msg('该商品活动已结束', function () { location.reload(); }); } $("#overTime").text(text);}//时间戳转换function add0(m) { return m < 10 ? '0' + m : m}//时间戳转换字符function formatDate(now) { var time = new Date(now); var y = time.getFullYear(); var m = time.getMonth() + 1; var d = time.getDate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); return y + '/' + add0(m) + '/' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);}//sort排序用function sortNumber(a, b) { return a - b;}//收藏商品$('#collectLink').click(function () { if (getCookie('user_id') == '') { layer.msg('请先登录!', { icon: 1 }); } else { var goods_arr = new Array(); //单个收藏 goods_arr.push($('input[name="goods_id"]').val()); $.ajax({ type: 'post', dataType: 'json', data: { goods_ids: goods_arr }, url: "/Home/Goods/collect_goods.html", success: function (res) { if (res.status == 1) { layer.msg(res.msg, { icon: 1 }); } else { layer.msg(res.msg, { icon: 3 }); } } }); }});//点击切换规格$(document).on('click', '.spec_item', function () { var spec_item_img_src = $(this).find('img').attr('src'); if (spec_item_img_src != '') { $('#zoomimg').attr('jqimg', spec_item_img_src).attr('src', spec_item_img_src); } $(this).addClass('red').siblings('a').removeClass('red'); $(this).siblings('input').removeAttr('checked'); $(this).prev('input').attr('checked', 'checked').prop('checked', 'checked'); if ($('#video').length > 0) { //判断是否有视频标签 $('#photoBody').addClass('picshow-ac'); video.pause(); } // 更新商品价格 initGoodsPrice(); //获取搭配购列表 getCombination();})