me-gift.page.js 3.76 KB
var $ = require('yoho-jquery'),
    Hbs = require('yoho-handlebars'),
    dialog = require('../common/dialog');

var meGift;

require('../common');

meGift = {
    // 验证邮箱模板
    emailTpl: Hbs.compile($('#verify-email-tpl').html()),

    // 绑定手机模板
    mobileTpl: Hbs.compile($('#verify-mobile-tpl').html()),

    // 激活礼品卡模板
    giftTpl: Hbs.compile($('#activate-gift-tpl').html()),

    // 消费明细模板
    detailGiftTpl: Hbs.compile($('#detail-gift-tpl').html()),

    // 添加礼品卡按钮
    $addGift: $('.add-gift'),

    init: function() {
        var that = this;

        // 添加礼品卡
        this.$addGift.click(function() {
            that.verifyEmailCode();
        });

        // 消费明细
        $('.me-gift-table').on('click', '.info-list', function() {
            that.infoList();
        });
    },

    // 我的礼品卡列表
    getList: function() {

    },

    // 礼品卡详情列表
    detailList: function() {

    },

    // 获取邮箱验证码
    getEmailCode: function() {
    },

    // 效验邮箱验证码
    verifyEmailCode: function() {
        var that = this;
        var dg = new dialog.Dialog({
            content: that.emailTpl({}),
            className: 'me-gift-confirm',
            btns: [{
                id: 'confirm-email-btn',
                name: '绑定手机号',
                btnClass: ['alert-sure'],
                cb: function() {
                    dg.close();
                    that.getMobileCode();
                }
            }]
        }).show();
    },

    // 获取手机验证码
    getMobileCode: function() {
        var that = this;
        var dg = new dialog.Dialog({
            content: that.mobileTpl({}),
            className: 'me-gift-confirm',
            btns: [{
                id: 'confirm-mobile-cancel',
                name: '取消',
                btnClass: ['confirm-cancel'],
                cb: function() {
                    dg.close();
                }
            }, {
                id: 'confirm-mobile-sure',
                name: '激活',
                btnClass: ['confirm-sure'],
                cb: function() {
                    dg.close();
                    that.activateGift();
                }
            }]
        }).show();
    },

    // 效验手机验证码并激活
    verifyMobileCode: function() {

    },

    // 激活礼品卡
    activateGift: function() {
        var that = this;
        var dg = new dialog.Dialog({
            content: that.giftTpl({}),
            className: 'me-gift-confirm',
            btns: [{
                id: 'confirm-gift-cancel',
                name: '取消',
                btnClass: ['confirm-cancel'],
                cb: function() {
                    dg.close();
                }
            }, {
                id: 'confirm-gift-sure',
                name: '激活',
                btnClass: ['confirm-sure'],
                cb: function() {
                    dg.close();
                    that.meAlert('<p>您的礼品卡激活成功</p><p>请尽情享用</p>');
                }
            }]
        }).show();
    },

    // 消费明细
    infoList: function() {
        var that = this;

        new dialog.Dialog({
            content: that.detailGiftTpl({}),
            className: 'me-gift-page me-gift-confirm'
        }).show();
    },

    // 我的弹框
    meAlert: function(content) {
        var dg = new dialog.Dialog({
            content: content,
            className: 'me-gift-alert',
            btns: [{
                name: '我知道了',
                btnClass: ['btn-close', 'alert-sure'],
                cb: function() {
                    dg.close();
                }
            }]
        }).show();
    }
};

$(function() {
    meGift.init();
});