Blame view

static/js/product/shop_coupon.js 1.7 KB
郝肖肖 authored
1
var $ = require('jquery'),
郝肖肖 authored
2
    IScroll = require('iscroll/iscroll-probe'),
3
    Swiper = require('yoho.iswiper'),
郝肖肖 authored
4 5
    tip = require('../plugin/tip');
郝肖肖 authored
6
var appVersion = $('input[name="app_version"]').val();
郝肖肖 authored
7
8
$(".coupon-content .receive-btn").closest('.swiper-slide').on('click', function(e) {
郝肖肖 authored
9
    var that = this,
10
        code = $(this).data('id') || '';
郝肖肖 authored
11
郝肖肖 authored
12
    if (that.isCouponClick === false) {
郝肖肖 authored
13 14 15
        return false;
    }
郝肖肖 authored
16
    that.isCouponClick = false;
郝肖肖 authored
17 18 19

    $.ajax({
        method: 'POST',
20
        url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
郝肖肖 authored
21
        data: {
郝肖肖 authored
22 23
            couponID: code,
            app_version: appVersion
郝肖肖 authored
24 25 26 27 28 29
        },
        xhrFields: {
            withCredentials: true
        },
        success: function(data) {
郝肖肖 authored
30
            that.isCouponClick = true;
郝肖肖 authored
31 32 33

            if (data.code === 200) {
                tip.show('领取成功');
34
                $(that).find('.receive-btn').html('已领取');
郝肖肖 authored
35 36
                return true;
            } else if (data.code === 4401) {
37 38 39
                $('#shop-login').remove();
                $('body').append('<a href=\'' + data.url + '\'><span id="shop-login"><span></a>');
                $('#shop-login').click();
40 41
            } else if (data.code === 401) {
                tip.show('已领取过');
郝肖肖 authored
42 43 44 45 46 47
            } else {
                tip.show(data.message);
            }
        },
        error: function() {
            tip.show('网络断开连接了~');
郝肖肖 authored
48
            that.isCouponClick = true;
郝肖肖 authored
49 50
        }
    });
郝肖肖 authored
51 52
});
53 54 55 56 57
$(function() {
    new Swiper('.coupon-content', {
        slideElement: '.coupon-small',
        slidesPerView: 'auto',
        watchSlidesVisibility: true
郝肖肖 authored
58
    });
59
})