var layerId;
var layer = null;

function initAccordion() {
    /*
     * 手风琴折叠事件
     */
    layui.use('element', function () {
        var element = layui.element;
        element.init();// 初始动态元素
    });
}

/*
 * 获取归一化处理的数据(当前处理的事件),从redis缓存获取
 */
function queryNormalizeData() {
    layui.use(['layer'], function () {
        layer = layui.layer;
        layerId = SHOW_LOAD_LAYER(layer);

        $.ajax({
            type: 'POST',
            dataType: "json",
            url: '/pqs9200/advanced/queryNormalizeData',
            success: function (data) {
                processNormalizeData(data);
            },
            error: function () {
                CLOSE_LOAD_LAYER(layer, layerId);
                layer.msg("归一化事件列表查询失败！");
            }
        });
    });
}

/*
 * 处理归一化数据 使用template加载数据
 */
function processNormalizeData(data) {
    if (data.code != 0) {
        CLOSE_LOAD_LAYER(layer, layerId);
        layer.msg("归一化事件列表查询失败！");
        return;
    }

    var offset = 0;

    /*
     * 加载html模板
     */
    while (offset < data.object.length) {
        var template = document.querySelector('#tab_template');
        template.content.querySelector('.layui-colla-title').textContent = data.object[offset].name;
        template.content.querySelector('.tBody').id = 'example_'
            + offset.toString();

        $('.layui-collapse').append(template.content.cloneNode(true));

        offset++;
    }

    initAccordion();

    offset = 0;

    while (offset < data.object.length) {
        var j = 0;
        while (j < data.object[offset].list.length) {
            $("#example_" + offset.toString()).append(
                "<tr role='row' class='odd text-center'><td >"
                + (j + 1).toString() + "</td><td >"
                + data.object[offset].list[j].strTime
                /*+ "</td><td >" + data.object[offset].list[j].events*/
                + "</td><td >"
                + data.object[offset].list[j].plantInfo.nameGD
                + "</td><td >"
                + data.object[offset].list[j].plantInfo.nameBD
                + "</td><td>"
                + data.object[offset].list[j].plantInfo.namePoint
                + "</td></tr>");
            j++;
        }

        offset++;
    }

    CLOSE_LOAD_LAYER(layer, layerId);
}