$().ready(function() {
    $('.card').append('<img src="/static/images/icon_border_lt.png" class="icon-border icon-border-lt"><img src="/static/images/icon_border_lb.png" class="icon-border icon-border-lb"><img src="/static/images/icon_border_rt.png" class="icon-border icon-border-rt"><img src="/static/images/icon_border_rb.png" class="icon-border icon-border-rb">');
    // 桩基检测本月本年切换
    // var baseUrl = 'https://detect.cnjsjd.net';
    var baseUrl = '';
    

$('#toggle-header').click(function(){
    console.log(21)
    if($('#toggle-header').attr('data-type') == 'true'){
        $('#toggle-header').attr('data-type', 'false');
        $("#page").addClass('hide-header');
    }else if($('#toggle-header').attr('data-type') == 'false'){
        $('#toggle-header').attr('data-type', 'true');
        $("#page").removeClass('hide-header');
    }
})

    $('#zjjc div').click(function() {
            $('#zjjc div').removeClass('active-tab');
            $(this).addClass('active-tab');
            $.ajax({
                url: baseUrl + '/ajax/GetStationCollect.ashx?type=13',
                dataType: "jsonp",
                async: false,

                jsonp: 'jsonCallBack',
                headers: {
                    'Content-Type': 'application/json;charset=UTF-8'
                },
                success: res => {
                    if ($(this).text() == '本月') {
                        console.log('本月zhuangjijiance ', res)
                        $("span[square_type='13'][num='num1']").text(res[0].num1);
                        $("span[square_type='13'][num='num2']").text(res[0].num2);
                        $("span[square_type='13'][num='num3']").text(res[0].num3);
                        $("span[square_type='14'][num='num1']").text(res[0].num1);
                        $("span[square_type='14'][num='num2']").text(res[0].num2);
                        getPileFoundationDetection_1(0, res[0]);
                    } else {
                        // 本年
                        $("span[square_type='13'][num='num1']").html(res[0].num5);
                        $("span[square_type='13'][num='num2']").html(res[0].num6);
                        $("span[square_type='13'][num='num3']").html(res[0].num7);
                        $("span[square_type='14'][num='num1']").html(res[0].num4);
                        $("span[square_type='14'][num='num2']").html(res[0].num5);
                        getPileFoundationDetection_1(1, res[0]);
                    }
                },
                error: res => {
                    console.log('fail:', res)
                }
            })
            $.ajax({
                url: baseUrl + '/ajax/GetStationCollect.ashx?type=14',
                dataType: "jsonp",
                async: false,

                jsonp: 'jsonCallBack',
                headers: {
                    'Content-Type': 'application/json;charset=UTF-8'
                },
                success: res => {
                    var datasource = res;
                    if ($(this).text() == '本月') {
                        $("span[square_type='14'][num='num1']").text(datasource[0].num1);
                        $("span[square_type='14'][num='num2']").text(datasource[0].num2);
                    } else {
                        $("span[square_type='14'][num='num1']").html(datasource[0].num6);
                        $("span[square_type='14'][num='num2']").html(datasource[0].num7);
                    }
                },
                error: res => {
                    console.log('fail:', res)
                }
            })

        })
        // 钢结构切换
    $('#stjy1').click(function() {
            if ($('#stjy1 .status').text() == '本月') {
                $('#stjy1 .status').text('本年');
                // 年数据
                // 无损
                $.ajax({
                        url: 'baseUrl/ajax/GetStationCollect.ashx?type=19',
                        dataType: "jsonp",
                        async: false,

                        jsonp: 'jsonCallBack',
                        headers: {
                            'Content-Type': 'application/json;charset=UTF-8'
                        },
                        success: res => {
                            var datasource = res;
                            $("span[square_type='19'][num='num1']").text(datasource[0].num4);
                            $("span[square_type='19'][num='num2']").text(datasource[0].num5);
                            $("span[square_type='19'][num='num3']").text(datasource[0].num6);
                            getSiteStructureTest1(1, datasource[0]);
                        }
                    })
                    // 涂装检测
                $.ajax({
                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=20',
                    dataType: "jsonp",
                    async: false,

                    jsonp: 'jsonCallBack',
                    headers: {
                        'Content-Type': 'application/json;charset=UTF-8'
                    },
                    success: res => {
                        var datasource = res;
                        $("span[square_type='20'][num='num1']").text(datasource[0].num4);
                        $("span[square_type='20'][num='num2']").text(datasource[0].num5);
                        $("span[square_type='20'][num='num3']").text(datasource[0].num6);
                        getSiteStructureTest2(1, datasource[0]);
                    }
                })
            } else {
                $('#stjy1 .status').text('本月');
                // 月数据
                $.ajax({
                        url: 'baseUrl/ajax/GetStationCollect.ashx?type=19',
                        dataType: "jsonp",
                        async: false,

                        jsonp: 'jsonCallBack',
                        headers: {
                            'Content-Type': 'application/json;charset=UTF-8'
                        },
                        success: res => {
                            var datasource = res;
                            $("span[square_type='19'][num='num1']").text(datasource[0].num1);
                            $("span[square_type='19'][num='num2']").text(datasource[0].num2);
                            $("span[square_type='19'][num='num3']").text(datasource[0].num3);
                            getSiteStructureTest1(0, datasource[0]);
                        }
                    })
                    // 涂装检测
                $.ajax({
                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=20',
                    dataType: "jsonp",
                    async: false,

                    jsonp: 'jsonCallBack',
                    headers: {
                        'Content-Type': 'application/json;charset=UTF-8'
                    },
                    success: res => {
                        var datasource = res;
                        $("span[square_type='20'][num='num1']").text(datasource[0].num1);
                        $("span[square_type='20'][num='num2']").text(datasource[0].num2);
                        $("span[square_type='20'][num='num3']").text(datasource[0].num3);
                        getSiteStructureTest2(0, datasource[0]);
                    }
                })
            }
        })
        // 市政工程切换
    $('#stjy2').click(function() {
            if ($('#stjy2 .status').text() == '本月') {
                $('#stjy2 .status').text('本年');
                // 市政工程
                // 弯沉
                $.ajax({
                        url: 'baseUrl/ajax/GetStationCollect.ashx?type=21',
                        dataType: "jsonp",
                        async: false,

                        jsonp: 'jsonCallBack',
                        headers: {
                            'Content-Type': 'application/json;charset=UTF-8'
                        },
                        success: res => {
                            var datasource = res;
                            $("span[square_type='21'][num='num1']").text(datasource[0].num4);
                            $("span[square_type='21'][num='num2']").text(datasource[0].num5);
                            $("span[square_type='21'][num='num3']").text(datasource[0].num6);
                            getSiteEnergyTest1(1, datasource[0]);
                        }
                    })
                    // 路面厚度
                $.ajax({
                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=22',
                    dataType: "jsonp",
                    async: false,

                    jsonp: 'jsonCallBack',
                    headers: {
                        'Content-Type': 'application/json;charset=UTF-8'
                    },
                    success: res => {
                        var datasource = res;
                        $("span[square_type='22'][num='num1']").text(datasource[0].num4);
                        $("span[square_type='22'][num='num2']").text(datasource[0].num5);
                        $("span[square_type='22'][num='num3']").text(datasource[0].num6);
                        getSiteEnergyTest2(1, datasource[0]);
                    }
                })
            } else {
                $('#stjy2 .status').text('本月');
                // 弯沉
                $.ajax({
                        url: 'baseUrl/ajax/GetStationCollect.ashx?type=21',
                        dataType: "jsonp",
                        async: false,

                        jsonp: 'jsonCallBack',
                        headers: {
                            'Content-Type': 'application/json;charset=UTF-8'
                        },
                        success: res => {
                            var datasource = res;
                            $("span[square_type='21'][num='num1']").text(datasource[0].num1);
                            $("span[square_type='21'][num='num2']").text(datasource[0].num2);
                            $("span[square_type='21'][num='num3']").text(datasource[0].num3);
                            getSiteEnergyTest1(0, datasource[0]);
                        }
                    })
                    // 路面厚度
                $.ajax({
                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=22',
                    dataType: "jsonp",
                    async: false,

                    jsonp: 'jsonCallBack',
                    headers: {
                        'Content-Type': 'application/json;charset=UTF-8'
                    },
                    success: res => {
                        var datasource = res;
                        $("span[square_type='22'][num='num1']").text(datasource[0].num1);
                        $("span[square_type='22'][num='num2']").text(datasource[0].num2);
                        $("span[square_type='22'][num='num3']").text(datasource[0].num3);
                        getSiteEnergyTest2(0, datasource[0]);
                    }
                })
            }
        })
        // 检测企业分析情况
    $('#jcqy div').click(function() {
            $('#jcqy div').removeClass('active-tab');
            $(this).addClass('active-tab');
            if ($(this).text() == '本月') {
                get_rt1(0);
                get_rt2(0);
            } else {
                get_rt1(1);
                get_rt2(1);
            }
        })
        // 行为监管情况
    $('#xwjgqk').click(function() {
            if ($('#xwjgqk .status').text() == '本月') {
                $('#xwjgqk .status').text('本年');
            } else {
                $('#xwjgqk .status').text('本月');
            }
        })
        // 两材两块
    $('#lclk div').click(function() {
            $('#lclk div').removeClass('active-tab');
            $(this).addClass('active-tab');

            var data1, data2, data3;
            if ($(this).text() == '本月') {
                $.ajax({
                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=23',
                    dataType: "jsonp",
                    async: false,

                    jsonp: 'jsonCallBack',
                    headers: {
                        'Content-Type': 'application/json;charset=UTF-8'
                    },
                    success: res => {
                        data1 = res;
                        $("span[square_type='23'][num='num1']").text(data1[0].num1);
                        $("span[square_type='23'][num='num2']").text(data1[0].num2);
                        $.ajax({
                            url: 'baseUrl/ajax/GetStationCollect.ashx?type=24',
                            dataType: "jsonp",
                            async: false,

                            jsonp: 'jsonCallBack',
                            headers: {
                                'Content-Type': 'application/json;charset=UTF-8'
                            },
                            success: res => {
                                data2 = res;
                                $("span[square_type='24'][num='num1']").text(data2[0].num1);
                                $("span[square_type='24'][num='num2']").text(data2[0].num2);
                                $.ajax({
                                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=25',
                                    dataType: "jsonp",
                                    async: false,

                                    jsonp: 'jsonCallBack',
                                    headers: {
                                        'Content-Type': 'application/json;charset=UTF-8'
                                    },
                                    success: res => {
                                        data3 = res;
                                        $("span[square_type='25'][num='num1']").text(data3[0].num1);
                                        $("span[square_type='25'][num='num2']").text(data3[0].num2);
                                        getlclkInfo(0, data1[0], data2[0], data3[0]);
                                    }
                                })
                            }
                        })
                    }
                })

            } else {
                // 本年
                $.ajax({
                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=23',
                    dataType: "jsonp",
                    async: false,

                    jsonp: 'jsonCallBack',
                    headers: {
                        'Content-Type': 'application/json;charset=UTF-8'
                    },
                    success: res => {
                        data1 = res;
                        $("span[square_type='23'][num='num1']").text(data1[0].num4);
                        $("span[square_type='23'][num='num2']").text(data1[0].num5);
                    }
                })
                $.ajax({
                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=24',
                    dataType: "jsonp",
                    async: false,

                    jsonp: 'jsonCallBack',
                    headers: {
                        'Content-Type': 'application/json;charset=UTF-8'
                    },
                    success: res => {
                        data2 = res;
                        $("span[square_type='24'][num='num1']").text(data2[0].num4);
                        $("span[square_type='24'][num='num2']").text(data2[0].num5);
                    }
                })
                $.ajax({
                    url: 'baseUrl/ajax/GetStationCollect.ashx?type=25',
                    dataType: "jsonp",
                    async: false,

                    jsonp: 'jsonCallBack',
                    headers: {
                        'Content-Type': 'application/json;charset=UTF-8'
                    },
                    success: res => {
                        data3 = res;
                        $("span[square_type='25'][num='num1']").text(data3[0].num4);
                        $("span[square_type='25'][num='num2']").text(data3[0].num5);
                    }
                })
            }
        })
        // 监督检测情况
    $('#jdjc').click(function() {
        if ($('#jdjc .status').text() == '本月') {
            $('#jdjc .status').text('本年');
        } else {
            $('#jdjc .status').text('本月');
        }
    })

    // 现场照片导航栏切换
    $('#zjjc-picView-popup .popup-sub-menu p').click(function() {
        $('#zjjc-picView-popup .popup-sub-menu p').removeClass('active');
        $(this).addClass('active');
        let id = $(this).attr('data-id');
        $('#zjjc-picView-popup .table-content').addClass('hidden');
        $('#zjjc-picView-popup .'+id).removeClass('hidden');
    })

    // 视频监控切换
    $('#spjk-popup .right-item .img-item').click(function() {
        $('#spjk-popup .right-item .img-item').removeClass('active');
        $(this).addClass('active');
    })
})

