// 用户登录
$('.userloginbtn').on('click',function(){
	$(".userlogin-wrap").show();
})

$('.close-loginbox').on('click',function(){
	$(".userlogin-wrap").hide();
})

$('.userloginbox .login-username').blur(function () {
	var isPassword=$('.userloginbox .login-password').is(":focus");
    if(!isPassword){
    	$(".userlogin-img").hide();
		$(".userlogin-img1").show();
    }
});

$('.userloginbox .login-password').blur(function () {
	var isUsername=$('.userloginbox .login-username').is(":focus");
    if(!isUsername){
    	$(".userlogin-img").hide();
		$(".userlogin-img1").show();
    }
});

$(".showUserLogin").on("click",function(){
	$(".userregister").hide();
	$(".userloginbox").show();
})
$(".showUserRegister").on("click",function(){
	$(".userloginbox").hide();
	$(".userregister").show();
})






/*时间查询*/

function initData(){
    var endTime=getNowFormatDate();
    var beginTime=getPreMonth(endTime);//近1个月
    var beginThreeTime=getPreThMonth(endTime);//近3个月
    var beginSevenDayTime=get7DaysBefore(endTime);//近7天
    beginTime += " 00:00:00";
    beginThreeTime += " 00:00:00";
    beginSevenDayTime+= " 00:00:00";
    endTime += " 23:59:59";
}

function initStrTime(_time){
	if(_time < 10){
		_time = '0'+ _time;
	}

	return _time;
}

// 获取近一周
function get7DaysBefore(date){
    var date = date || new Date(),
        timestamp, newDate;
    if(!(date instanceof Date)){
        date = new Date(date.replace(/-/g, '/'));
    }
    timestamp = date.getTime();
    newDate = new Date(timestamp - 7 * 24 * 3600 * 1000);
    return [[newDate.getFullYear(), initStrTime(newDate.getMonth() + 1), initStrTime(newDate.getDate())].join('-')];
}

//获取昨天的时间
function yestodayTime(data){
    var date = date || new Date(),
        timestamp, newDate;
    if(!(date instanceof Date)){
        date = new Date(date.replace(/-/g, '/'));
    }
    timestamp = date.getTime();
    newDate = new Date(timestamp -  24 * 3600 * 1000);
    return [[newDate.getFullYear(), initStrTime(newDate.getMonth() + 1), initStrTime(newDate.getDate())].join('-')];
}

//获取明天的时间
function tomorrowTime(data){
    var date = date || new Date(),
        timestamp, newDate;
    if(!(date instanceof Date)){
        date = new Date(date.replace(/-/g, '/'));
    }
    timestamp = date.getTime();
    newDate = new Date(timestamp +  24 * 3600 * 1000);
    return [[newDate.getFullYear(), initStrTime(newDate.getMonth() + 1), initStrTime(newDate.getDate())].join('-')];
}


// 获取近一月
function getPreMonth(date) {
    var arr = [];
    var year = null; //获取当前日期的年份
    var month = null; //获取当前日期的月份
    var day = null; //获取当前日期的日
    if(typeof(date) == "string"){
        arr = date.split('-');
        year = arr[0]; //获取当前日期的年份
        month = arr[1]; //获取当前日期的月份
        day = arr[2]; //获取当前日期的日
    }else if(typeof(date) == "date"){
        year = nowDate.getFullYear(); //获取当前日期的年份
        month = nowDate.getMonth(); //获取当前日期的月份
        day = nowDate.getDate(); //获取当前日期的日
    }

    var days = new Date(year, month, 0);
    days = days.getDate(); //获取当前日期中月的天数
    var year2 = year;
    var month2 = parseInt(month) - 1;
    if (month2 == 0) {
        year2 = parseInt(year2) - 1;
        month2 = 12;
    }
    var day2 = day;
    var days2 = new Date(year2, month2, 0);
    days2 = days2.getDate();
    if (day2 > days2) {
        day2 = days2;
    }
    if (month2 < 10) {
        month2 = '0' + month2;
    }
    var t2 = year2 + '-' + month2 + '-' + day2;
    return t2;
}

