//获取表单token,防止表单重复提交
function setFormToken(){
    $.ajax({
        type:'get',
        url:path+"/contant/getUuid",
        async:false,
        dataType:'json',
        success:function(data){
            if(data != null){
                $("#formToken").val(data);
                $("#formToken1").val(data);
            }
        }
    })
}
    jQuery(function ($) {
    //解决模态框背景色越来越深的问题
    $(document).on('show.bs.modal', '.modal', function (event) {
        $(this).appendTo($('body'));
    }).on('shown.bs.modal', '.modal.in', function (event) {
        setModalsAndBackdropsOrder();
    }).on('hidden.bs.modal', '.modal', function (event) {
        setModalsAndBackdropsOrder();
    });

    function setModalsAndBackdropsOrder() {
        var modalZIndex = 1040;
        $('.modal.in').each(function (index) {
            var $modal = $(this);
            modalZIndex++;
            $modal.css('zIndex', modalZIndex);
            $modal.next('.modal-backdrop.in').addClass('hidden').css('zIndex', modalZIndex - 1);
        });
        $('.modal.in:visible:last').focus().next('.modal-backdrop.in').removeClass('hidden');
    }

    //覆盖Modal.prototype的hideModal方法
    $.fn.modal.Constructor.prototype.hideModal = function () {
        var that = this
        this.$element.hide()
        this.backdrop(function () {
            //判断当前页面所有的模态框都已经隐藏了之后body移除.modal-open，即body出现滚动条。
            $('.modal.fade.in').length === 0 && that.$body.removeClass('modal-open')
            that.resetAdjustments()
            that.resetScrollbar()
            that.$element.trigger('hidden.bs.modal')
        })
    }


    function moveModal($this) {
        var $head = $this.find('.modal-header2');
        var $dialog = $this.find('.modal-dialog');
        var move = {
            isMove: false,
            left: 0,
            top: 0
        };
        //委托
        //console.log('点击的是', $this);
        $this.on('mousemove', function (e) {
            if (!move.isMove) return;
            //console.log('移动的是', e.target);
            $dialog.offset({
                top: e.pageY - move.top,
                left: e.pageX - move.left
            });
        }).on('mouseup', function (e) {
            move.isMove = false;
        });
        $head.on('mousedown', function (e) {
            move.isMove = true;
            var offset = $dialog.offset();
            move.left = e.pageX - offset.left;
            move.top = e.pageY - offset.top;
        });
    }

    var oldModal = $.fn.modal;
    $.fn.modal = function (o, _r) {
        var $this = $(this);
        if (!$this.attr('ifbindmv')) {
            $this.attr('isbindmv', '1');
            moveModal($this);
        }
        return oldModal.call(this, o, _r);
    }
    ////要拖动的div背景
    //$('#showErr').modal({backdrop: 'static'});




});

//设计出院日期的上限 年(年数差) 、月(月数差) 、日（天数差）
//返回两个日期相差的年数
function YearsBetw(date1, date2) { //date1和date2是2019-3-12格式
    //用-分成数组
    date1 = date1.split("-");
    date2 = date2.split("-");
    var year1 = parseInt(date1[0]),
        year2 = parseInt(date2[0]),
        year =  (year2 - year1) ;
    return year;
}
//返回两个日期相差的月数
function MonthsBetw(date1, date2) { //date1和date2是2019-3-12格式
    //用-分成数组
    date1 = date1.split("-");
    date2 = date2.split("-");
    //获取年,月数
    var year1 = parseInt(date1[0]),
        month1 = parseInt(date1[1]),
        year2 = parseInt(date2[0]),
        month2 = parseInt(date2[1]),
        //通过年,月差计算月份差
        months = (year2 - year1) * 12 + (month2 - month1) + 1;
    return months;
}

//计算天数差的函数，通用
function DateDiff(sDate1, sDate2) { //sDate1和sDate2是2019-3-12格式
    var aDate, oDate1, oDate2, iDays
    aDate = sDate1.split("-")
    oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为9-25-2017格式
    aDate = sDate2.split("-")
    oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
    iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数
    return iDays
}

//当前日期
function getCurrDate() {
    var myDate = new Date();
    var nowY = myDate.getFullYear();
    var nowM = myDate.getMonth() + 1;
    var nowD = myDate.getDate();
    var startDateV = nowY + "-" + (nowM < 10 ? "0" + nowM : nowM) + "-" + (nowD < 10 ? "0" + nowD : nowD);
    return startDateV;
}

//获取三十天前日期
function getCurrDay30() {
    var myDate = new Date();
    var lw = new Date(myDate - 1000 * 60 * 60 * 24 * 30);//最后一个数字30可改，30天的意思
    var lastY = lw.getFullYear();
    var lastM = lw.getMonth() + 1;
    var lastD = lw.getDate();
    var startdate30 = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
    return startdate30;
}