function mapHandle(type) {
    if (type == 0) {
        getMapData_people();
        $('.left-bar').addClass('activeImg');
        $('.left-bar').removeClass('negativeImg');
        $('.right-bar').addClass('negativeImg');
        $('.right-bar').removeClass('activeImg');
        $('.right-bar2').addClass('negativeImg');
        $('.right-bar2').removeClass('activeImg');
        $('.map-legend').addClass('hidden');
    } else if(type == 1){
        getMapData_room();
        $('.left-bar').addClass('negativeImg');
        $('.left-bar').removeClass('activeImg');
        $('.right-bar').addClass('activeImg');
        $('.right-bar').removeClass('negativeImg');
        $('.right-bar2').addClass('negativeImg');
        $('.right-bar2').removeClass('activeImg');
        $('.map-legend').removeClass('hidden');
    } else if(type == 2){
        getMapData_ZJJC();
        $('.left-bar').addClass('negativeImg');
        $('.left-bar').removeClass('activeImg');
        $('.right-bar').addClass('negativeImg');
        $('.right-bar').removeClass('activeImg');
        $('.right-bar2').addClass('activeImg');
        $('.right-bar2').removeClass('negativeImg');
        $('.map-legend').addClass('hidden');
    }
}

function closePopup() {
    $('.popup').addClass('hidden');
}
var other_pageIndex = 1,
    other_pageSize = 12,
    jcitem_val = '',
    projectname_val = '',
    jcunit_val = '',
    unq_id = '';
