Blame view

public/js/product/detail/recommend-for-you-product-desc.js 2.38 KB
1 2 3 4 5 6 7
/**
 * 为您优选
 * @author: liangzhifeng<zhifeng.liang@yoho.cn>
 * @date: 2015/11/16
 */

lijing authored
8
let lazyLoad = require('yoho-jquery-lazyload'),
zhangxiaoru authored
9
    $ = require('yoho-jquery');
10
lijing authored
11
let $recommendForYou = $('.recommend-for-you'),
12 13 14 15 16
    preferenceUrl = $('#preferenceUrl').val(),
    winH = $(window).height(),
    end = false,
    requesting = false;
lijing authored
17
let RECID = (new Date().getTime() + '_H5_YOHOBUY_' + Math.floor(Math.random() * 1000000 + 1000000) +
zhangxiaoru authored
18 19
    '_' + Math.floor(Math.random() * 1000000 + 1000000));
lijing authored
20
let goodid,
沈志敏 authored
21
    goodIds = [],
沈志敏 authored
22
    prdLoad;
zhangxiaoru authored
23
24 25 26 27 28 29 30 31
function request() {
    if (requesting || end) {
        return;
    }

    requesting = true;

    if (preferenceUrl) {
郭成尧 authored
32
        $.get(preferenceUrl, {yhChannel: window.cookie('_Channel') || 'boys'}).then(function(html) {
郭成尧 authored
33 34 35
            if (typeof html !== 'string') {
                return;
            }
沈志敏 authored
36
沈志敏 authored
37
            $recommendForYou.html(html.replace(/https?:/gi, '')).show();
郭成尧 authored
38
            lazyLoad($recommendForYou.find('img.lazy'));
zhangxiaoru authored
39
zhangxiaoru authored
40
            // 为你优选埋点- 加载
41
            $('.new-goods.container').find('.good-info').each(function() {
zhangxiaoru authored
42 43 44 45 46
                goodid = $(this).data('good-id');

                if (goodid) {
                    goodIds.push(goodid);
                }
zhangxiaoru authored
47
            });
zhangxiaoru authored
48 49 50

            prdLoad = JSON.stringify(goodIds).replace(/\[|\]|/g, '');
沈志敏 authored
51 52 53 54 55 56 57 58
            window.givePoint({
                REC_POSE: 100013,
                REC_ID: RECID,
                PRD_ID: prdLoad,
                PRD_NUM: goodIds.length,
                ACTION_ID: 0,
                PAGE_NUM: 1
            });
zhangxiaoru authored
59
zhangxiaoru authored
60
            // 点击商品
zhangxiaoru authored
61
            $('.good-info').on('click', function() {
lijing authored
62
                let PRD_ID = $(this).data('good-id'),
zhangxiaoru authored
63 64
                    PRD_NUM = $(this).index();
沈志敏 authored
65 66 67 68 69 70 71 72
                window.givePoint({
                    REC_POSE: 100013,
                    REC_ID: RECID,
                    PRD_ID: PRD_ID,
                    PRD_NUM: PRD_NUM,
                    ACTION_ID: 1,
                    PAGE_NUM: 1
                });
zhangxiaoru authored
73
zhangxiaoru authored
74
                // return false;
zhangxiaoru authored
75 76
            });
77 78
            window.rePosFooter && window.rePosFooter();
79 80 81 82 83 84 85 86 87 88 89 90 91 92
        }).fail(function() {
            $recommendForYou.hide();
        });
    }
}

function scrollHandler() {
    if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) {
        request();
    }
}

$(window).scroll(function() {
    window.requestAnimationFrame(scrollHandler);
沈志敏 authored
93
});