message-content.js 1.02 KB
/**
 * 我的信息
 * @author: yyqing<yanqing.yang@yoho.cn>
 * @date: 2016/3/25
 */
var $ = require('yoho.jquery');

var Alert = require('../common/dialog').Alert;

var $pickBtn = $('.pick-coupon-btn');

var pickBusy = false;

$('.show-birth-coupon').click(function() {
    var $this = $(this);
    var msg = $this.data('msg');

    if (msg) {
        new Alert(msg).show();
        return;
    }

    $this.siblings('.birth-coupon-wrap').show();
    $this.hide().siblings('p').hide();
    $(window).scrollTop(0);
});

$pickBtn.click(function() {
    var data = $(this).data();

    if (pickBusy) {
        return;
    }
    pickBusy = true;
    $.ajax({
        type: 'GET',
        url: '/home/message/pickCoupon',
        data: data
    }).then(function(jsonData) {
        var msg = jsonData.message;

        if (jsonData.code === 200) {
            msg = '领取成功';
            $(this).removeClass('pick-coupon-btn');
        }

        pickBusy = false;

        alert(msg);
    });
});