sale.page.js 1.18 KB
var $ = require('yoho-jquery'),
    $saleBox = $('.sale-box'),
    $navItem = $('.sale-nav li'),
    lazyLoad = require('yoho-jquery-lazyload');
var product = require('./product');

require('./sale/banner');
require('../common/slider');
require('../common/filter');
require('../common/sort-pager');

product.init(4);

lazyLoad($('img.lazy'));
$('.slide-container').slider();

// 请求带导航的列表数据
function getNaviData(items) {
    var location, url, goodItems, navTitle;

    navTitle = items.attr('urlLocation');

    location = 'http://localhost:6002/product/sale/goods';

    goodItems = items.parent().parent('.sale-box').find('.goods');

    url = location + navTitle;
    $.ajax({
        type: 'GET',
        url: url,
        data: ''
    }).then(function(res) {

        goodItems.html('');
        goodItems.append(res);
        lazyLoad($('img.lazy'));
    });
}

$navItem.on('click', function() {
    $(this).siblings('.active').removeClass('active');
    $(this).addClass('active');

    getNaviData($(this));

});


//  初始化页面数据
(function() {

    $saleBox.each(function() {
        var item = $(this).find($navItem).eq(0);

        getNaviData(item);
    });
}());