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

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

var $container = $('#message-main-container');
var $pickBtn = $('.pick-coupon-btn');

var pickBusy = false;

var Alert = Dialog.Alert,
    Confirm = Dialog.Confirm;

function msgOperation(data) {
    if (!data) {
        return;
    }

    $.ajax({
        type: 'GET',
        url: '/home/message/del',
        data: data
    }).then(function(jsonData) {
        if (jsonData.code === 200) {
            window.location.reload();
        } else {
            new Alert(jsonData.message);
        }
    });
}

$container.on('click', '.del-btn', function() {
    var data = $(this).data();

    if (data.id) {
        new Confirm({
            content: '您确定要删除这条短消息?',
            cb: function() {
                msgOperation(data);
            }
        }).show();
    }
});

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

    $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;

        new Alert(msg);
    });
});