list.page.js 3.88 KB
/**
 * search
 * @author: sefon 2016-7-12 15:28:22
 */

var $ = require('yoho-jquery');
var yas = require('../common/data-yas');
var lazyLoad = require('yoho-jquery-lazyload');



var product = require('./index/product');
var qs = {};

var $footPage = $('.foot-pager').data('total'),
    $productIdArr = [],
    $leftUl = $('.sort-container .sort-child-list'),
    $leftLi = $leftUl.find('li.active');

var listType = $('.path-nav').attr('listType'),
    brandId = $('.path-nav').attr('brandId');

var filterValue = yas.getFilterValue();

var commonParams = {};
var $qrcodeImg = $('#qrcode-img');

$('.good-info .product-id').each(function() {
    $productIdArr.push($(this).html());
});

require('yoho-jquery-qrcode');
require('../common');
require('../plugins/filter');
require('../plugins/sort-pager');
require('./detail/latest-walk');
require('./index/top-coupon');


// 品牌
require('./index/brand');

product.init(4);

lazyLoad($('img.lazy'), {
    failure_limit: 20
});
qs = window.queryString();
commonParams = {
    PAGE_NUM: qs.page || 1,
    FILTER_VALUE: filterValue,
    L1_SORT: $leftLi.length > 0 ? $leftLi.parent().prev().attr('title') : '',
    L2_SORT: $leftLi.find('a').attr('title') || '',
    SORT_TYPE: qs.order || 's_n_desc'
};

// 时间戳格式化
function getLocalTime(nS) {
    return new Date(parseInt(nS, 10) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
}

/*
 * 页面加载完
 */
$(function() {

    var loadYas = {
        RES_QTY: $footPage || 0,
        PRD_LIST: $productIdArr.join(',')
    };
    var opt = '';

    switch (listType) {
        case 'search':
            loadYas.KEYWORD = qs.query || '';
            opt = 'YB_KEYWORD_GOODS_LIST_L';
            break;
        case 'brand':
            loadYas.BRAND_ID = brandId;
            opt = 'YB_BRAND_GOODS_LIST_L';
            break;
        case 'new':
            loadYas.SHELF_TIME = 'ALL';
            opt = 'YB_NEW_GOODS_LIST_L';
            break;
        default:// 品类查找sort
            loadYas.CATEGORY_ID = qs.misort || qs.msort || '';
            opt = 'YB_CATEGORY_GOODS_LIST_L';
            break;
    }
    loadYas = $.extend(loadYas, commonParams);

        // 关键词搜索结果页展示时
    yas.givePoint(opt, loadYas);

});

// 点击搜索列表商品
$('.good-item-wrapper').click(function() {
    var $this = $(this),
        proId = $this.find('.product-id').html(),
        aIndex = $this.attr('activeIndex'),
        pageNum = qs.page || 1,
        limit = qs.limit || 60,
        proNum = (parseInt(pageNum, 10) - 1) * limit + parseInt(aIndex, 10),
        shelveTime = $this.find('.shelve-time').html();

    var loadYas = {
        PRD_ID: proId,
        PRD_NUM: proNum
    };

    var opt = '';

    switch (listType) {
        case 'search':
            loadYas.KEYWORD = qs.query || '';
            opt = 'YB_KEYWORD_GOODS_LIST_C';
            break;
        case 'brand':
            loadYas.BRAND_ID = brandId;
            opt = 'YB_BRAND_GOODS_LIST_C';
            break;
        case 'new':
            loadYas.SHELF_TIME = getLocalTime(shelveTime);
            opt = 'YB_NEW_GOODS_LIST_C';
            break;
        default:// 品类查找sort
            loadYas.CATEGORY_ID = qs.misort || qs.msort || '';
            opt = 'YB_CATEGORY_GOODS_LIST_C';
            break;
    }
    loadYas = $.extend(loadYas, commonParams);

    // 点击搜索列表商品埋点
    yas.givePoint(opt, loadYas);
});

// 生成二维码
$qrcodeImg.qrcode({
    render: 'div', // 显示方式,canvas,image和div
    text: $qrcodeImg.attr('data-url'), // 二维码的内容
    size: parseInt($qrcodeImg.width(), 10) // 大小
});

$('.qrcode-hover-box').mouseenter(function() {
    window._hmt.push(['_trackEvent', '二维码', '普通店铺', 'shopId', $(this).attr('data-id')]);
});

$('#code-buy').mouseenter(function() {
    window._hmt.push(['_trackEvent', '二维码', '商品', '', '']);
});

require('./good-slide');