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

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

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

require('../common');

lazyLoad($('.lazy'));
ellipsis.init();

function getProductInfo(skn, promotionId) {
    loading.showLoadingMask();
    $.get('/cart/index/giftinfo', {
        skn: skn,
        promotionId: promotionId
    }).then(function(html) {
        if (!html) {
            tip.show('网络错误');
            return;
        }
        chosePanel.show(html, function() {
            window.location.href = '/cart/index/index?cartType=' + queryString.cartType;
        });
    }, function() {
        tip.show('网络错误');
    }).always(function() {
        loading.hideLoadingMask();
    });
}

$page.find('.chose').each(function(i, elem) {
    var choseHammer = new Hammer(elem);

    choseHammer.on('tap', function(e) {
        var $this = $(e.target),
            id = $this.closest('.gift-advance-good').data('id'),
            promotionId = $this.closest('.advance-block').data('promotion-id');

        getProductInfo(id, promotionId);
    });
});

setTimeout(function() {
    $('.gift-advance-good .name').each(function() {
        this.mlellipsis(2);
    });
}, 0);