// // 自适应
var designW = 1920;
var font_rate = 100;
document.getElementsByTagName("html")[0].style.fontSize = document.body.offsetWidth / designW *
    font_rate + "px";
document.getElementsByTagName("body")[0].style.fontSize = document.body.offsetWidth / designW *
    font_rate + "px";
// //监测窗口大小变化
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() {
    document.getElementsByTagName("html")[0].style.fontSize = document.body.offsetWidth /
        designW * font_rate + "px";
    document.getElementsByTagName("body")[0].style.fontSize = document.body.offsetWidth /
        designW * font_rate + "px";
}, false);

const URL = '/';
const baseURL = '/Ajax/Screen/';
const videoURL = '/Ajax/Screen/Pile/';
var publicData = {
    province: '',
    xy: [],
    area: '',
    op_name: '',
};
function getHead(){
    $("#header").html(`<div class="title" id="headTop">${publicData.unit_name}</div>
    <div class="flex-item" id="tab">
        <div class="item" onclick="checkPage('zjjc')"><div>桩基检测</div></div>
        <div class="item" onclick="checkPage('xcjc')"><div>现场检测</div></div>
    </div>
    <div class="right-item">
        <div class="date" id="hdate">2023年3月11号  星期一</div>
        <div class="select-item htgl">
            <div onclick="back()">后台管理</div>
        </div>
        <div class="select-item">
            <div id="hselect" class="hselect">${publicData.op_name}</div>
        </div>
    </div>`);

    layui.use('dropdown', function() {
        var dropdown = layui.dropdown
        dropdown.render({
            elem: '#hselect' ,
            data: [
                {title: publicData.op_name, id: 1}, 
                {title: '退出登录', id: 2}
            ],
            click: function(obj) {
                hselect.value = obj.title
                if(obj.id == 2){
                    window.location.href="/LoginDirect.aspx"
                }
            }
        });
    });
}

function getHeadData(){
	return new Promise(resolve => {
        $.ajax({
            url: baseURL+'GetHeaderInfo.ashx',
            type: "post",
            success: function(data) {
                data =  JSON.parse(data);
                publicData.province = data.data[0].unit_area;
                publicData.area = data.data[0].area;
                publicData.xy = [data.data[0].mapx, data.data[0].mapy]
                publicData.op_name = data.data[0].op_name;
                publicData.unit_name = data.data[0].unit_name;
                getHead();
                getDateTimeWeek()
                resolve();
            },
            error: function(jqXHR) {
                console.log("发生错误：" + jqXHR.status);
            }
        })
    })
}

function getDate(){
    var d = new Date();
    var day =d.getDate();
    
    if(d.getMonth()<10){
        var month = "0"+(d.getMonth()+1);
    }
    
    if(d.getDate()<10){
        day = "0"+d.getDate();
    }
    
    var datew = d.getFullYear()+"-"+month+"-"+day;
    var datew = datew.toString();
    return datew;
}

function getMonth(){
    var d = new Date();
    var day =d.getDate();
    
    if(d.getMonth()<10){
        var month = "0"+(d.getMonth()+1);
    }
    
    var datew = d.getFullYear()+"-"+month;
    var datew = datew.toString();
    return datew;
}

function getDateTimeWeek(){
    var today=new Date();//定义日期对象   
    var yyyy = today.getFullYear();//获取年    
    var MM = today.getMonth()+1;//通获取月  
    var dd = today.getDate();//获取日     
    var hh=today.getHours();//获取小时   
    var mm=today.getMinutes();//获取分钟   
    var ss=today.getSeconds();//获取秒

    //获取星期				
    var day;
    if(today.getDay()==0)   day   =   "星期日 " 
    if(today.getDay()==1)   day   =   "星期一 " 
    if(today.getDay()==2)   day   =   "星期二 " 
    if(today.getDay()==3)   day   =   "星期三 " 
    if(today.getDay()==4)   day   =   "星期四 " 
    if(today.getDay()==5)   day   =   "星期五 " 
    if(today.getDay()==6)   day   =   "星期六 " 
    $("#hdate").html(`${yyyy}年${MM}月${dd}号&nbsp;&nbsp;&nbsp;${day}`);

    //动态时间加载  
    setTimeout('getDateTimeWeek()',10000);
}

function back(){
    window.location.href="/Main.aspx?from=screen"
}

function checkPage(params) {
    window.location.href="./"+params+".html"
}

window._AMapSecurityConfig = {
    securityJsCode: '0711374220aba81dbf7515aaac08e50b',
}

// layui.use(['layer', 'laydate'],function(){
//     var layer=layui.layer;
// });