invitation.js 6.68 KB
define('admin/invitation', function(require, exports)
{
        var box = require('admin/box'); // 提示框
        var $ = require("jquery");
        var common = require("common");
        var upload = require('admin/upload');
        var form_html = $("#form_pan").html() + '';
        $("#form_pan").remove();

        $("#add_index").click(function()
        {
                box.confirm
                        (
                                form_html, submit,
                                {
                                        title: '添加' + $(".active").eq(1).children().text(),
                                        width: '770px',
                                        autoClose: false
                                }
                        );
        });

        $(".apply").click(function()
        {
                var id = $(this).attr('data-id');
                var status = $(this).attr('status');
                box.confirm((status > 0 ? "确定要取消显示在申请列表中吗?" : "确定要显示在申请列表中吗?"), function()
                {
                        $.ajax
                                ({
                                        type: "post",
                                        url: '/admin/invitation/showinapply',
                                        data: "id=" + id + '&status=' + (status > 0 ? 0 : 1),
                                        success: function(data)
                                        {
                                                if (data.code == 200)
                                                {
                                                        window.location.reload();
                                                }
                                                else
                                                {
                                                        box.alert(data.message);
                                                }
                                        }
                                });
                });
        });
        
        $(".pass").click(function()
        {
                var id = $(this).attr('data-id');
                var status = $(this).attr('status');
                box.confirm((status > 0 ? "确定要取消显示在通过列表中吗?" : "确定要显示在通过列表中吗?"), function()
                {
                        $.ajax
                                ({
                                        type: "post",
                                        url: '/admin/invitation/showinpass',
                                        data: "id=" + id + '&status=' + (status > 0 ? 0 : 1),
                                        success: function(data)
                                        {
                                                if (data.code == 200)
                                                {
                                                        window.location.reload();
                                                }
                                                else
                                                {
                                                        box.alert(data.message);
                                                }
                                        }
                                });
                });
        });
        
        //提交index
        function submit()
        {
                var type = $('#type').val();
                
                var d = $('#myTabContent > div.active');
                var category = d.find('input[name=category]').val();
                var sub = d.find('input[name$=sub]:checked').val();
                var name = d.find('input[name=name]').val();
                var contacter = d.find('input[name=contacter]').val();
                var phone = d.find('input[name=phone]').val();
                var email = d.find('input[name=email]').val();
                if (type == "")
                {
                        alert("必须选择一个类型!");
                        return;
                }
                if (/^\s*$/.test(name))
                {
                        alert("名称不能为空!");
                        return;
                }
                if (/^\s*$/.test(contacter))
                {
                        alert("联系人不能为空!");
                        return;
                }
                
                if (phone == "")
                {
                        alert("联系电话不能为空!");
                        return;
                }
                //if (!/^(\d{3,4}[-]?)?\d{7,8}(-\d{3,4})?$/.test(phone) && !/^(13|15|17)[0-9]{9}$/.test(phone))
                if (!/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/.test(phone))
                {
                        alert("联系电话格式错误!");
                        return;
                }
                
                if (email == "")
                {
                        alert("邮箱不能为空!");
                        return;
                }
                //if (!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email))
                if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
                {
                        alert("邮箱格式错误!");
                        return;
                }
                
                $.ajax
                        ({
                                type: "post",
                                url: '/admin/invitation/submit',
                                data: "type=" + type +
                                        "&category=" + category +
                                        "&sub=" + sub +
                                        "&name=" + encodeURIComponent(name) +
                                        "&contacter=" + encodeURIComponent(contacter) +
                                        "&phone=" + encodeURIComponent(phone) +
                                        "&email=" + encodeURIComponent(email),
                                success: function(data)
                                {
                                        if (data.code == 200)
                                        {
                                                window.location.reload();
                                        }
                                        else
                                        {
                                                box.alert(data.message);
                                        }
                                }
                        });
        }
});