bundle.page.js 4.31 KB
/**
 * Created by targaryen on 2016/11/28.
 */
require('product/bundle/detail.page.css');

let $ = require('yoho-jquery'),
    tip = require('plugin/tip'),
    Swiper = require('yoho-swiper');

require('common');
let share = require('common/share');

let chosePanelRender = require('common/chose-panel'),
    chosePanel = require('cart/chose-panel');

let $selectBtn = $('.select-btn'),
    $buyNowBtn = $('#bundle-buy-now');

// cookie 参数
let actCkOpthn = {
    path: '/cart/index'
};

$(function() {
    window.setCookie('activity-info', '', actCkOpthn);
    if ($('#shareUrl').length) {
        share({
            imgUrl: $('#shareImgUrl').val(),
            title: decodeURIComponent($('#shareTitle').val()),
            link: $('#shareUrl').val(),
            desc: decodeURIComponent($('#shareSubTitle').val())
        });
    }
    if ($('.bundle-tabs').find('.swiper-slide').length > 3) {
        new Swiper('.bundle-tabs', {
            freeMode: true,
            slidesPerView: 'auto',
            lazyLoading: true
        });
    }
});

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

    $.post('/product/detail/info', {
        id: self.data('id'),
        productSkn: self.data('skn')
    }, function(data) {
        chosePanelRender(data);
        chosePanel.init();
        chosePanel.setBundleModeWithSknId(self.data('skn'));
        chosePanel.show('', (productData) => {
            var product = $('#gskn-' + productData.skn);

            product.data('sku', productData.sku);
            product.html('颜色:' + productData.color + ' 尺码:' + productData.size);
        });
    });
});

$('.goods-img').on('touchend', function() {
    let 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.productId,
                TAB_ID: window.queryString.index || 1,
                PACKAGE_GOODS: packGood.data('id'),
                PACKAGE_INDEX: packGood.data('index') + 1
            })
        }, true);
    }

});

$('.bundle-tabs').on('click', '.swiper-slide', (e) => {
    let $tab = $(e.currentTarget);

    if ($tab.hasClass('selected')) {
        return;
    }
    if (window._yas && window._yas.sendCustomInfo) {
        window._yas.sendCustomInfo({
            op: 'YB_GDS_PACKAGE_TAB_C',
            param: JSON.stringify({
                C_ID: window._ChannelVary[window.cookie('_Channel')],
                PRD_ID: window.queryString.productId,
                TAB_ID: $(e.currentTarget).data('index') + 1,
                PACKAGE_DETAIL: 2
            })
        }, true);
    }
    let href = $tab.data('href');

    window.location.href = href;
});

/**
 * 立即购买
 */
$buyNowBtn.on('touchstart', function() {
    let 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.productId,
                PACKAGE_GOODS: yasGid.join(',')
            })
        }, true);
    }

    if (gsknSelected) {
        window.setCookie('_cartType', 'bundle', actCkOpthn);
        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&productId=' + window.queryString.productId;
    }
});