$(function () {
    loadMajor();
});

/* 新增一个选项卡
* url :选项卡的内容（跳转的地址）
* title:选项卡的标题
* size: name的iframe+size 序号，尽量不用重复
*/
function page(url, title, size, type) {
    var nav = $(window.parent.document).find('.J_menuTabs .page-tabs-content ');
    $(window.parent.document).find('.J_menuTabs .page-tabs-content ').find(".J_menuTab.active").removeClass("active");
    $(window.parent.document).find('.J_mainContent').find("iframe").css("display", "none");

    // 选项卡菜单已存在
    var wpd = $(window.parent.document);
    var mainContent = wpd.find('.J_mainContent');
    var thisIframe = mainContent.find("iframe[data-id='"+ url +"']");

    var pageTabs = wpd.find('.J_menuTabs .page-tabs-content');
    // pageTabs.find(".J_menuTab .active").removeClass("active");
    // mainContent.find("iframe").css("display", "none");

    console.log("thisIframe:" + thisIframe.length);
    if(thisIframe.length > 0){	// 选项卡已打开
        console.log("选项卡已打开");
        thisIframe.css("display", "inline");
        pageTabs.find(".J_menuTab[data-id='"+ url +"']").addClass("active");
    }else{
        console.log("选项卡未打开");
        var iframe = '<iframe class="J_iframe" name="iframe"' + size + ' width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url
            + '" seamless="" style="display: inline;"></iframe>';
        $(window.parent.document).find('.J_menuTabs .page-tabs-content ').append(
            ' <a href="javascript:;" class="J_menuTab active" data-id="' + url + '">' + title + ' <i class="fa fa-times-circle"></i></a>');
        $(window.parent.document).find('.J_mainContent').append(iframe);
    }
}

var core_data = [{
    "dataname": "焦炭使用量",
    "times": "2022-03-01 12:32:56",
    "dataSource": "炼铁工序生产系统"
}, {
    "dataname": "系统频率",
    "times": "2022-03-03 15:23:26",
    "dataSource": "电力控制系统"
}, {
    "dataname": "线路潮流",
    "times": "2022-03-03 15:23:26",
    "dataSource": "电力控制系统"
}, {
    "dataname": "配料机参数",
    "times": "2022-03-03 15:23:26",
    "dataSource": "炼铁工序生产系统"
}, {
    "dataname": "脱硫脱磷处理量",
    "times": "2022-03-03 15:23:26",
    "dataSource": "炼铁工序生产系统"
}, {
    "dataname": "烧结矿经破碎冷却时间值",
    "times": "2022-03-03 15:23:26",
    "dataSource": "炼铁工序生产系统炼铁工序生产系统炼铁工序生产系统炼铁工序生产系统"
}, {
    "dataname": "测试数据",
    "times": "2022-03-03 15:23:26",
    "dataSource": "测试系统"
},];


var bt_data = [{
    "dataname": "高炉入炉风温度",
    "times": "2022-03-01 12:32:56",
    "dataSource": "炼铁工序生产系统"
}, {
    "dataname": "测试数据",
    "times": "2022-03-03 15:23:26",
    "dataSource": "测试系统"
}, {
    "dataname": "发电机出力",
    "times": "2022-03-03 15:23:26",
    "dataSource": "电力控制系统"
}, {
    "dataname": "母线电压",
    "times": "2022-03-03 15:23:26",
    "dataSource": "电力控制系统"
}, {
    "dataname": "炉顶压力",
    "times": "2022-03-03 15:23:26",
    "dataSource": "炼铁工序生产系统炼铁工序生产系统炼铁工序生产系统炼铁工序生产系统"
}, {
    "dataname": "铁水重量",
    "times": "2022-03-03 15:23:26",
    "dataSource": "炼铁工序生产系统"
}, {
    "dataname": "石灰石数量",
    "times": "2022-03-03 15:23:26",
    "dataSource": "炼铁工序生产系统"
},];

function loadMajor() {


    //$('#exampleTable').bootstrapTable('load', bt_data);
    //$(exampleTable).bootstrapTable('prepend', bt_data);

    $('#coreTable').bootstrapTable('destroy').bootstrapTable({
        data: core_data,// 表格数据
        locale: $('#locale').val(),// 语言
        columns: [ // 列详情
            {
                title: '数据名称',// 表头字段名
                field: 'dataname',// 数据 key

                cellStyle: formatTableUnit,
                formatter: paramsMatter,
            }, {
                title: '数据来源',
                field: 'dataSource',

                cellStyle: formatTableUnit,
                formatter: paramsMatter,
            }, {
                title: '上传时间',
                field: 'times',

                cellStyle: formatTableUnit,
                formatter: paramsMatter,
            }
        ]
    });
    $('#coreTable').bootstrapTable("hideLoading");

    $('#majorTable').bootstrapTable('destroy').bootstrapTable({
        data: bt_data,// 表格数据
        locale: $('#locale').val(),// 语言
        columns: [ // 列详情
            {
                title: '数据名称',// 表头字段名
                field: 'dataname',// 数据 key

                cellStyle: formatTableUnit,
                formatter: paramsMatter,
            }, {
                title: '数据来源',
                field: 'dataSource',

                cellStyle: formatTableUnit,
                formatter: paramsMatter,
            }, {
                title: '上传时间',
                field: 'times',

                cellStyle: formatTableUnit,
                formatter: paramsMatter,
            }
        ]
    });
    $('#majorTable').bootstrapTable("hideLoading");


}

// //表格超出宽度鼠标悬停显示td内容
// function paramsMatter(value, row, index, field) {
//     var span = document.createElement('span');
//     span.setAttribute('title', value);
//     span.innerHTML = value;
//     return span.outerHTML;
// }
//
// //td宽度以及内容超过宽度隐藏
// function formatTableUnit(value, row, index) {
//     return {
//         css: {
//             "white-space": 'nowrap',
//             "text-overflow": 'ellipsis',
//             "overflow": 'hidden',
//             // "max-width": '100px'
//         }
//     }
// }