// 获取近三月
function getPreThMonth(date) {
    var arr = [];
    var year = null; //获取当前日期的年份
    var month = null; //获取当前日期的月份
    var day = null; //获取当前日期的日
    if(typeof(date) == "string"){
        arr = date.split('-');
        year = arr[0]; //获取当前日期的年份
        month = arr[1]; //获取当前日期的月份
        day = arr[2]; //获取当前日期的日
    }else if(typeof(date) == "date"){
        year = nowDate.getFullYear(); //获取当前日期的年份
        month = nowDate.getMonth(); //获取当前日期的月份
        day = nowDate.getDate(); //获取当前日期的日
    }

    var days = new Date(year, month, 0);
    days = days.getDate(); //获取当前日期中月的天数
    var year2 = year;
    var month2 = parseInt(month) - 3;
    if (month2 == 0) {
        year2 = parseInt(year2) - 1;
        month2 = 12;
    }
    var day2 = day;
    var days2 = new Date(year2, month2, 0);
    days2 = days2.getDate();
    if (day2 > days2) {
        day2 = days2;
    }
    if (month2 < 10) {
        month2 = '0' + month2;
    }
    var t2 = year2 + '-' + month2 + '-' + day2;
    return t2;
}


// 获取当日期
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

// 获取本月日期
function getThisMonthDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }

    var currentdate = year + seperator1 + month + seperator1 + '01';
    return currentdate;
}


/*----------------搜索时间总js-----------------*/

//今天的日期
$("#getTodayDate").on("click",function(){
	var mystr = getNowFormatDate() + ' ~ ' + tomorrowTime(getNowFormatDate());
	$("#searchTime").val(mystr);
})

//昨天的日期
$("#getLastdayDate").on("click",function(){
	var mystr = yestodayTime(getNowFormatDate()) + ' ~ ' + getNowFormatDate();
	$("#searchTime").val(mystr);
})

//本月的日期
$("#getThisMonthDate").on("click",function(){
	var mystr = getThisMonthDate() + ' ~ ' + tomorrowTime(getNowFormatDate());
	$("#searchTime").val(mystr);
})

//近一周的日期
$("#getRecentlyWeekDate").on("click",function(){
	var mystr = get7DaysBefore(getNowFormatDate()) + ' ~ ' + tomorrowTime(getNowFormatDate());
	$("#searchTime").val(mystr);
})

//近一月的日期
$("#getRecentlyMonthDate").on("click",function(){
	var mystr = getPreMonth(getNowFormatDate()) + ' ~ ' + tomorrowTime(getNowFormatDate());
	$("#searchTime").val(mystr);
})

//近三月的日期
$("#getRecentlyThreeMonthDate").on("click",function(){
	var mystr = getPreThMonth(getNowFormatDate()) + ' ~ ' + tomorrowTime(getNowFormatDate());
	$("#searchTime").val(mystr);
})



function initRegisterImg(){
    

    $(".user-enter-info").focus(function(){
        $(".userlogin-img").hide();
        $(".userlogin-img2").show();
    })
    $(".user-enter-pass").focus(function(){
        $(".userlogin-img").hide();
        $(".userlogin-img3").show();
    })

    $('.user-enter-info').blur(function () {
        var isPassword=$('.user-enter-pass').is(":focus");
        if(!isPassword){
            $(".userlogin-img").hide();
            $(".userlogin-img1").show();
        }
    });

    $('.user-enter-pass').blur(function () {
        var isUsername=$('.user-enter-info').is(":focus");
        if(!isUsername){
            $(".userlogin-img").hide();
            $(".userlogin-img1").show();
        }
    });
}
/*金额数值格式转换*/
function number_format(v) {
    return parseFloat(v).toFixed(3);
}
/*检测数字类型*/
function isNumber(op){
    if(isNaN(op)){
        return false;
    }else if(op == -Infinity || op == Infinity){
        return false;
    }else{
        return true;
    }
}
layui.use("element",function(){
    layui.config({
        base:window.Think.STATIC+"/layui/lay/mymodules/"
    }).extend({
        myValidate: 'my_validate',
    });

    $(function(){
        $(document).keydown(function(e) {
            // 按F5时，重新访问搜索页面
            if(e.keyCode == 116) {
                location.reload();
                return false;
            }
        });
    });
});

//AJAX 数据处理
function ajaxdatadeal(data,successFunc,failFunc){
    if( 1 == data.status) {
        try{successFunc();}catch(e){}
        //toastr.success(data.info,'成功');
        layer.msg(data.info);
        if( "" != data.url){
            setTimeout(function(){window.location.href = data.url;},2000);
        }
    } else if(0 == data.status) {
        try{failFunc();}catch(e){}
        //toastr.error(data.info,'失败');
        layer.msg(data.info);
        if( "" != data.url){
            setTimeout(function(){window.location.href = data.url;},2000);
        }
    } else {
        try{failFunc();}catch(e){}
        //toastr.error('系统发生错误，请联系管理员','失败');
        layer.msg("系统发生错误，请联系管理员");
    }
}
function get_user_info()
{
    var user = $.cookie("front_user_auth");
    if(!!user)
    {
        user = user.substr(6);
        if(user)
            return JSON.parse(user);
        else
            return false;
    }
    else
        return false;
}