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

var $ = require('yoho-jquery'),
    lazyLoad = require('yoho-jquery-lazyload'),
    dialog = require('../common/dialog'),
    $sellBox = $('.cart-table .pre-sell-box');

require('../plugins/slider');
require('../common/center-slider');
require('../common');

$('.side-img-dd').slider2({
    shownum: 5,
    isCircle: true
});

// var dialogTpl = require('hbs/cart/cart-togetherGoods.hbs');

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

function isCheckAll() {

    var isAllCheck = true;
    $('[data-role=pitem] [data-role=cart-item-check]').each(function() {

        // 有一个没选中,跳出循环
        if (!$(this).hasClass('cart-item-checked')) {
            isAllCheck = false;
            return false;
        }
    });

    if (isAllCheck) {
        // 头部全选
        $('.cart-title .cart-item-check').addClass('cart-item-checked');

        // 底部全选
        $('#cbSelAllGoods').addClass('cart-item-checked');
    }
}

// 判断商品是否已收藏,是否全选
function isCheckFav() {
    var pidArray = [];

    $sellBox.each(function() {
        pidArray.push($(this).data('pid'));
    });

    $.ajax({
        type: 'POST',
        url: '/newcart/index/checkFav',
        data: {
            pidList: pidArray.join(',')
        }
    }).done(function(result) {
        $.each(result.data, function(pid, obj) {

            if (obj.code !== 200) {
                return false;
            }

            if (obj.data) {
                $sellBox.each(function() {
                    if (String($(this).data('pid')) === String(pid)) {
                        $(this).find('.cart-col-btn').addClass('has-col-btn').html('已收藏');
                        return false;
                    }
                });
            }

        });
    });
}


$(function() {
    $('.bottom-tab .change').click(function() {
        $('.img-brand-switch .next').trigger('click');
    });

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


    isCheckAll();
    isCheckFav();
});

require('./cart-action');
require('./cart-color-panel');
require('./cart-goods-win');
require('./cart-together');