const apiUrl = "/";
const hTitle = "指标库";
let pageCode = 1;
let pageName = "疾病分析";

$(function () {
    pageCode = GetQueryValue("pageCode");
    pageName = GetQueryValue("pageName");
    $("#page_title").html(pageName + " " + hTitle);
    GetIndSelect();
})

/**
 * 指标列表
 */
function GetIndSelect(filter) {
    $.ajax({
        url: apiUrl + "ind/find",
        type: "GET",
        data: {'pageCode': pageCode, 'filter': filter},
        contentType: "application/json",
        success: function (result) {
            $("#ind_list tr").remove();
            if (result.code === 1) {
                for (let i = 0; i < result.data.length; i++) {
                    let calculateWay = result.data[i].calculateWay;
                    if (calculateWay == 'null' || calculateWay == null) {
                        calculateWay = '';
                    }
                    let td_content = "<tr>" +
                        "<td>" + result.data[i].indCode + "</td>" +
                        "<td>" + result.data[i].indName + "</td>" +
                        "<td>" + result.data[i].indField + "</td>" +
                        "<td>" + result.data[i].showField + "</td>" +
                        "<td>" + calculateWay + "</td>" +
                        "</tr>";
                    $("#ind_list").append(td_content);
                }
            }
        }
    });
}

function GetQueryValue(queryName) {
    var query = decodeURI(window.location.search.substring(1));
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == queryName) {
            return pair[1];
        }
    }
    return null;
}

function getKey() {
    if (event.keyCode == 13) {
        GetIndSelect($(".filterTxt").val());
    }
}