data-yas.js 2.35 KB
/**
 * Created by DELL on 2016.11.9.
 */
var $ = require('yoho-jquery');

function getCookie(name) {
    var arr, reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');

    if (arr === document.cookie.match(reg)) {
        return unescape(arr[2]);
    } else {
        return null;
    }
}

// 频道、性别、品类、折扣、人群、颜色、尺码、分类
function _getCommonFilterValue() {
    var $section = $('.channel, .sort, .discount, .misort, .color, .size');
    var $attrchecked = $section.find('.attr-content .attr.checked');
    var filterValue = '';

    $attrchecked.each(function() {
        var $this = $(this);
        var key = $this.parents('.attr-content').prev().html(),
            name = $this.attr('name');

        filterValue += key + name + ';';
    });

    return filterValue;
}

// 价格、品牌、高级筛选
function _getOtherFilterValue() {
    var filterValue = '';

    $('.checked-conditions .attr-content .tag').each(function() {
        var type = $(this).attr('itemType'),
            name = $(this).attr('name');

        switch (type) {
            case 'brands':
                type = '品牌';
                break;
            case 'price':
                type = '价格';
                break;
            default:
                break;
        }
        filterValue += type + ':' + name + ';';
    });

    return filterValue;
}

/** *埋点方法***/
function givePoint(op, parameter) {
    var CID = 1;

    if (!window._yas || !window._yas.sendCustomInfo) {
        return false;
    }

    if (!getCookie('_Channel')) {
        // 男:1,女:2,潮童:3,创意生活:4
        switch (getCookie('_Channel')) {
            case 'boys':
                CID = 1;
                break;
            case 'girls':
                CID = 2;
                break;
            case 'kids':
                CID = 3;
                break;
            case 'lifestyle':
                CID = 4;
                break;
            default:
                CID = 1;
        }
    }

    parameter = $.extend({
        C_ID: CID
    }, parameter);

    console.info(parameter);
    window._yas.sendCustomInfo({
        op: op,
        param: JSON.stringify(parameter)
    }, true);
}

function getFilterValue() {
    return _getCommonFilterValue() + _getOtherFilterValue();
}


exports.givePoint = givePoint;
exports.getFilterValue = getFilterValue;