bundle.page.js 2.69 KB
/**
 * Created by targaryen on 2016/11/28.
 */
var $ = require('yoho-jquery'),
    tip = require('../plugin/tip');

require('../common');

var chosePanelRender = require('../common/chose-panel'),
    chosePanel = require('./bundle/chose-pannel');

var $selectBtn = $('.select-btn'),
    $buyNowBtn = $('#bundle-buy-now'),
    actCkOpthn = {
        expires: 'Session',
        path: '/',
        domain: 'm.yohobuy.com'
    };

$(function() {
    window.setCookie('activity-info', '', actCkOpthn);
});

/**
 * 选择商品颜色等
 */
$selectBtn.on('touchend', function() {
    var self = $(this);

    $.post('/product/detail/info', {
        id: self.data('id'),
        productSkn: self.data('skn')
    }, function(data) {
        chosePanelRender(data);
        chosePanel.init(self.data('skn'));
        chosePanel.show();
    });
});

$('.goods-img').on('touchend', function() {
    var packGood = $(this).parent().find('.select-btn');

    if (window._yas && window._yas.sendCustomInfo) {
        window._yas.sendCustomInfo({
            op: 'YB_GDS_PACKAGE_GOODS_C',
            param: JSON.stringify({
                C_ID: window._ChannelVary[window.cookie('_Channel')],
                PRD_ID: window.queryString.gid,
                PACKAGE_GOODS: packGood.data('id'),
                PACKAGE_INDEX: packGood.data('index') + 1
            })
        }, true);
    }

});

/**
 * 立即购买
 */
$buyNowBtn.on('click', function() {
    var bundleGoods = [],
        bundleId = $('#activityId').val(),
        gskn = $('span[id^="gskn"]'),
        gsknSelected = false,
        yasGid = [];

    if (gskn.length < 1) {
        tip.show('非法请求!');
        return;
    }

    gskn.each(function() {
        if (!$(this).data('sku')) {
            gsknSelected = false;
            tip.show('请为套餐商品选择属性');
            return;
        }

        gsknSelected = true;

        bundleGoods.push({
            type: 'bundle',
            sku: $(this).data('sku'),
            buy_number: 1
        });

        yasGid.push($(this).data('id'));
    });

    if (window._yas && window._yas.sendCustomInfo) {
        window._yas.sendCustomInfo({
            op: 'YB_GDS_PACKAGE_BUY_NOW_C',
            param: JSON.stringify({
                C_ID: window._ChannelVary[window.cookie('_Channel')],
                PRD_ID: window.queryString.id,
                PACKAGE_GOODS: yasGid.join(',')
            })
        }, true);
    }

    if (gsknSelected) {
        window.setCookie('activity-info', JSON.stringify({
            product_sku_list: bundleGoods,
            activity_id: bundleId
        }), actCkOpthn);

        window.location.href = '/cart/index/new/orderEnsure?cartType=bundle&activityType=bundle';
    }
});