// 展示不合格列表
function showPop(id) {
    $('.popup').removeClass('hidden');
    $('.other-box').removeClass('hidden');
    $('.service-box').addClass('hidden');
    $('.map-box').addClass('hidden');
    $('.popup-title').text('不合格列表');
    unq_id = id;
    getOtherList(id, other_pageIndex, other_pageSize, jcitem_val, projectname_val, jcunit_val);
}
// 其他列表 查询按钮
function otherSearch(type) {
    other_pageIndex = 1;
    jcitem_val = $('#jcitem_val').val();
    projectname_val = $('#projectname_val').val();
    jcunit_val = $('#jcunit_val').val();
    getOtherList(unq_id, other_pageIndex, other_pageSize, jcitem_val, projectname_val, jcunit_val);
}

function videoConect(receiver_op_code) {
    // var op_code = "hzcs";
    //console.log('op_code:' + receiver_op_code);
    //$('#div_video').removeClass('hidden');
    //$('#video').attr("src", "/VideoConnection.aspx?target_op_code=" + receiver_op_code);
    window.open('https://detect.cnjsjd.net/VideoConnection.aspx?target_op_code='+encodeURIComponent(receiver_op_code));
}

function closevideo() {
    $('.popup').addClass('hidden');
    $('#video').attr("src", "");
}
// 放大地图
function biggerMap() {
    if ($('.sizingmap').hasClass('icon-fangda-icon-2-2')) {
        $('.map-outer').addClass('bigMap');
    } else {
        $('.map-outer').removeClass('bigMap');
    }
    $('.sizingmap').toggleClass('icon-suoxiao-3-2').toggleClass('icon-fangda-icon-2-2');
}
var map_pageIndex = 1,
    map_pageSize = 12,
    customer_type = '',
    status = '',
    customer_name = '';
