/*全局自适应高度*/
function autoFlashHeight(){
    let headerHeight = $(".header").height();
    let toolsbarHeight = $(".toolsbar").height();
    let ftoolsbarHeight = $(".toolsbar-f").height();
    let btntoolsbarHeight = $(".btn-toolbar").height();
    // var feeRateToolsbarHeight = $(".toolsbar_feeRate").height();
    let toolsBarHeightQ = $(".tools-bar-height-q").height();
    let toolsBarHeightD = $(".tools-bar-height-d").height();
    let toolsBarHeightZ = $(".tools-bar-height-z").height();
    //$(".main-data-side-q").height($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightQ-302);
    $(".main-data-side-q").height($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightQ-$('#qd').find('.bottom-content').find('.p-0').height()-5);
    //$(".main-data-side-d").height($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightD-302);
    $(".main-data-side-d").height($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightD-$('#stdSectionRations').height()-5);
    $(".main-data-side-zb").height(($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightZ));
    /*$(".main-data-side-zi").height($(window).height()-headerHeight-toolsbarHeight- toolsBarHeightZ - $(".main-data-side-zb").height());*/
    $('.main-content').width($(window).width()-$('.main-nav').width()-$('.main-side').width()-5);
    $('#glj_tree_div .modal-content').width($(window).width() < 1020 + 20 ? $(window).width() - 20 : 1020);
    //$("#main .main-data-top").height($(window).height()-headerHeight-toolsbarHeight-bottomContentHeight-1);
    $(".main-data-full").height($(window).height()-headerHeight-toolsbarHeight-1);
    $(".main-data-full-fl").height($(window).height()-headerHeight-toolsbarHeight-37);
    $(".main-data-full-feeRate").height($(window).height()-headerHeight-78);
    $(".main-data-full-tender").height($(window).height()-headerHeight-btntoolsbarHeight-10);
    $(".main-data-not").height($(window).height()-headerHeight-1);
    $(".main-data-side-search").height($(window).height()-headerHeight-toolsbarHeight-64);
    $(".side-content").height($(window).height()-headerHeight );
    $(".poj-list").height($(window).height()-headerHeight-toolsbarHeight);
    $(".gc-list").height($(window).height()-headerHeight-toolsbarHeight-40);
    $(".share-list").height($(window).height()-headerHeight-toolsbarHeight-40);
    $(".form-view").height($(window).height()-headerHeight-ftoolsbarHeight);
    $(".form-list").height($(window).height()-headerHeight);
    $('#comments').find('textarea').height($('#comments').height() - 25);
    $('#project-glj-main').width($(window).width()-($('.main-nav').width()+ 2));//-($('.filterType').width()+12)-5); //2、12是padding宽度，width 是不算padding宽度的
    $('#project_glj_sheet').width($('#project-glj-main').width()-($('.filterType').width())-1)//1是border宽度,width 是不算padding和border宽度的
    typeof(loadProjectGljSize)== 'function'?loadProjectGljSize():'';
    typeof(loadMainSize)== 'function' ?loadMainSize():'';//zhang 2018-06-04  统一加载高度方法
    //typeof zmhs_obj === 'object' ? zmhs_obj.loadSideResize() : '';
};



/*全局自适应高度结束*/
$(function () {
    //拖动头部
    $('body').on("show.bs.modal", ".modal", function(){
        if (typeof  $(this).find('.modal-content').draggable === 'function') {
            $(this).find('.modal-content').draggable({handle: '.modal-header', cancel: 'a, button'});
        }
    });
    $(window).resize(autoFlashHeight);
    /*侧滑*/
  /*  $(".open-sidebar").click(function () {
        $(".slide-sidebar").animate({width: "800"}).addClass("open");
    });
    $("body").click(function (event) {
        var e = event || window.event; //浏览器兼容性
        if (!$(event.target).is('a')) {
            var elem = event.target || e.srcElement;
            while (elem) { //循环判断至跟节点，防止点击的是div子元素
                if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
                    return false;
                }
                elem = elem.parentNode;
            }
            $(".slide-sidebar").animate({width: "0"}).removeClass("open")// 关闭处理
        }

    });*/
    /*侧滑*/
    /*工具提示*/
    $(function () {
        $('[data-toggle="tooltip"]').tooltip();
        if( $('[data-submenu]').submenupicker) $('[data-submenu]').submenupicker();
        $('[data-toggle="tooltip"]').click(function () {
            $(this).tooltip('hide');
        })
    });

});

/**
 * 设置本地缓存
 *
 * @param {String} key
 * @param {String|Number} value
 * @return {void}
 */
let storageErrCount = 0;
function setLocalCache(key, value) {
    const storage = window.localStorage;
    if (!storage || key === '' || value === '') {
        return;
    }
    try {
        storage.setItem(key, value);
        storageErrCount = 0;
    } catch (err) {
        storageErrCount++;
        if (storageErrCount > 1) {
            alert(`字段“${key}”数据过大，存入本地缓存失败。`)
            storageErrCount = 0;
            return;
        }
        storage.clear();
        setLocalCache(key, value);
    }
}

/**
 * 获取本地缓存
 *
 * @param {String} key
 * @return {String}
 */
function getLocalCache(key) {
    const storage = window.localStorage;
    if (!storage || key === '') {
        return null;
    }

    return storage.getItem(key);
}

function removeLocalCache(key) {
    const storage = window.localStorage;
    if (!storage || key === '') {
        return null;
    }
    return storage.removeItem(key);
}

function getFormatter(decimal) {
    var pre = "0.";
    if (decimal <= 0) {
        return "0";
    }
    for (let i = 0; i < decimal; i++) {
        pre += "0"
    }
    return pre;
}

function getFeeIndex(fees) {
    let feesIndex = {};
    if (fees) {
        for(let fee of fees){
            const parsedUnitFee = parseFloat(fee.unitFee);
            const parsedTotalFee = parseFloat(fee.totalFee);
            const parsedTenderUnitFee = parseFloat(fee.tenderUnitFee);
            const parsedTenderTotalFee = parseFloat(fee.tenderTotalFee);
            fee.unitFee = parsedUnitFee || 0;
            fee.totalFee = parsedTotalFee || 0;
            fee.tenderUnitFee = parsedTenderUnitFee || 0;
            fee.tenderTotalFee = parsedTenderTotalFee || 0;
            feesIndex[fee.fieldName] = fee;
        }
    }
    return feesIndex;
}

function replaceAll(FindText, RepText,str) {
    let regExp = new RegExp(FindText, "g");
    return str.replace(regExp, RepText);
};

function setTimeoutSync(handle, time) {
    return new Promise(function(resolve, reject) {
        setTimeout(function () {
            if (handle && typeof handle === 'function') {
                handle();
            }
            resolve();
        }, time);
    });
}

async function progressStart(title,autoProgress = false){

}

