/**
 * company.js
 */
var basePath;
var company_code;
var V_LOGINNAME;
var V_PASSWORD;
var storeTime = 60000;
var buildingStore = null,
    companyStore = null,
    devicesStore = null;
var building_name;
var max_level = 0;
var min_level = 0;
var top_level = 0;
var default_check = 65535;
var myMask;
var show_project_info = true;
var start = 0;
var end = 360;
var theme;
var vAlarmInfoWin;
var online_video = false;
var onair_video = false;
var ConfirmStore;
var modifywin;
var had_play = false;
var fillvalue = false;


Ext.Loader.setConfig({
    enabled: true
});

Ext.Loader.setPath('Ext.ux', '../../res/extjs/examples/ux');

Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.ux.RowExpander',
    'Ext.selection.CheckboxModel'
]);

var bak_to_front = function() {
    location.href = basePath + 'view/frontpage/map.jsp?company_code=' + company_code;
}

var staSortBypoint = function(a, b) {
    return a.point_code - b.point_code;;
}

var body_resize = function() {
    $("#company_bg_mm").css('display', 'none');
    if ($(document).innerWidth() >= 1820) {
        $("#company_bg_tm").css('display', 'block');
        $("#company_bg_tm").css('width', ($(document).innerWidth() - 1820) + 'px');
        $("#company_bg_bm").css('display', 'block');
        $("#company_bg_bm").css('width', ($(document).innerWidth() - 1820) + 'px');
    } else {
        $("#company_bg_tm").css('display', 'none');
        $("#company_bg_bm").css('display', 'none');
    }
    if ($(document).innerHeight() >= 932) {
        $("#company_bg_ml").css('display', 'block');
        $("#company_bg_mr").css('display', 'block');
        $("#company_bg_ml").css('height', ($(document).innerHeight() - 932) + 'px');
        $("#company_bg_mr").css('height', ($(document).innerHeight() - 932) + 'px');
        if ($(document).innerWidth() >= 1820) {
            $("#company_bg_mm").css('display', 'block');
            $("#company_bg_mm").css('height', ($(document).innerHeight() - 932) + 'px');
            $("#company_bg_mm").css('width', ($(document).innerWidth() - 1820) + 'px');
        }
    } else {
        $("#company_bg_ml").css('display', 'none');
        $("#company_bg_mr").css('display', 'none');
    }
    $("#company_building").css('height', ($(document).innerHeight() - 328) + 'px');
    $("#history_alarm_list").css('width', ($(document).innerWidth() - 975) + 'px');
    $("#history_alarm_list").css('height', ($(document).innerHeight() - 616) + 'px');
    $("#project_info_bar").css('width', ($(document).innerWidth() - 975) + 'px');
}

var chk_click_big = function(obj) {
    location.href = basePath + 'view/3dBig/index.jsp?theme=' + theme + '&company_code=' + ($("#company_code").val());
}