// 显示地图legend点击效果
function handle(customer_type, name) {
    $('.popup').removeClass('hidden');
    $('.service-box').addClass('hidden');
    $('.other-box').addClass('hidden');
    $('.map-box').removeClass('hidden');
    $('.popup-title').text(name);
    console.log('点击 legend customer_type:', customer_type);
    getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
    if (customer_type == 10) {
        console.log('工地')
        $("#mapKind").find("option[value='0']").attr("selected", true);
        $("#mapKind").find("option[value='1']").attr("selected", false);
    } else if (customer_type == 2) {
        console.log('检测')
        $("#mapKind").find("option[value='1']").attr("selected", true);
        $("#mapKind").find("option[value='0']").attr("selected", false);
    }
}
// 切换类别
function changeKind() {
    map_pageIndex = 1;
    let val = $("#mapKind").find("option:selected").val();
    console.log('切换类别:', val)
    console.log('工地/检测标养室:', val);
    if (val == 0) {
        customer_type = 10;
        getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
    } else if (val == 1) {
        customer_type = 2;
        getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
    }
}
// 切换状态
function changeStatus() {
    map_pageIndex = 1;
    let val = $("#mapStatus").find("option:selected").val();
    if (val == 0) {
        status = 0; // 在线
        getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
    } else if (val == 1) {
        status = 1; // 离线
        getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
    }
}
// 地图搜索按钮
function mapSearch() {
    customer_name = $('#customer_name').val();
    map_pageIndex = 1;
    let val = $("#mapKind").find("option:selected").val();
    let customer_type;
    if (val == 0) {
        customer_type = 10;
    } else if (val == 1) {
        customer_type = 2
    }
    getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
}
// 地图下方各个按钮
function btnHandle(type, index) {
    let val = $("#mapKind").find("option:selected").val();
    console.log('val:', val)
    if (val == 0) {
        customer_type = 10;
    } else if (val == 1) {
        customer_type = 2;
    }
    if (type == 'map') { //地图
        if (index == 0) { // 首页
            map_pageIndex = 1;
            getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
        } else if (index == 1) { //上一页
            if (map_pageIndex > 1) {
                map_pageIndex -= 1;
                getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
            }
        } else if (index == 2) { //下一页
            if (map_pageIndex < $('.map_total_page').html()) {
                map_pageIndex += 1;
                getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
            }
        } else if (index == 3) { //尾页
            map_pageIndex = $('.map_total_page').html();
            getMapList($('.map_total_page').html(), map_pageSize, customer_type, status, customer_name);
        } else if (index == 4) { // 搜索
            if ($('#map_page_index').val() <= $('.map_total_page').html()) {
                map_pageIndex = $('#map_page_index').val();
                getMapList(map_pageIndex, map_pageSize, customer_type, status, customer_name);
            }
        }
    } else if (type == 'other') { //其他不合格
        if (index == 0) {
            other_pageIndex = 1;
            getOtherList(unq_id, other_pageIndex, other_pageSize, jcitem_val, projectname_val, jcunit_val);
        } else if (index == 1) {
            if (other_pageIndex > 1) {
                other_pageIndex -= 1;
                getOtherList(unq_id, other_pageIndex, other_pageSize, jcitem_val, projectname_val, jcunit_val);
            }
        } else if (index == 2) {
            if (other_pageIndex < $('.other_total_count').html()) {
                other_pageIndex += 1;
                getOtherList(unq_id, other_pageIndex, other_pageSize, jcitem_val, projectname_val, jcunit_val);
            }
        } else if (index == 3) { // 末页
            other_pageIndex = $('.other_total_page').html();
            getOtherList(unq_id, other_pageIndex, other_pageSize, jcitem_val, projectname_val, jcunit_val);
        } else if (index == 4) {
            if ($('#other_page_index').val() <= $('.other_total_page').html()) {
                other_pageIndex = $('#other_page_index').val();
                getOtherList(unq_id, other_pageIndex, other_pageSize, jcitem_val, projectname_val, jcunit_val);
            }
        }
    } else if (type == 'service') {
        if (index == 0) {
            service_pageIndex = 1;
            getServiceList(service_pageIndex, service_pageSize, service_customer);
        } else if (index == 1) {
            if (service_pageIndex > 1) {
                service_pageIndex -= 1;
                getServiceList(service_pageIndex, service_pageSize, service_customer);
            }
        } else if (index == 2) {
            if (service_pageIndex < $('.service_total_page').html()) {
                service_pageIndex += 1;
                getServiceList(service_pageIndex, service_pageSize, service_customer);
            }
        } else if (index == 3) { // 末页
            service_pageIndex = $('.service_total_page').html();
            getServiceList(service_pageIndex, service_pageSize, service_customer);
        } else if (index == 4) {
            if ($('#service_page_index').val() <= $('.service_total_page').html()) {
                service_pageIndex = $('#service_page_index').val();
                getServiceList(service_pageIndex, service_pageSize, service_customer);
            }
        }
    }
}
var service_pageIndex = 1,
    service_pageSize = 12,
    service_customer = '';
