good-slide.js 1.53 KB
/**
 * 你可能喜欢
 * @author: gxh<xuhui.ge@yoho.cn>
 * @date: 2017/03/03
 */

'use strict';
var lazyLoad = require('yoho-jquery-lazyload');
var dataLazyLoad = require('../plugins/lazy-load')(document);
var $ = require('yoho-jquery');
var recommendTpl = require('hbs/product/good-slide.hbs');
var $recommendSlide = $('[data-role="recommend-slide"]');

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

function getSearchRecommend() {

    $.ajax({
        url: 'http://search.yohobuy.com/product/search/less/recommend',
        dataType: 'json',
        success: function(data) {

            var res;

            if (data.code === 200) {
                res = data.data.item;

                // 若无最近浏览,请隐藏容器
                if (res === null) {
                    $('.bottom-tab-line').hide();
                    $('[data-role="recommend-slide"]').closest('.goods-slide').hide();
                    return;
                }

                $recommendSlide.html(recommendTpl({
                    item: res,
                    hasNext: res && res.length > 5,
                    hasPrev: res && res.length > 5
                }));
                lazyLoad($recommendSlide.find('.lazy'));

                $recommendSlide.find('.goods-slide-item').slider2({
                    shownum: 5,
                    isCircle: true
                });
            }
        }

    });
}

window.getSearchRecommend = getSearchRecommend;

// 数据懒加载
dataLazyLoad.init({cls: '.lazy-load-object-2', threshold: 700});