Blame view

public/js/product/sale.page.js 2.55 KB
王水玲 authored
1 2 3 4 5 6
/**
 * 商品列表页
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/5/17
 */
7
require('product/sale/index.page.css');
徐炜 authored
8
陈峰 authored
9
let $ = require('yoho-jquery'),
徐炜 authored
10
    Swiper = require('yoho-swiper2'),
ccbikai authored
11
    ellipsis = require('yoho-mlellipsis'),
ccbikai authored
12
    fastclick = require('yoho-fastclick'),
ccbikai authored
13
    lazyload = require('yoho-jquery-lazyload');
王水玲 authored
14
陈峰 authored
15 16
let search = require('./sale/search');
let defaultOpt = require('../common/query-param');
biao authored
17
王水玲 authored
18
require('../common');
biao authored
19 20

search.start();
ccbikai authored
21
lazyload($('img.lazy'));
ccbikai authored
22
ellipsis.init();
王水玲 authored
23
ccbikai authored
24 25 26 27 28 29 30 31 32 33 34 35 36
$('.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)
        });
    }
});
ccbikai authored
37 38

$(function() {
ccbikai authored
39
    var $body = $('body');
ccbikai authored
40
    var $saleNavSelect = $('.sale-nav-select');
ccbikai authored
41
    var $vipFloor = $('.vip-floor');
ccbikai authored
42
    var $saleNavWrap = $('.sale-nav-wrap');
43
    var $listNavLayer = $saleNavWrap.find('.list-nav-layer');
ccbikai authored
44
    var $filterMask = $('.filter-mask');
ccbikai authored
45
ccbikai authored
46 47
    fastclick.attach(document.body);
ccbikai authored
48
    $('.sale-nav').on('click', function() {
ccbikai authored
49
        $saleNavSelect.toggleClass('show');
ccbikai authored
50
    });
ccbikai authored
51 52 53 54 55

    // 读取会员专享商品
    $.ajax({
        url: '/product/sale/search',
        data: {
56
            yh_channel: window.queryString.channel || defaultOpt.channel || 'boys',
ccbikai authored
57
            saleType: '2',
ccbikai authored
58
            productPool: $vipFloor.data('id'),
ccbikai authored
59 60 61 62 63 64
            limit: '4'
        }
    }).then(function(res) {
        if (/good-info/.test(res)) {
            $vipFloor.html(res).addClass('goods-container');
            lazyload($vipFloor.find('img.lazy'));
ccbikai authored
65 66 67 68 69 70 71

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

                $title[0].mlellipsis(2);
            });
ccbikai authored
72 73

            $vipFloor.css('padding-bottom', '0.75rem');
ccbikai authored
74 75
        }
    });
ccbikai authored
76 77 78 79

    $saleNavWrap.css({
        height: $saleNavWrap.height()
    });
ccbikai authored
80
ccbikai authored
81
    $(window).on('scroll', function() {
ccbikai authored
82 83 84 85
        if (!$filterMask.length) {
            $filterMask = $('.filter-mask');
        }
ccbikai authored
86
        if ($body.scrollTop() > $saleNavWrap.offset().top) {
87
            $listNavLayer.addClass('fixed');
ccbikai authored
88
            $filterMask.addClass('fixed');
ccbikai authored
89
        } else {
90
            $listNavLayer.removeClass('fixed');
ccbikai authored
91
            $filterMask.removeClass('fixed');
ccbikai authored
92 93
        }
    }).trigger('scroll');
ccbikai authored
94
});