// 开展服务
function showService() {
    $('.popup').removeClass('hidden');
    $('.service-box').removeClass('hidden');
    $('.other-box').addClass('hidden');
    $('.map-box').addClass('hidden');
    $('.popup-title').text('开展服务');
    getServiceList(service_pageIndex, service_pageSize, service_customer);
}
// 开展服务搜索按钮
function serviceSearch() {
    service_customer = $('#jcunit_val2').val();
    getServiceList(service_pageIndex, service_pageSize, service_customer);
}

// 桩基检测
function show_picView_Popup(SceneTask_id){
    $("#zjjc-picView-popup").removeClass('hidden');
    $('#zjjc-picView-popup .popup-sub-menu p').removeClass('active');
    $('#zjjc-picView-popup .popup-sub-menu p:first-child').addClass('active');
    $('#zjjc-picView-popup .table-content').addClass('hidden');
    $('#zjjc-picView-popup .content1').removeClass('hidden');
    get_scxczp(SceneTask_id);
    get_xcjl(SceneTask_id);
    get_zpzp(SceneTask_id);
}

// 首次现场图像弹窗
function get_scxczp(id){
    $.ajax({
        url: baseUrl + '/ajax/ZJJC/GetStationZJJC.ashx?id='+id+'&type=photo_list&kind=0',
        dataType: "jsonp",
        async: false,

        jsonp: 'jsonCallBack',
        headers: {
            'Content-Type': 'application/json;charset=UTF-8'
        },
        success: function(res) {
            console.log('首次现场图像:', res)
            $('#zjjc-picView-popup .content1 .img-list').html('');
            if(res.length > 0){
                for(var i=0; i<res.length; i++){
                    if(res[i].file_ext == '.map'){
                        $('#zjjc-picView-popup .content1 .img-list').append(`
                            <div class="img-group" onclick="picView('${res[i].file_path}','${res[i].file_ext}')">
                                <div class="img"><video src="${res[i].file_path}"></video></div>
                                <div class="name">${res[i].text}</div>
                            </div>
                        `);
                    }else{
                        $('#zjjc-picView-popup .content1 .img-list').append(`
                            <div class="img-group" onclick="picView('${res[i].file_path}','${res[i].file_ext}')">
                                <div class="img"><img src="${res[i].file_path}" ></div>
                                <div class="name">${res[i].text}</div>
                            </div>
                        `);
                    }
                }
            }else{
                $('#zjjc-picView-popup .content1 .img-list').html('<p>暂无数据!</p>');
            }
        },
        error: function(res) {
            console.log('fail:', res)
        }
    });
}