var chk_click = function(obj) {
    if ((obj.id == 'dev_all_checkbox') || (obj.id == 'dev_all_checklabel')) {
        if (default_check != 65535)
            default_check = 65535;
        else
            default_check = 0;
    } else if ((obj.id == 'dev_ui_checkbox') || (obj.id == 'dev_ui_checklabel')) {
        if ((default_check & 1) == 1)
            default_check = (default_check & 65534);
        else
            default_check = (default_check | 1);
    } else if ((obj.id == 'dev_fc_checkbox') || (obj.id == 'dev_fc_checklabel')) {
        if ((default_check & 2) == 2)
            default_check = (default_check & 65533);
        else
            default_check = (default_check | 2);
    } else if ((obj.id == 'dev_ef_checkbox') || (obj.id == 'dev_ef_checklabel')) {
        if ((default_check & 4) == 4)
            default_check = (default_check & 65531);
        else
            default_check = (default_check | 4);
    } else if ((obj.id == 'dev_wp_checkbox') || (obj.id == 'dev_wp_checklabel')) {
        if ((default_check & 8) == 8)
            default_check = (default_check & 65527);
        else
            default_check = (default_check | 8);
    } else if ((obj.id == 'dev_ll_checkbox') || (obj.id == 'dev_ll_checklabel')) {
        if ((default_check & 16) == 16)
            default_check = (default_check & 65519);
        else
            default_check = (default_check | 16);
    } else if ((obj.id == 'dev_ci_checkbox') || (obj.id == 'dev_ci_checklabel')) {
        if ((default_check & 32) == 32)
            default_check = (default_check & 65503);
        else
            default_check = (default_check | 32);
    } else if ((obj.id == 'dev_va_checkbox') || (obj.id == 'dev_va_checklabel')) {
        if ((default_check & 64) == 64)
            default_check = (default_check & 65471);
        else
            default_check = (default_check | 64);
    } else if ((obj.id == 'dev_ot_checkbox') || (obj.id == 'dev_ot_checklabel')) {
        if ((default_check & 128) == 128)
            default_check = (default_check & 65407);
        else
            default_check = (default_check | 128);
    } else if ((obj.id == 'dev_sm_checkbox') || (obj.id == 'dev_sm_checklabel')) {
        if ((default_check & 256) == 256)
            default_check = (default_check & 65279);
        else
            default_check = (default_check | 256);
    }
    if (default_check == 0) {
        $("#dev_all_checkbox").removeClass('dev_checkbox');
        $("#dev_all_checkbox").removeClass('dev_few_checkbox');
        $("#dev_all_checkbox").addClass('dev_uncheckbox');
    } else if (default_check == 65535) {
        $("#dev_all_checkbox").removeClass('dev_uncheckbox');
        $("#dev_all_checkbox").removeClass('dev_few_checkbox');
        $("#dev_all_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_all_checkbox").removeClass('dev_uncheckbox');
        $("#dev_all_checkbox").removeClass('dev_checkbox');
        $("#dev_all_checkbox").addClass('dev_few_checkbox');
    }
    if ((default_check & 1) == 1) {
        $("#dev_ui_checkbox").removeClass('dev_uncheckbox');
        $("#dev_ui_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_ui_checkbox").removeClass('dev_checkbox');
        $("#dev_ui_checkbox").addClass('dev_uncheckbox');
    }
    if ((default_check & 2) == 2) {
        $("#dev_fc_checkbox").removeClass('dev_uncheckbox');
        $("#dev_fc_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_fc_checkbox").removeClass('dev_checkbox');
        $("#dev_fc_checkbox").addClass('dev_uncheckbox');
    }
    if ((default_check & 4) == 4) {
        $("#dev_ef_checkbox").removeClass('dev_uncheckbox');
        $("#dev_ef_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_ef_checkbox").removeClass('dev_checkbox');
        $("#dev_ef_checkbox").addClass('dev_uncheckbox');
    }
    if ((default_check & 8) == 8) {
        $("#dev_wp_checkbox").removeClass('dev_uncheckbox');
        $("#dev_wp_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_wp_checkbox").removeClass('dev_checkbox');
        $("#dev_wp_checkbox").addClass('dev_uncheckbox');
    }
    if ((default_check & 16) == 16) {
        $("#dev_ll_checkbox").removeClass('dev_uncheckbox');
        $("#dev_ll_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_ll_checkbox").removeClass('dev_checkbox');
        $("#dev_ll_checkbox").addClass('dev_uncheckbox');
    }
    if ((default_check & 32) == 32) {
        $("#dev_ci_checkbox").removeClass('dev_uncheckbox');
        $("#dev_ci_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_ci_checkbox").removeClass('dev_checkbox');
        $("#dev_ci_checkbox").addClass('dev_uncheckbox');
    }
    if ((default_check & 64) == 64) {
        $("#dev_va_checkbox").removeClass('dev_uncheckbox');
        $("#dev_va_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_va_checkbox").removeClass('dev_checkbox');
        $("#dev_va_checkbox").addClass('dev_uncheckbox');
    }
    if ((default_check & 128) == 128) {
        $("#dev_ot_checkbox").removeClass('dev_uncheckbox');
        $("#dev_ot_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_ot_checkbox").removeClass('dev_checkbox');
        $("#dev_ot_checkbox").addClass('dev_uncheckbox');
    }
    if ((default_check & 256) == 256) {
        $("#dev_sm_checkbox").removeClass('dev_uncheckbox');
        $("#dev_sm_checkbox").addClass('dev_checkbox');
    } else {
        $("#dev_sm_checkbox").removeClass('dev_checkbox');
        $("#dev_sm_checkbox").addClass('dev_uncheckbox');
    }
    bak_reset();
}

