index.page.js 2.04 KB
/**
 * 个人中心首页
 * @author: bikai<kai.bi@yoho.cn>
 * @date: 2015/11/12
 */
let $ = require('yoho-jquery'),
    noticeScroll = require('plugin/notice-scroll');

let $userAvatar = $('.user-avatar'),
    $listItem = $('.list-item');

let myImage = new Image(),
    avatar;

let Swiper = require('yoho-swiper2');

require('home/index.page.css');

require('common');
if ($('.recommend-for-you').length) {
    require('./recommend-for-you-user-center');
}
require('common/suspend-cart');
require('common/footer');

if ($('.banner-center-swiper').length > 0) {
    new Swiper('.banner-center-swiper', {
        pagination: '.swiper-pagination',
        lazyLoading: true,
        lazyLoadingInPrevNext: true,
        paginationClickable: true,
        autoplay: 3000
    });
}

window.reMarginFooter('.footer-tab');

// 部分老用户没有头像,显示默认头像
avatar = $userAvatar.data('avatar');
if (avatar) {
    myImage.src = avatar;
    myImage.onload = function() {
        $userAvatar.css('background-image', 'url(' + avatar + ')');
    };
}

noticeScroll('.notice', $('.notice').data('time') * 1000);

$('.yoho-page').on('touchstart', '.list-item, .type-item, .order-title', function() {
    $listItem.removeClass('highlight');
    $(this).addClass('highlight');
}).on('touchend touchcancel', '.list-item, .type-item, .order-title', function() {
    $(this).removeClass('highlight');
});

// 埋点
$('.res-c').on('click', 'a', function() {
    let $this = $(this);
    let index = $this.index() + 1;
    let pIndex = $this.parent('div').index() + 1;
    let url = $this.attr('href');
    let name = $this.attr('name');
    let id = $this.attr('id');
    let status = $this.parent('li').hasClass('swiper-slide');

    if (status) {
        index = $this.parent('li').index() + 1;
        pIndex = 1;
    }

    if (window._yas && window._yas.sendCustomInfo) {
        window._yas.sendCustomInfo({
            I_INDEX: index,
            F_URL: encodeURIComponent(url),
            F_NAME: name,
            F_INDEX: pIndex,
            F_ID: id
        }, true);
    }
});