cart.page.js 5.37 KB
/**
 * 订单结算页
 * @author: gxh<xuhui.ge@yoho.cn>
 * @date: 2016/12/27
 */

var $ = require('yoho-jquery');

var lazyLoad = require('yoho-jquery-lazyload');
var Dialog = require('../common/dialog').Dialog;
var Alert = Dialog.Alert;
var $cartGoodsDetail = $('#goodsTogetherDetail'),
    pacList = 0,
    shopNum = 1,
    promotionId,
    shopNumAll;

// 优惠券 显示和隐藏
$('.sale-info').mouseenter(function() {
    $(this).addClass('active').children('ul').removeClass('none');
}).mouseleave(function() {
    $(this).removeClass('active').children('ul').addClass('none');
});

// 推荐、优选、浏览切换
$('.bottom-tab-slide').on('click', '.bottom-title', function() {
    var $this = $(this),
        index = $this.index();
    console.log(index);
    var $togetherGoods = $('.individual-item-togetherGoods'),
        $latestWalk = $('.individual-item-latestWalk'),
        $recommendGoods = $('.individual-item-recommendGoods');

    if ($this.hasClass('cur')) {
        return;
    }

    $this.addClass('cur');
    $this.siblings('.cur').removeClass('cur');

    switch (index) {
        case 0: {

            $togetherGoods.removeClass('none');
            $recommendGoods.addClass('none');
            $latestWalk.addClass('none');
            break;
        }
        case 1: {
            $togetherGoods.addClass('none');
            $recommendGoods.removeClass('none');
            $latestWalk.addClass('none');
            break;
        }
        case 2: {
            $togetherGoods.addClass('none');
            $recommendGoods.addClass('none');
            $latestWalk.removeClass('none');
            break;
        }

    }

});


// 凑单图片懒加载
var togetherDialog = {};
var dialogTpl = require('hbs/cart/cart-togetherGoods.hbs');

lazyLoad($('#details-html img'));

$('.shop-cart').on('click', '.gift-sell .btn-clear', function() {

    var tid = $(this).attr('data-together-id');
    showTogetherGoods(tid);

});

// 凑单
function showTogetherGoods(id) {

    if (!id) {
        return;
    }

    var dialog = togetherDialog[id];
    if (!dialog) {
        dialog = new Dialog({
            content: dialogTpl(),
            className: 'cart-togetherGoods'
        });

        togetherDialog[id] = dialog;
    }

    dialog.show();

}

// 凑单弹框 详情切换
$('body').on('click', '.piclist li', function() {
    console.log(99999);
    pacList = $(this).index();
    $('.detail-bigpic:not(.none) .piclist li').removeClass('active');
    $(this).addClass('active');
    $('.detail-bigpic:not(.none) .bigpic').hide().eq($(this).index()).show();
});

$('body').on('click', '.pre, .next', function() {
    if ($(this).hasClass('next')) {
        if (pacList >= $(this).siblings('.con').find('li').length - 1) {
            return false;
        }
        pacList++;
    } else {
        if (pacList < 1) {
            return false;
        }
        pacList--;
    }
    $(this).siblings('.con').find('li').removeClass('active').eq(pacList).addClass('active');
    $('.detail-bigpic:not(.none) .bigpic').hide().eq(pacList).show();
});
$('body').on('click', '.color', function() {
    pacList = 0;
    $('.color').find('p').removeClass('active');
    $(this).find('p').addClass('active');
    $('.showSizeBox').addClass('none').eq($(this).index()).removeClass('none');
    if ($('.showSizeBox:not(.none) span').length < 2) {
        $('.showSizeBox:not(.none) span:first').addClass('active');
    }
    $('.detail-bigpic').addClass('none').eq($(this).index()).removeClass('none');
    $('.detail-bigpic').eq($(this).index()).find('.bigpic').hide();
    $('.detail-bigpic').eq($(this).index()).find('.bigpic:first').show();
    $('.detail-bigpic').eq($(this).index()).find('.con li').removeClass('active');
    $('.detail-bigpic').eq($(this).index()).find('.con li:first').addClass('active');
    $('.showSizeBox').eq($(this).index()).find('span').each(function() {
        if ($(this).hasClass('null-atcivec')) {
            $('.addcart').addClass('none');
            $('.btn_sellout').removeClass('none');
        } else {
            $('.addcart').removeClass('none');
            $('.btn_sellout').addClass('none');
            return false;
        }
    });
});

$('body').on('click', '.showSizeBox span', function() {
    shopNumAll = $(this).data('num');
    if ($(this).data('num') > 0) {
        $('.showSizeBox:not(.none) span').removeClass('atcivec atcive').eq($(this).index()).addClass('active');
        $('.addcart').removeClass('none');
        $('.btn_sellout').addClass('none');
    } else {
        $('.showSizeBox:not(.none) span').removeClass('atcivec atcive').eq($(this).index()).addClass('active');
        $('.addcart').addClass('none');
        $('.btn_sellout').removeClass('none');
    }
});

$('body').on('click', '.cut, .add', function() {
    count = $(this).hasClass('minus') ? 'decreaseNum' : 'increaseNum';
    if (promotionId) {
        if ($(this).hasClass('cut')) {
            new Alert('-_-,已经是最后一件,不能再减了!').show();
        } else {
            new Alert('最多只能购买一件,您好像购买的太多了!').show();
        }
    } else {
        if ($(this).hasClass('add')) {
            shopNum++;
        } else {
            shopNum--;
        }
        if (shopNum < 1) {
            new Alert('-_-,已经是最后一件,不能在减了!').show();
            shopNum = 1;
            return false;
        }

        $('#num').val(shopNum);
    }

});