detail.js 3.52 KB
/**
 *  商品详情
 * @author: liangzhifeng<zhifeng.liang@yoho.cn>
 * @date: 2015/10/20
 */
var $ = require('jquery'),
    Swiper = require('yoho.iswiper'),
    Hammer = require('yoho.hammer'),
    lazyLoad = require('yoho.lazyload');

var goodsSwiper,
    $discountFolder = $('.goodsDiscount .discount-folder'),
    $discountArrow = $('.goodsDiscount .first-item span');

var goodsDiscountEl = document.getElementById('goodsDiscount'),
    goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl),
    $discountFirstItem = $(goodsDiscountEl).find('.first-item');

var $cart = $('.cart-bar');

var limitSaleHammer = (limitSaleHammer = document.getElementById('limit-sale')) && new Hammer(limitSaleHammer);

var appUrl = $('input[name="limitCodeUrl"]').val();

var dialog = require('../../me/dialog');

//add extra marign-bottom for footer to show the yoho copyright
function showFooter() {
    var $cartBar = $('.cart-bar');

    var timer = setInterval(function() {
        if ($cartBar) {
            window.reMarginFooter('.cart-bar');
            clearInterval(timer);
        } else {
            $cartBar = $('.cart-bar');
        }
    }, 200);
}

showFooter();

require('./like');

lazyLoad($('img.lazy'));

if ($('#goodsDiscount h1').length < 1) {
    $('.dropdown').remove();
}

//顶部swiper
goodsSwiper = new Swiper('.banner-swiper', {
    lazyLoading: true,
    lazyLoadingInPrevNext: true,
    paginationClickable: true,
    pagination: '.banner-top .pagination-inner',
    nextButton: '.my-swiper-button-next',
    prevButton: '.my-swiper-button-prev',
    spaceBetween: 3
});


//初始化goods-discount
if (0 === $discountFolder.children().length) {
    $discountFolder.css('display', 'none');
    $discountArrow.html('');
}

//goods-discount下拉按钮点击事件
if (goodsDiscountHammer && $discountFolder.children().length > 0) {
    goodsDiscountHammer.on('tap', function(e) {
        if ($discountFolder.is(':hidden')) {
            $discountFirstItem.removeClass('short-text');
            $discountArrow.removeClass('icon-down').addClass('icon-up').html('&#xe608;');
            $discountFolder.slideDown();
        } else {
            $discountFirstItem.addClass('short-text');
            $discountArrow.removeClass('icon-up').addClass('icon-down').html('&#xe609;');
            $discountFolder.slideUp();
        }
    });
}

limitSaleHammer && limitSaleHammer.on('tap', function(e) {
    e.srcEvent.stopPropagation();
    dialog.showDialog({
        dialogText: '进入有货APP尖货频道分享\n以获取限购码',
        hasFooter: {
            rightBtnText: '打开Yoho!Buy有货APP'
        }
    }, function() {
        window.location.href = appUrl;
    }, undefined, true);

    $('.dialog-wrapper').off('touchstart').on('touchstart', function(e) {
        e.stopPropagation();
        if ($(e.target).hasClass('dialog-wrapper')) {
            dialog.hideDialog();
        }
    });
});

require('./desc');
require('./comments-consults');
require('../recommend-for-you-product-desc');

//购物车商品数量
$.ajax({
    type: 'GET',
    url: '/cart/index/count',
    success: function(data) {
        var count;

        if (data.code === 200) {
            count = data.data.cart_goods_count || 0;
            if (count === 0) {
                return false;
            }
            if (count > 99) {
                count = '99+';
            }
            $cart.find('.num-tag').html(count).removeClass('hide');
        }
    }
});

if ($('.good-detail-page').length > 0) {
    $('#yoho-footer').css('border-top', '1px solid #e0e0e0');
}