var clear_append_form = function() {

    Ext.getCmp('fa_company_code').setValue("");
    Ext.getCmp('fa_userfile').setValue("");
    Ext.getCmp('FactoryListPageToolbar').moveFirst();

}


var sc = function() {
    modifywin();
}


var chk_empty_level = function(level) {
    for (var i = 0; i < buildingStore.length; i++) {
        if (buildingStore[i].min_level == level) {
            if (((default_check & 1) == 1) && (buildingStore[i].dwtype == 'YTUI'))
                return false;
            else if (((default_check & 2) == 2) && (buildingStore[i].dwtype == 'YTFC'))
                return false;
            else if (((default_check & 4) == 4) && (buildingStore[i].dwtype == 'YTEF'))
                return false;
            else if (((default_check & 8) == 8) && (buildingStore[i].dwtype == 'YTWP'))
                return false;
            else if (((default_check & 16) == 16) && (buildingStore[i].dwtype == 'YTLL'))
                return false;
            else if (((default_check & 32) == 32) && (buildingStore[i].dwtype == 'YTCI'))
                return false;
            else if (((default_check & 64) == 64) && (buildingStore[i].dwtype == 'YTVA'))
                return false;
            else if (((default_check & 128) == 128) && (buildingStore[i].dwtype == 'YTWC'))
                return false;
            else if (((default_check & 256) == 256) && (buildingStore[i].dwtype == 'YTSM'))
                return false;
        }
    }
    return true;
}

