/*
 弹出招生类别及首选科目
 日期：2023-04-12
 需要和layer弹窗控件一起使用。

 settings 参数说明
 -----
 refresh:是否刷新当前页面
 gotourl:转向到目标页面
 posturl:提交登录数据网址
 ------------------------------ */
(function($) {

    $.fn.postyboxnew = function(settings, callback) {
        if (this.length < 1) {
            return;
        }
        // 默认值
        settings = $.extend({
            posturl: '/Zhi/AjaxServices/postyboxnew.html',
            refresh: true,
            gotourl:'',
            ty:'普通类',
            topchoose:'物理',
            userscore:400,
            tyidx:0,
            tpidx:0,
        }, settings);

        this.bind("click", function() {
            $(".a-change-tynew a").each(function(){
                $(this).removeClass('active');
                if ($(this).html()==settings.ty){
                    $(this).addClass('active');
                    settings.tyidx = $(this).data('idx');
                }
            });
            $(".a-change-tpnew a").each(function(){
                $(this).removeClass('active');
                if ($(this).html()==settings.topchoose){
                    $(this).addClass('active');
                    settings.tpidx = $(this).data('idx');
                }
            });
            $(".a-change-usnew a").each(function(){
                $(this).removeClass('active');
                if ($(this).data('idx')==settings.userscore){
                    $(this).addClass('active');
                }
            })

            layer.open({
                type: 1,
                skin: 'layui-layer-rim gxzs-popup-boder', //加上边框
                area: ['680px', '450px'], //宽高
                content: $('#pop-postynew-box-div')
            });
        });

        // 加载样式
        var loadCss = function() {
            if($('#pop-postynew-box-css').length && $('#pop-postynew-box-css').length>0){

            }else{
                var js=document.scripts;
                var jsPath;
                for(var i=js.length;i>0;i--){
                    if(js[i-1].src.indexOf("postybox.js")>-1){
                        jsPath=js[i-1].src.substring(0,js[i-1].src.lastIndexOf("/")+1);
                    }
                }
                $("head").append('<link>');
                css = $("head").children(":last");
                css.attr({
                    rel: "stylesheet",
                    type: "text/css",
                    href: jsPath + "css/style.css",
                    id:"pop-postynew-box-css"
                });
            }
        };

        var loadBoxcontent = function() {
            var content = ''
                +'<div id="pop-postynew-box-div" class="gxzs-popup clearfix" style="display: none">\r\n'
                + '        <div class="gxzs-popup-input clearfix">\r\n'
                + '            <div class="popup-input-l">招生类别</div>\r\n'
                + '            <div class="popup-input-r clearfix a-change-tynew">\r\n'
                + '                <a href="javascript:void(0)" data-idx="0" class="active">普通类</a>\r\n'
                + '                <a href="javascript:void(0)" data-idx="1">体育类</a>\r\n'
                + '                <a href="javascript:void(0)" data-idx="2">艺术类</a>\r\n'
                 + '            </div>\r\n'
                + '        </div>\r\n'
                + '        <div class="gxzs-popup-input clearfix" style="margin-top:15px;">\r\n'
                + '            <div class="popup-input-l">首选科目</div>\r\n'
                + '            <div class="popup-input-r clearfix  a-change-tpnew">\r\n'
                + '                <a href="javascript:void(0);" data-idx="0" class="active">物理</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="1">历史</a>\r\n'
                + '            </div>\r\n'
                + '        </div>\r\n'
                + '        <div class="gxzs-popup-input clearfix" style="margin-top:15px;">\r\n'
                + '            <div class="popup-input-l">预估分数</div>\r\n'
                + '            <div class="popup-input-r2 clearfix  a-change-usnew">\r\n'
                + '                <a href="javascript:void(0);" data-idx="200">300分以下</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="300">300-320分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="320">320-340分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="340">340-360分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="360">360-380分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="380">380-400分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="400">400-420分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="420">420-440分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="440">440-460分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="460">460-480分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="480">480-500分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="500">500-520分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="520">520-540分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="540">540-560分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="560">560-580分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="580"class="active">580-600分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="600">600-620分</a>\r\n'
                + '                <a href="javascript:void(0);" data-idx="620">620-650分</a>\r\n'
                + '            </div>\r\n'
                + '        </div>\r\n'
                + '        <div class="gxzs-popup-btn"><a href="javascript:void(0)">确定</a></div>\r\n'
                + '    </div>\r\n';

            if($('#pop-postynew-box-div').length && $('#pop-postynew-box-div').length>0){
            }else{
                $("body").append(content);
            }
        };


        var init = function() {
            loadCss();
            loadBoxcontent();

            var layer_index;

            $(".a-change-tynew a").click(function(){
                $(this).addClass('active').siblings().removeClass('active');
                settings.ty = $(this).html();
                settings.tyidx = $(this).data('idx');
            });
            $(".a-change-tpnew a").click(function(){
                $(this).addClass('active').siblings().removeClass('active');
                settings.topchoose = $(this).html();
                settings.tpidx = $(this).data('idx');
            });
            $(".a-change-usnew a").click(function(){
                $(this).addClass('active').siblings().removeClass('active');
                settings.userscore = $(this).data('idx');
            });

            $('.gxzs-popup-btn a').click(function(){
                window.location.href = settings.gotourl + "?score="+settings.userscore+"&ty=" +  encodeURI(settings.ty) + "&topchoose=" +  encodeURI(settings.topchoose)
            });
        };
        init();
    };
})(jQuery);