// 现场记录弹窗
function get_xcjl(id){
    $.ajax({
        url: baseUrl + '/ajax/ZJJC/GetStationZJJC.ashx?id='+id+'&type=photo_list&kind=1',
        dataType: "jsonp",
        async: false,

        jsonp: 'jsonCallBack',
        headers: {
            'Content-Type': 'application/json;charset=UTF-8'
        },
        success: function(res) {
            console.log('首次现场图像:', res)
            if(res.length > 0){
                $('#zjjc-picView-popup .content2 .timeAxis-group').html('');
                const sorted =groupBy(res, function (item) {
                    return [item.create_time];//按照name进行分组
                });
                var HTML = '';
                for(var i=0; i<sorted.length; i++){
                    HTML += 
                    '<div class="timeAxis">'+
                    '   <div class="date">'+sorted[i][0].create_time+'</div>'+
                    '   <div class="img-list">';
                        for(var j=0; j<sorted[i].length;j++){
                            if(sorted[i][j].file_ext == '.map'){
                            HTML += 
                            '   <div class="img-group" style="width:calc(25% - 2rem)" onclick="picView(\''+sorted[i][j].file_path+'\',\''+sorted[i][j].file_ext+'\')">'+
                            '       <div class="img"><div><video src="'+sorted[i][j].file_path+'" /></div></div>'+
                            '       <div class="name">'+sorted[i][j].text+'</div>'+
                            '   </div>';
                            }else{
                            HTML += 
                            '   <div class="img-group" style="width:calc(25% - 2rem)" onclick="picView(\''+sorted[i][j].file_path+'\',\''+sorted[i][j].file_ext+'\')">'+
                            '       <div class="img"><div><img src="'+sorted[i][j].file_path+'" ></div></div>'+
                            '       <div class="name">'+sorted[i][j].text+'</div>'+
                            '   </div>';
                            }
                        }
                    HTML += '</div>'+
                    '</div>';
                }
                $('#zjjc-picView-popup .content2 .timeAxis-group').html(HTML);
            }else{
                $('#zjjc-picView-popup .content2 .timeAxis-group').html('<p>暂无数据!</p>');
            }
        },
        error: function(res) {
            console.log('fail:', res)
        }
    });
}