var draw_buinding = function() {
    var building_icon_height = 0;
    $("#building_level_count").html(max_level);

    let array = ["10309", "10308", "10307", "10306", "10305", "10304", "10303", "10302", "10301", "10300", "10299", "10298", "10297", "10296", "10295", "10294", "10293", "10292", "10291", "10290", "10289", "10288", "10287", "10286", "10285", "10284", "10283", "10282", "10281", "10280", "10279", "10278", "10277", "10276", "10275", "10274", "10273", "10272", "10271", "10270", "10269", "10268", "10267", "10266", "10265", "10264", "10263", "10262", "10261", "10260", "10259", "10258", "10257", "10256", "10255", "10254", "10253", "10252", "10251", "10250", "10249", "10248", "10246", "10245", "10244", "10243", "10242", "10241", "10240", "10239", "10238", "10237", "10236", "10234"]
    //  10244，10243，10242，10238 16层

    //  if (company_code == '10182') {
    if (array.includes(company_code)) {
        //    $("#dev_big_checklabel").addClass('dev_big_checklabel');
        //   var dev_big_checklabel = document.getElementById('dev_big_checklabel');
        //     dev_big_checklabel.innerHTML = '最大化';
        $("#company_bg_tl").removeClass('company_bg_tl');
        $("#company_bg_tl").addClass('company_bg_YP');
        $("#dev_all_checkbox").hide();
        $("#dev_all_checklabel").hide();
        $("#dev_ui_checkbox").hide();
        $("#dev_ui_checklabel").hide();
        $("#dev_sm_checkbox").hide();
        $("#dev_sm_checklabel").hide();
        $("#dev_fc_checkbox").hide();
        $("#dev_fc_checklabel").hide();
        $("#dev_ef_checkbox").hide();
        $("#dev_ef_checklabel").hide();
        $("#dev_wp_checkbox").hide();
        $("#dev_wp_checklabel").hide();
        $("#dev_ll_checkbox").hide();
        $("#dev_ll_checklabel").hide();
        $("#dev_ci_checkbox").hide();
        $("#dev_ci_checklabel").hide();
        $("#dev_va_checkbox").hide();
        $("#dev_va_checklabel").hide();
        $("#dev_ot_checkbox").hide();
        $("#dev_ot_checklabel").hide();
        $("#company_building").removeClass('company_building');
        $("#company_building").addClass('company_building_on');
        var company_building = document.getElementById('company_building');
        company_building.innerHTML = '<iframe id="myIframe" name="thingjs" src="https://www.thingjs.com/s/b11227d4fd5505106989737c?params=105b0f77fd24654d4eebc434e9" style="width:146%;height:123%;border:1px solid #0082ff;"></iframe>';

        var t1 = window.setTimeout(function() {
            //     console.log(buildingStore);
            //    debugger;
            callFuncInThingJS("userListener", buildingStore, top_level,company_code);


            window.clearTimeout(t1);

        }, 10000)


    } else {
        var company_building = document.getElementById('company_building');
        company_building.innerHTML = '';
        var currett_build = document.createElement('div');
        company_building.appendChild(currett_build)
        var building_top = document.createElement('div');
        building_top.setAttribute('class', 'building_top');
        building_top.style.top = '0px';
        currett_build.appendChild(building_top);
        building_icon_height += 120;
        var top_info = document.createElement('div');
        top_info.id = "building_top_info";
        top_info.setAttribute('class', 'building_top_label');
        top_info.innerHTML = 'RF';
        building_top.appendChild(top_info);
        var top_icon = document.createElement('div');
        top_icon.setAttribute('class', 'building_top_icon');
        building_top.appendChild(top_icon);
        if (max_level > 0) {
            var last_empty = max_level + 2;
            var first_empty = max_level + 2;
            for (var i = max_level; i > 0; i--) {
                if (chk_empty_level(i)) {
                    if (last_empty != (i + 1)) {
                        first_empty = i;
                        last_empty = i;
                        var build_level = document.createElement('div');
                        build_level.setAttribute('class', 'building_level');
                        build_level.style.top = (building_icon_height - 60) + 'px';
                        currett_build.appendChild(build_level);
                        building_icon_height += 48;
                        var level_info = document.createElement('div');
                        level_info.id = "building_empty_level_info_" + i;
                        level_info.setAttribute('class', 'building_level_info')
                        level_info.innerHTML = i + 'F';
                        build_level.appendChild(level_info);
                        var level_icon = document.createElement('div');
                        level_icon.setAttribute('class', 'building_empty_level_icon');
                        build_level.appendChild(level_icon);
                    } else {
                        var level_info = document.getElementById('building_empty_level_info_' + first_empty);
                        if (level_info != undefined)
                            level_info.innerHTML = i + 'F~' + first_empty + 'F';
                        last_empty = i;
                    }
                } else {
                    var build_level = document.createElement('div');
                    build_level.setAttribute('class', 'building_level');
                    build_level.style.top = (building_icon_height - 60) + 'px';
                    currett_build.appendChild(build_level);
                    building_icon_height += 48;
                    var level_info = document.createElement('div');
                    level_info.id = "building_level_info_" + i;
                    level_info.setAttribute('class', 'building_level_info')
                    level_info.innerHTML = i + 'F';
                    build_level.appendChild(level_info);
                    var level_icon = document.createElement('div');
                    level_icon.setAttribute('class', 'building_level_icon');
                    build_level.appendChild(level_icon);
                }
            }
        }
        if (min_level < 0) {
            for (var i = -1; i >= min_level; i--) {
                var base_level = document.createElement('div');
                base_level.setAttribute('class', 'building_base');
                base_level.style.top = (building_icon_height - 60) + 'px';
                currett_build.appendChild(base_level);
                building_icon_height += 48;
                var base_info = document.createElement('div');
                base_info.id = 'building_base_info_' + (0 - i);
                base_info.setAttribute('class', 'building_base_info');
                base_info.innerHTML = 'B' + (0 - i) + 'F';
                base_level.appendChild(base_info);
                var base_icon = document.createElement('div');
                base_icon.setAttribute('class', 'building_base_icon');
                base_level.appendChild(base_icon);
            }
        }
        $("#company_building").css('height', ($(document).innerHeight() - 402) + 'px');
        building_icon_height += 60;
        currett_build.style.marginLeft = '59px';
        currett_build.style.marginRight = '59px';
        currett_build.style.width = '536px';

        if ((buildingStore != null) && (buildingStore.length > 0)) {
            for (var i = 0; i < buildingStore.length; i++) {
                var iconid = buildingStore[i].dwtype + '_' + buildingStore[i].min_level;
                var icon = document.getElementById(iconid);
                if (icon == undefined) {
                    icon = document.createElement('div');
                    icon.id = buildingStore[i].dwtype + '_' + buildingStore[i].min_level;
                    icon.dwtype = buildingStore[i].dwtype;
                    icon.level = buildingStore[i].min_level;
                    icon.owner_code = buildingStore[i].owner_code;
                    icon.style.position = 'absolute';
                    icon.style.width = '62px';
                    icon.style.height = '62px';
                    icon.style.cursor = 'pointer';
                    icon.setAttribute('onclick', 'icon_click(this)');
                    currett_build.appendChild(icon);
                    var this_min_level = buildingStore[i].min_level;
                    var level_label = document.getElementById("building_level_info_" + this_min_level);
                    if (this_min_level == top_level) {
                        level_label = document.getElementById('building_top_info');
                    } else if (this_min_level < 0) {
                        level_label = document.getElementById('building_base_info_' + (0 - this_min_level));
                    }
                    if (level_label != null) {
                        if (buildingStore[i].dwtype == 'YTUI') {
                            if ((default_check & 1) == 1) {
                                icon.title = '用户传输装置';
                                icon.style.top = (level_label.offsetParent.offsetTop + 1) + 'px'
                                icon.style.left = (level_label.offsetParent.offsetLeft + 28) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/ui_icon.png)';
                            }
                        } else if (buildingStore[i].dwtype == 'YTFC') {
                            if ((default_check & 2) == 2) {
                                icon.title = '消防控制柜';
                                icon.style.top = (level_label.offsetParent.offsetTop + 15) + 'px'
                                icon.style.left = (level_label.offsetParent.offsetLeft + 68) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/fc_icon.png)';
                            }
                        } else if (buildingStore[i].dwtype == 'YTEF') {
                            if ((default_check & 4) == 4) {
                                icon.title = '电气火灾';
                                icon.style.top = (level_label.offsetParent.offsetTop + 29) + 'px'
                                icon.style.left = (level_label.offsetParent.offsetLeft + 108) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/ef_icon.png)';
                            }
                        } else if (buildingStore[i].dwtype == 'YTWP') {
                            if ((default_check & 8) == 8) {
                                icon.title = '水压';
                                icon.style.top = (level_label.offsetParent.offsetTop + 43) + 'px'
                                icon.style.left = (level_label.offsetParent.offsetLeft + 148) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/wp0_icon.png)';
                            }
                        } else if (buildingStore[i].dwtype == 'YTLL') {
                            if ((default_check & 16) == 16) {
                                icon.title = '液位';
                                icon.style.top = (level_label.offsetParent.offsetTop + 48) + 'px'
                                icon.style.left = (level_label.offsetParent.offsetLeft + 188) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/ll_icon.png)';
                            }
                        } else if (buildingStore[i].dwtype == 'YTCI') {
                            if ((default_check & 32) == 32) {
                                icon.title = '环境监测';
                                icon.style.top = (level_label.offsetParent.offsetTop + 43) + 'px'
                                icon.style.left = (level_label.offsetParent.offsetLeft + 228) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/ci_icon.png)';
                            }
                        } else if (buildingStore[i].dwtype == 'YTVA') {
                            if ((default_check & 64) == 64) {
                                icon.title = '视频监控';
                                icon.style.top = (level_label.offsetParent.offsetTop + 29) + 'px'
                                icon.style.left = (level_label.offsetParent.offsetLeft + 268) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/va_icon.png)';
                            }
                        } else if (buildingStore[i].dwtype == 'YTWC') {
                            if ((default_check & 128) == 128) {
                                icon.title = '风机控制柜';
                                icon.style.top = (level_label.offsetParent.offsetTop + 15) + 'px'
                                icon.style.left = (level_label.offsetParent.offsetLeft + 308) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/wc_icon.png)';
                            }
                        } else if (buildingStore[i].dwtype == 'YTSM') {
                            if ((default_check & 256) == 256) {
                                icon.title = '烟感';
                                icon.style.top = (level_label.offsetParent.offsetTop + 1) + 'px';
                                icon.style.left = (level_label.offsetParent.offsetLeft + 348) + 'px';
                                icon.style.backgroundImage = 'url(../../res/img/icons/sm_icon.png)';
                            }
                        }
                    }
                } else
                    icon.owner_code = "";
            }
        }
    }


    if (show_project_info) {
        var project_info_bar = document.getElementById('project_info_bar');
        project_info_bar.innerHTML = '';
        var project_label = document.createElement('div');
        project_label.setAttribute('class', 'project_label');
        project_label.style.position = 'absolute';
        project_label.style.top = '30px';
        project_label.style.left = '50px';
        project_label.innerHTML = '项目名称';
        project_info_bar.appendChild(project_label);
        var project_info = document.createElement('div');
        //  ;
        project_info.setAttribute('class', 'project_info');
        project_info.style.position = 'absolute';
        project_info.style.top = '60px';
        project_info.style.left = '50px';
        project_info.innerHTML = companyStore.company_name;
        project_info_bar.appendChild(project_info);
        project_label = document.createElement('div');
        project_label.setAttribute('class', 'project_label');
        project_label.style.position = 'absolute';
        project_label.style.top = '110px';
        project_label.style.left = '50px';
        project_label.innerHTML = '项目地址';
        project_info_bar.appendChild(project_label);
        project_info = document.createElement('div');;
        project_info.setAttribute('class', 'project_info');
        project_info.style.position = 'absolute';
        project_info.style.top = '140px';
        project_info.style.left = '50px';
        project_info.innerHTML = companyStore.address;
        project_info_bar.appendChild(project_info);
        project_label = document.createElement('div');
        project_label.setAttribute('class', 'project_label');
        project_label.style.position = 'absolute';
        project_label.style.top = '190px';
        project_label.style.left = '50px';
        project_label.innerHTML = '项目坐标';
        project_info_bar.appendChild(project_label);
        project_info = document.createElement('div');;
        project_info.setAttribute('class', 'project_info');
        project_info.style.position = 'absolute';
        project_info.style.top = '220px';
        project_info.style.left = '50px';
        project_info.innerHTML = companyStore.lng + ',' + companyStore.lat;
        project_info_bar.appendChild(project_info);
        project_label = document.createElement('div');
        project_label.setAttribute('class', 'project_label');
        project_label.style.position = 'absolute';
        project_label.style.top = '30px';
        project_label.style.left = '480px';
        project_label.innerHTML = '联系人';
        project_info_bar.appendChild(project_label);
        project_info = document.createElement('div');;
        project_info.setAttribute('class', 'project_info');
        project_info.style.position = 'absolute';
        project_info.style.top = '60px';
        project_info.style.left = '480px';
        project_info.innerHTML = companyStore.username;
        project_info_bar.appendChild(project_info);
        project_label = document.createElement('div');
        project_label.setAttribute('class', 'project_label');
        project_label.style.position = 'absolute';
        project_label.style.top = '110px';
        project_label.style.left = '480px';
        project_label.innerHTML = '联系电话';
        project_info_bar.appendChild(project_label);
        project_info = document.createElement('div');;
        project_info.setAttribute('class', 'project_info');
        project_info.style.position = 'absolute';
        project_info.style.top = '140px';
        project_info.style.left = '480px';
        project_info.innerHTML = companyStore.phone;
        project_info_bar.appendChild(project_info);
        var history_alarm_list = document.getElementById('history_alarm_list');
        history_alarm_list.innerHTML = '';
        var table = document.createElement('table');
        table.width = '100%';
        history_alarm_list.appendChild(table);
        var tr = document.createElement('tr');
        table.appendChild(tr);
        var dwtypelist = [1, 7, 2, 6, 16, 17];
        for (var i = 0; i < 6; i++) {
            var td = document.createElement('td');
            td.setAttribute('colspan', '2');
            td.setAttribute('style', 'width:128px;');
            td.setAttribute('class', 'data_bar_title');
            td.style.textAlign = 'center';
            td.style.paddingTop = '15px';
            td.setAttribute('onclick', 'show_alarm_list("' + company_code + '","' + dwtypelist[i] + '")');
            if (i == 0)
                td.innerHTML = '火灾监控';
            else if (i == 1)
                td.innerHTML = '电气火灾监控';
            else if (i == 2)
                td.innerHTML = '水系统监控';
            else if (i == 3)
                td.innerHTML = 'RTU监控';
            else if (i == 4)
                td.innerHTML = '视频告警监控'
            else
                td.innerHTML = '电梯告警监控'
            tr.appendChild(td);
        }
        tr = document.createElement('tr');
        table.appendChild(tr);
        for (var i = 0; i < 6; i++) {
            var td = document.createElement('td');
            td.setAttribute('class', 'data_bar_total_label');
            td.style.textAlign = 'right';
            td.width = '10%';
            td.innerHTML = '设备总数';
            td.setAttribute('onclick', 'show_alarm_list("' + company_code + '","' + dwtypelist[i] + '")');
            tr.appendChild(td);
            td = document.createElement('td');
            td.setAttribute('class', 'data_bar_total_number');
            td.style.textAlign = 'left';
            td.style.paddingLeft = '10px';
            td.setAttribute('onclick', 'show_alarm_list("' + company_code + '","' + dwtypelist[i] + '")');
            if (i == 0)
                td.innerHTML = companyStore.d1;
            else if (i == 1)
                td.innerHTML = companyStore.d7;
            else if (i == 2)
                td.innerHTML = companyStore.d2;
            else if (i == 3)
                td.innerHTML = companyStore.d6;
            else if (i == 4)
                td.innerHTML = companyStore.d16;
            else
                //td.innerHTML=companyStore.d17;
                td.innerHTML = 0;
            tr.appendChild(td);
        }
        tr = document.createElement('tr');
        table.appendChild(tr);
        for (var i = 0; i < 6; i++) {
            var td = document.createElement('td');
            td.setAttribute('class', 'data_bar_total_label');
            td.style.textAlign = 'right';
            td.width = '10%';
            td.innerHTML = '已处理';
            td.setAttribute('onclick', 'show_alarm_list("' + company_code + '","' + dwtypelist[i] + '")');
            tr.appendChild(td);
            td = document.createElement('td');
            td.setAttribute('class', 'device_confirm_num1');
            td.style.textAlign = 'left';
            td.style.paddingLeft = '10px';
            td.setAttribute('onclick', 'show_alarm_list("' + company_code + '","' + dwtypelist[i] + '")');
            if (i == 0)
                td.innerHTML = companyStore.d1ac;
            else if (i == 1)
                td.innerHTML = companyStore.d7ac;
            else if (i == 2)
                td.innerHTML = companyStore.d2ac;
            else if (i == 3)
                td.innerHTML = companyStore.d6ac;
            else if (i == 4)
                td.innerHTML = companyStore.d16ac;
            else
                //td.innerHTML=companyStore.d17ac;
                td.innerHTML = 0;
            tr.appendChild(td);
        }
        tr = document.createElement('tr');
        table.appendChild(tr);
        for (var i = 0; i < 6; i++) {
            var td = document.createElement('td');
            td.setAttribute('class', 'data_bar_total_label');
            td.style.textAlign = 'right';
            td.width = '10%';
            td.innerHTML = '待处理';
            td.setAttribute('onclick', 'show_alarm_list("' + company_code + '","' + dwtypelist[i] + '")');
            tr.appendChild(td);
            td = document.createElement('td');
            td.setAttribute('class', 'device_confirm_num2');
            td.style.textAlign = 'left';
            td.style.paddingLeft = '10px';
            td.setAttribute('onclick', 'show_alarm_list("' + company_code + '","' + dwtypelist[i] + '")');
            if (i == 0)
                td.innerHTML = companyStore.d1a - companyStore.d1ac;
            else if (i == 1)
                td.innerHTML = companyStore.d7a - companyStore.d7ac;
            else if (i == 2)
                td.innerHTML = companyStore.d2a - companyStore.d2ac;
            else if (i == 3)
                td.innerHTML = companyStore.d6a - companyStore.d6ac;
            else if (i == 4)
                td.innerHTML = companyStore.d16a - companyStore.d16ac;
            else
                //td.innerHTML=companyStore.d17a-companyStore.d17ac;
                td.innerHTML = 0;
            tr.appendChild(td);
        }
        tr = document.createElement('tr');
        table.appendChild(tr);
        for (var i = 0; i < 6; i++) {
            var td = document.createElement('td');
            td.setAttribute('colspan', '2');
            tr.appendChild(td);
            var div = document.createElement('div');
            div.id = 'alarm_pie_' + i;
            div.style.margin = '10px auto 10px auto';
            div.style.width = '110px';
            td.setAttribute('onclick', 'show_alarm_list("' + company_code + '","' + dwtypelist[i] + '")');
            td.appendChild(div);
        }
        draw_pie('alarm_pie_0', companyStore.d1a, companyStore.d1ac);
        draw_pie('alarm_pie_1', companyStore.d7a, companyStore.d7ac);
        draw_pie('alarm_pie_2', companyStore.d2a, companyStore.d2ac);
        draw_pie('alarm_pie_3', companyStore.d6a, companyStore.d6ac);
        draw_pie('alarm_pie_4', companyStore.d16a, companyStore.d16ac);
        //draw_pie('alarm_pie_5',companyStore.d17a,companyStore.d17ac);
        draw_pie('alarm_pie_5', 0);
    } else {
        var project_info_bar = document.getElementById('project_info_bar');
        project_info_bar.innerHTML = '';
        var history_alarm_list = document.getElementById('history_alarm_list');
        history_alarm_list.innerHTML = '';
    }
}


function callFuncInThingJS(funcName, data, top_level,company_code) {
    var iframe = $('#myIframe')[0];
    var msg = { data, top_level,company_code }
    var message = {
        'funcName': funcName,
        'param': msg
    }
    iframe.contentWindow.postMessage(message, '*');
}

function myaleart() {
    alert("wwwwwwwwwwwwwwwwwww");
}

window.addEventListener('message', function(e) {
    var data = e.data;
    var funcName = data.funcName;
    var param = data.param;
    if (window[funcName]) window[funcName](param);
