shop_coupon.js 1.25 KB
var $ = require('jquery'),
    tip = require('../plugin/tip');

var isCouponClick = true;

$(".coupon-content .receive-btn").on('touchstart', function(e) {
    var that = this,
        code = $(this).closest('.coupon-small').data('id') || '';

    if (isCouponClick === false) {
        return false;
    }

    isCouponClick = false;

    $.ajax({
        method: 'POST',
        url: '/product/index/userCoupon',
        // url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
        data: {
            couponID: code
        },
        xhrFields: {
            withCredentials: true
        },
        success: function(data) {

            isCouponClick = true;

            if (data.code === 200) {
                tip.show('领取成功');
                $(that).addClass('padding-20').html('已领取');
                $(that).unbind('touchstart');//移除绑定事件
                return true;
            } else if (data.code === 4401) {
                document.location.href = data.url;
            } else {
                tip.show(data.message);
            }
        },
        error: function() {
            tip.show('网络断开连接了~');
            isCouponClick = true;
        }
    });
});