sale.page.js 2.49 KB
/**
 * 商品列表页
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/5/17
 */

require('product/sale/index.page.css');

let $ = require('yoho-jquery'),
    Swiper = require('yoho-swiper2'),
    ellipsis = require('yoho-mlellipsis'),
    lazyload = require('yoho-jquery-lazyload');

let search = require('./sale/search');
let defaultOpt = require('common/query-param');

require('common');

search.start();
lazyload($('img.lazy'));
ellipsis.init();

$('.swiper-container').each(function() {
    if ($(this).find('.swiper-slide').length > 1) {
        new Swiper($(this).get(0), {
            lazyLoading: true,
            lazyLoadingInPrevNext: true,
            loop: true,
            autoplay: 3000,
            autoplayDisableOnInteraction: true,
            paginationClickable: true,
            pagination: $(this).closest('.banner-top').find('.pagination-inner').get(0)
        });
    }
});

$(function() {
    let $body = $('body');
    let $saleNavSelect = $('.sale-nav-select');
    let $vipFloor = $('.vip-floor');
    let $saleNavWrap = $('.sale-nav-wrap');
    let $listNavLayer = $saleNavWrap.find('.list-nav-layer');
    let $filterMask = $('.filter-mask');

    $('.sale-nav').on('click', function() {
        $saleNavSelect.toggleClass('show');
    });

    // 读取会员专享商品
    $.ajax({
        url: '/product/sale/search',
        data: {
            yh_channel: window.queryString.channel || defaultOpt.channel || 'boys',
            saleType: '2',
            productPool: $vipFloor.data('id'),
            limit: '4'
        }
    }).then(function(res) {
        if (/good-info/.test(res)) {
            $vipFloor.html(res).addClass('goods-container');
            lazyload($vipFloor.find('img.lazy'));

            // $('.good-detail-text .name').each(function() {
            //     let $this = $(this),
            //         $title = $this.find('a');

            //     $title[0].mlellipsis(2);
            // });

            $vipFloor.css('padding-bottom', '0.75rem');
        }
    });

    // $saleNavWrap.css({
    //     height: $('.list-nav').height()
    // });

    $(window).on('scroll', function() {
        if (!$filterMask.length) {
            $filterMask = $('.filter-mask');
        }

        if ($body.scrollTop() > $saleNavWrap.offset().top) {
            $listNavLayer.addClass('fixed');
            $filterMask.addClass('fixed');
        } else {
            $listNavLayer.removeClass('fixed');
            $filterMask.removeClass('fixed');
        }
    }).trigger('scroll');
});