
var myjs = {
    urls: {
        files: "/api/ReportApi/getreportfiles",
        fileContentUrl: "/api/ReportApi/GetHtml",
        reportUrl: "/api/ReportApi/GetPrint",
        getresult: "/api/ReportApi/GetResult",
    },
    //定义从对象获取请求参数的方法
    getParaStr(data) {
        var arr = []
        for (const key in data) {
            arr.push(key + "=" + data[key])
        }
        return arr.join('&')
    },
    //创建sql字符串
    createSql(e) {
        var pn = "";
        var paras = "";
        var ec = $(e).find("input");
        for (var i = 0; i < ec.length; i++) {
            var e = $(ec[i]);
            var n = e.attr("name");
            var v = e.val();
            if (n == "ProcedureName") {
                pn = v;
            } else if (n == "reportName" || n == "sqlStr") {

            } else {
                paras = paras + " @" + n + "='" + v + "',";
            }
        }
        return "exec " + pn + paras.substring(0, paras.lastIndexOf(','));;
    },
    //发送post请求，发送data数据，执行成功方法sc和失败方法ec
    post(url, data, sc, ec) {
        if (!ec) {
            ec = function (e) {
                debugger;
                console.log(e);
                alert(e);
            };
        }
        fetch(url, {
            credentials: 'same-origin',
            method: 'POST', // or 'PUT'
            body: this.getParaStr(data),
            headers: new Headers({
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            })
        })
            .then(Response => Response.json())
            .then(sc)
            .catch(ec);
    },
    //提示消息并记录
    showmsg(msg) {
        console.log(msg);
        alert(msg);
    },
    getUId() {
        return JSON.parse($.cookie("_userCK")).uid;
    },
    getUName() {
        return JSON.parse($.cookie("_userCK")).un;
    },
    print() {
        var pName = $("input[name='reportName']").val();
        var sqlStr = $("input[name='sqlStr']").val();
        $.cookie("_reportName", pName);
        $.cookie("_SqlString", sqlStr);
        window.open(this.urls.reportUrl + "?fileName=" + pName);
    },
    getReportName() {
        return $.cookie("_reportName");
    },
    getSqlStr() {
        return $.cookie("_SqlString");
    }
};