//自定义tools类下各种方法
$.tools = {
    //消息提示
    alert: function (msg) {
        $.messager.show({
            title: lang.Prompt,
            msg: msg,
            showType: 'show'
        });
    },
    //格式化日期
    formatDate: function (val, row) {
        if (val == null) return null;
        return eval("new " + val.substr(1, val.length - 2)).format("yyyy-MM-dd");
    },
    //格式化日期时间
    formatDateTime: function (val, row) {
        if (val == null) return null;
        return eval("new " + val.substr(1, val.length - 2)).format("yyyy-MM-dd hh:mm:ss");
    },
    //格式化日期（日期已到期或即将一个月后到期显示红色）
    formatDateExpire: function (val, row) {
        if (val == null) return null;
        var now = new Date();
        var nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate()).format("yyyy-MM-dd");
        var date = eval("new " + val.substr(1, val.length - 2)).format("yyyy-MM-dd");
        if (nextMonth > date) {
            date = "<font style='color:red'>" + date + "</font>";
        }
        else {
            date = "<font style='color:black'>" + date + "</font>";
        }
        return date;
    },
    //noalert：是否需要提示，默认提示
    ajaxRun: function (params, url, callback, scope, type, noalert) {
        $.ajax({
            type: type,
            url: url,
            data: params,
            success: function (result) {
                if (result.IsSuccess) {
                    if (noalert == true && callback != undefined) {
                        callback.call(scope, result);
                        return;
                    }
                    var msg = lang.OperationSuccessful;
                    if (result.Message != undefined && result.result != "") {
                        msg = result.Message;
                    }
                    $.tools.alert(msg);
                    if (callback != undefined) {
                        callback.call(scope, result);
                    }
                }
                else {
                    //$.tools.alert(result.Message);
                    $.messager.alert(lang.Prompt, result.Message, "warning");
                }
            },
            error: function () {
                //$.tools.alert(lang.OperationFailed);
                $.messager.alert(lang.Prompt, lang.OperationFailed, "warning");
            }
        });
    },
    //ajax post方式
    post: function (params, url, callback, scope, noalert) {
        this.ajaxRun(params, url, callback, scope, "POST", noalert)
    },
    //删除ajax post
    delPost: function (params, url, callback, scope) {
        this.confrimPost(lang.AYSYWTDTSD, params, url, callback, scope);
    },
    //确认提示ajax post
    confrimPost: function (msg, params, url, callback, scope) {
        $.messager.confirm(lang.Prompt, msg, function (r) {
            if (r) {
                $.tools.post(params, url, callback, scope);
            }
        });
    },
    ajaxLoading: function (msg) {
        $("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body");
        $("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo("body").css({ display: "block", fontSize: "12px", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });
    },
    ajaxLoadEnd: function () {
        $(".datagrid-mask").remove();
        $(".datagrid-mask-msg").remove();
    },
    //单格式上鼠标停留显示完整内容
    formatCellTooltip: function (val) {
        return "<span title='" + val + "'>" + val + "</span>";
    }
}