/**
 * 中间件状态
 */
var name = $("#sel").val();
var dataTable = null;
var i;

function load() {
    $.ajax({
        type: "POST",
        url: "/pqs9900/middRun/getMiddRunAll",
        data: "",
        beforeSend: function () {
            i = ityzl_SHOW_LOAD_LAYER();
        },
        success: function (data) {
            var height = $(window).height() - 155;
            var length = Math.floor(height / 28);
            if (length < 1) {
                length = 1;
            }
            // var heightTemp = screen.height;
            // var length;
            // if (heightTemp === 768) {
            //     length = 10;
            // } else if (heightTemp === 1024) {
            //     length = 20;
            // } else if (heightTemp === 960) {
            //     length = 15;
            // } else if (heightTemp === 1050) {
            //     length = 18;
            // } else {
            //     length = 15;
            // }
            //没有权限的请求
            if (data == 300) {
                location.href = '/pqs9900/auth/unauthorized';
                //没有登陆的请求
            } else if (data == 301) {
                location.href = '/pqs9900';
            } else {
                dataTable = $("#example").DataTable();
                dataTable.clear().draw();
                dataTable = $('#example').DataTable({
                    order: [],
                    columnDefs: [
                        {
                            orderable: false,
                            targets: [1, 2, 3, 4,7]
                        }
                    ],
                    data: data.body,
                    destroy: true,
                    searching: true,
                    dom: 'rtip',
                    pageLength: length,
                    columns: [
                        {"width": "7%"},
                        {"width": "7%"},
                        {"width": "10%"},
                        {"width": "8%"},
                        {
                            "width": "9%", render: function (data, type, full, meta) {
                                var value = data;
                                if (value == 0) {
                                    value = "异常";
                                } else if (value == 1) {
                                    value = "正常";
                                }
                                return value;
                            }
                        },
                        {"width": "8%"},
                        {"width": "10%"},
                        {"width": "10%"}
                    ],
                    language: {
                        url: '/pqs9900/json/chine.json',
                        "sEmptyTable": "没有内容"
                    },
                    'fnDrawCallback': function (oTable) {
                        $("#example_paginate").append("<div style='float:right;padding-top:4px;padding-left:10px'>到第 <input type='text' id='changePage' class='input-text' style='width:50px;height:28px;'> 页  <button class='btn btn-primary' id='dataTable-btn'>确定</button></div>");
                        var table = $("#example").dataTable();
                        $('#dataTable-btn').click(function (e) {
                            if ($("#changePage").val() && $("#changePage").val() > 0) {
                                var redirectpage = $("#changePage").val() - 1;
                            } else {
                                var redirectpage = 0;
                            }
                            table.fnPageChange(redirectpage);
                        });
                    }
                });
                modifyCss(dataTable);
            }
            //***********关闭loading
            ityzl_CLOSE_LOAD_LAYER(i);
        }
    });
}

$(document).ready(function () {
    load();
});

function modifyCss(table) {
    dataTable.buttons().container().css("display", "inline-block");
    dataTable.buttons().container().css("float", "right");
    dataTable.buttons().container().css("top", "4px");
    dataTable.buttons().container().find("a").prepend("<i class='glyphicon glyphicon-share'></i>");
    dataTable.buttons().container().appendTo('.header');
    dataTable.buttons().container().after($("#fliteData")[0]);
}

//搜索表中的数据
function searchResult(value) {
    dataTable.search(value).draw();
}

//查看详细信息以列表展示
function middRunDetail(middRunIndex) {
}