gift-advance.js 1.15 KB
/**
 * 赠品/加价购
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/23
 */

var $ = require('jquery'),
    lazyLoad = require('yoho.lazyload'),
    tip = require('../plugin/tip'),
    loading = require('../plugin/loading'),
    chosePanel = require('./chose-panel');

var $page = $('.gift-advance-page');

lazyLoad($('.lazy'));

function getProductInfo(skn, promotionId) {
    loading.showLoadingMask();
    $.get('/cart/index/giftinfo', {
        skn: skn,
        promotionId: promotionId
    }).then(function(res) {
        if (res.code === 200) {
            chosePanel.show({
                cartInfo: res.data,
                cb: function(loc) {
                    window.location.href = loc;
                }
            });
        } else {
            tip.show(res.message);
        }
    }, function() {
        tip.show('网络错误');
    }).always(function() {
        loading.hideLoadingMask();
    });
}

$page.on('touchend', '.chose', function() {
    var $this = $(this),
        id = $this.closest('.gift-advance-good').data('id'),
        promotionId = $this.closest('.advance-block').data('promotion-id');

    getProductInfo(id, promotionId);
});