function  groupBy(array, f){
    debugger;
    const groups = {};        
    array.forEach(function (o) { //注意这里必须是forEach 大写
        const group = JSON.stringify(f(o));
        groups[group] = groups[group] || [];
        groups[group].push(o);
    });
    return Object.keys(groups).map(function (group) {
        return groups[group];
    }); 
}    

// 抓拍照片弹窗
function get_zpzp(id){
    $('#zjjc-picView-popup .content3 .img-list').html('');
    $('#zjjc-picView-popup .content3 .img-list').html('<p>暂无数据!</p>');
}

function closexczp(){
    $("#zjjc-picView-popup").addClass('hidden');
}

//视频监控
function show_spjk_popup(id){
    $("#spjk-popup").removeClass('hidden');
    $('#spjk-popup .right-item .img-item').removeClass('active');
    $('#spjk-popup .right-item .img-item:first-child').addClass('active');
    console.log(id);
    $.ajax({
        url: baseUrl + '/ajax/ZJJC/GetStationZJJC.ashx?type=equ_list&id='+id,
        dataType: "jsonp",
        async: false,

        jsonp: 'jsonCallBack',
        headers: {
            'Content-Type': 'application/json;charset=UTF-8'
        },
        success: function(res) {
            console.log('视频监控:', res);
            $('#spjk-popup .table-content .right-item .img-List').html('');
            if(res.length>0){
                $('#spjk-popup .table-content .left-item').html('<iframe src="http://apiservice.zjszsk.com/api/LiveServicePlay/'+res[0].resource_code+'" frameborder="0" class="isScroll"></iframe>');
                for(var i=0; i<res.length; i++){
                    $('#spjk-popup .table-content .right-item .img-List').append(`
                        <div class="img-item" onclick="check_spjk('${res[i].resource_code}')">
                            <div class="name">${res[i].Equipment_no}</div>
                        </div>
                    `);
                }
                $('#spjk-popup .table-content .right-item .img-List .img-item:first-child').addClass('active');
            }else{
                $('#spjk-popup .table-content .left-item').html('<p>暂无数据!</p>');
                $('#spjk-popup .table-content .right-item .img-List').html('<p>暂无数据!</p>');
            }
        },
        error: function(res) {
            console.log('fail:', res)
        }
    });
}

// 视频监控切换
function check_spjk(resource_code){
    $('#spjk-popup .table-content .left-item').html('<iframe src="http://apiservice.zjszsk.com/api/LiveServicePlay/'+resource_code+'" frameborder="0" class="isScroll"></iframe>');
}

function closespjk(){
    $("#spjk-popup").addClass('hidden');
}

// 图像预览
function picView(file_path, file_ext) {
    $('#pic-view-popup').removeClass('hidden');
    if(file_ext == '.map'){
        $("#pic-view-popup .table-content").html('<video src="'+file_path+'" />')
    }else{
        $("#pic-view-popup .table-content").html('<img src="'+file_path+'" />')
    }
}

function close_picView() {
    $('#pic-view-popup').addClass('hidden');
}