collocation.page.js 2.33 KB
/**
 * 星潮教室-星搭配分页加载
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/4/12
 */

let $ = require('yoho-jquery'),
    tip = require('js/plugin/tip'),
    loading = require('js/plugin/loading'),
    lazyLoad = require('yoho-jquery-lazyload');
let stopLoading = false,
    page = 1;

require('./list-common');

function massageAJAX(pageData) {
    loading.showLoadingMask();
    $.ajax({
        type: 'GET',
        url: '/guang/star/collocation/list',
        data: {
            page: pageData,
            appVersion: window.queryString.app_version
        },
        dataType: 'html',
        success: function(data) {
            stopLoading = false;

            if (data === '') {
                stopLoading = true;
                tip.show('没有更多内容了');
            }

            $('.collocation-list').append(data);

            loading.hideLoadingMask();
            lazyLoad($('img.lazy'));

            if (pageData === 1) {
                $('.buriedpoint').on('click', bpClickHdl); // eslint-disable-line
            }
        },
        error: function() {
            tip.show('网络断开连接了~');
        }
    });
}

function scrollHandler() {
    if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() * 0.75)) {
        stopLoading = true;
        page++;
        massageAJAX(page);
    }
}

$(window).scroll(function() {
    window.requestAnimationFrame(scrollHandler);
});

if ($('.collocation-list').find('li').length === 0) {
    massageAJAX(1);
}

// app埋点
let C_ID = window._ChannelVary[window.cookie('_Channel')];
let bpClickHdl = function() {
    if (!window._yas || !window._yas.sendAppLogs) {
        return;
    }

    let $this = $(this);

    window._yas.sendAppLogs({
        appop: 'YB_H5_STROLL_STAR_FLR_C',
        param: JSON.stringify({
            C_ID: C_ID,
            TAB_INDEX: 2,
            TAB_NAME: '星搭配',
            CONTENT_INDEX: $this.index() + 1,
            CONTENT_ID: $this.attr('articleId')
        })
    }, true);
};

setTimeout(function() {
    if (!window._yas || !window._yas.sendAppLogs) {
        return;
    }
    window._yas.sendAppLogs({
        appop: 'YB_H5_STROLL_STAR_TAB_C',
        param: JSON.stringify({
            C_ID: C_ID,
            TAB_INDEX: 2,
            TAB_NAME: '星搭配'
        })
    }, true);
}, 500);