/**
 * Created by Administrator on 2018/6/1 0001.
 */

$(function () {
    $('.project-tap-nav li.project-tap-item').click(function () {
        var liindex = $('.project-tap-nav .project-tap-item').index(this);
        $(this).addClass('on').siblings().removeClass('on');
        $('.project-form-show div.project-form').eq(liindex).fadeIn(150).siblings('div.project-form').hide();
    });
});
$(function () {
    $('.zz-tap-ul li').click(function () {
        var liindex = $('.zz-tap-ul li').index(this);
        $(this).addClass('on').siblings().removeClass('on');
        $('.zz-tap-ul-box div.zz-tap-con').eq(liindex).fadeIn(150).siblings('div.zz-tap-con').hide();
    });
});

//下拉列表
$(".sel-bg input.cursor,.sel-bg img").click(function (e) {
    $(".sel-bg .sel-list").hide();
    $(".sel-bg-val .sel-list").hide();
    $(this).parent().find(".sel-list").show();
    var e = e || event;
    e.stopPropagation();
});
$(document).on("click", ".sel-bg .sel-list li", function () {
    $(this).parents(".sel-list").hide();
    $(this).parents(".sel-bg").find("input").val($(this).text());
});
$(".sel-bg-val input.cursor").click(function (e) {
    if ($(this).attr("class").indexOf("cursor") != -1) {
        $(".sel-bg .sel-list").hide();
        $(".sel-bg-val .sel-list").hide();
        $(this).parent().find(".sel-list").show();
        var e = e || event;
        e.stopPropagation();
    }

});
$(document).on("click", ".sel-bg-val .sel-list li", function () {
    $(this).parents(".sel-list").hide();
    $(this).parents(".sel-bg-val").find("input").val($(this).attr("val"));
});
$(document).click(function () {
    $(".sel-list").hide();
});

//获取验证码倒计时
var wait = 60;
function time(o) {
    if (wait == 0) {
        o.html("获取验证码");
        wait = 60;
    } else {
        o.html("重新发送(" + wait + ")");
        wait--;
        setTimeout(function () {
            time(o)
        },
            1000);
    }
}

$(".hide").click(function () {
    $(this).parents('.foot-fixed').addClass("on");
});
$(".hides").click(function () {
    $(this).parents('.foot-fixed').removeClass("on");
});

// 侧边栏
$(window).scroll(function () {
    var scroll_len = $(window).scrollTop();
    if (scroll_len > 400) {
        $('.side').css({
            "position": "fixed",
            "top": "30%"
        });
        $('.side-fh').css({
            "display": "block"
        });
    } else {
        $('.side').css({
            "position": "absolute",
            "top": "55%"
        });
        $('.side-fh').css({
            "display": "none"
        });
    }
});
$(function () {
    //侧边栏
    $(".side li").hover(function () {
        $(this).find(".wx").stop().animate({
            "width": "123px"
        }, 300);
    }, function () {
        $(this).find(".wx").stop().animate({
            "width": "0"
        }, 300);
    });
    //返回顶部
    $(".side-fh").click(function () {
        $("html,body").animate({
            scrollTop: 0
        }, 600);
    })
});

// 预约时间
laydate.render({
    elem: '#test0',
    type: 'datetime'
});

/* 合并时新增的代码 */
(function ($) {
    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, // month
            "d+": this.getDate(), // day
            "h+": this.getHours(), // hour
            "m+": this.getMinutes(), // minute
            "s+": this.getSeconds(), // second
            "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
            "S": this.getMilliseconds()
        };
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    };
    $.scroll_load = function (options) {
        var defaults = {
            offset: 300,
            url: '',
            format_func: '',
            tpl: '',
            box: '',
            begin: 2,
            args: {}
        };
        $.extend(defaults, defaults, options);

        var flag = 0;
        if (defaults.format_func === '' || defaults.url === '') {
            return;
        }

        var page = defaults.begin;

        var load_data = function () {
            $.get(defaults.url + page, defaults.args, function (data) {
                if (data.error == 0) {
                    for (var i = 0; i < data.list.length; i++) {
                        var item = defaults.tpl.clone();
                        item = defaults.format_func(item, data.list[i], page);
                        defaults.box.append(item);
                    }
                    flag = 0;
                    page = data.page + 1;
                } else {
                    flag = 2;
                }
            }, 'json');
        };

        var scroll_func = function () {
            if ($(document).height() - $(this).scrollTop() - $(this).height() < defaults.offset) {
                if (flag == 0) {
                    flag = 1;
                    load_data();
                }
            }
        };
        $(window).scroll(scroll_func);
        scroll_func();
    };
    $(document).ready(function () {
        var form = $('#pop-form');
        var hide_form = function () {
            $('#pop-mask').hide();
            form.hide();
            form.children().hide();
            $("body,html").removeClass('body-overflow');
        };
        $('.pop-btn').each(function () {
            var $this = $(this);
            $this.click(function () {
                var name = $this.attr('data-dlg');
                form.load('/dlg-' + name, {}, function () {
                    $('#pop-mask').show();
                    form.show();
                    form.children().show();
                    $("body,html").addClass('body-overflow');
                    form.find('.pop-hide').click(hide_form);
                });
            });
        });
        $("#pop-mask").click(hide_form);
        $('.fsubmit').fsubmit();
        var set_text = function (obj, text) {
            if (obj.is('a') || obj.is('span')) {
                obj.html(text);
            } else {
                obj.val(text);
            }
        };
        $('.sms_code').each(function () {
            var btn = $(this);
            var html;
            var prefix = '重新发送';
            if (btn.is('a') || btn.is('span')) {
                html = btn.html();
            } else {
                html = btn.val();
                prefix = '重发';
            }
            var delay = function (left) {
                if (left > 0) {
                    set_text(btn, prefix + '(' + left + '秒)');
                    setTimeout(function () {
                        delay(left - 1);
                    }, 1000);
                } else {
                    set_text(btn, html);
                }
            };
            btn.click(function () {
                var url = btn.attr('data-base_url');
                var target_class = btn.attr('data-target');
                var target = $(target_class);
                $.get(url, {
                    target: target.val()
                }, function (data) {
                    alert(data.msg);
                    if (data.error === 0) {
                        delay(data.offset);
                    }
                }, 'json');
            });
        });
    });
})(jQuery);


