/**
 * [OElove] (C)2010-2099 oelove.com biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2020/03/11 by CL $
*/
var _inst_oesearch = null;
$(function(){
    
    //搜索类
    function OESearch() {
        this._search_dialog = null; //弹出对象
        this._search_box = "search_wrap"; //搜索框名称
        this.slide_time = 200;
        this.params = ""; //搜索项组合 item=value&item=value
        
        this.this_dom = null;
        this.slide_box = null;
        
        this.wake();
    }
    
    OESearch.prototype = {
        
        wake:function() {
            _this = this;
            
            //选择分类
            $(document).on("click", "[f='but_sel_cat']", function(){
                var $val = $(this).attr("data-val");
                var $input = $(this).attr("data-input");
                $("#"+$input).val($val);
                $(this).addClass('current').siblings().removeClass('current');
                
                _this.submitSearch();
            });
            
            //显示隐藏下拉参数
            $(document).on("click", "[f='but_slide_item']", function(){
                _this.this_dom = $(this);
                var $slide = $(this).attr("data-slide");
                _this.slide_box  = $slide+"_item_box";
                if (!$(this).hasClass("selected")) {
                    $(this).addClass("selected");
                    $(".item_list").hide();
                    $("#"+_this.slide_box).show();
                }
                else {
                    $(this).removeClass("selected");
                    $(".item_list").hide();
                }
            });
            //选中下拉参数
            $(document).on("click", "[f='but_sel_seritem']", function(){
                var $val = $(this).attr("data-val");
                $(this).addClass("color_main").siblings().removeClass("color_main");
                $(this).siblings().find("i").hide();
                $(this).find("i").show();
                var $input = $(this).attr("data-input");
                $("#"+$input).val($val);
                var $text = $(this).find("em").text();
                
                $("#"+_this.slide_box).hide();
                $(_this.this_dom).removeClass("selected");
                $(_this.this_dom).find("em").html($text);
                $(_this.this_dom).addClass("current");
                
                _this.submitSearch();
            });
            
        }, 
        
        
        //执行搜索
        submitSearch:function() {
            _this = this;
            
            _this.params = _this.buildParams(); //获取参数
            $reqs_url = WAP_APPFILE+"&c=article&a=list&datatype=json";
            $reqs_url += "&"+_this.params;
            $("#reqs_url").val($reqs_url);
            $("#page").val("1");
            
            //重新搜索...
            setTimeout(function(){
                if (_inst_oepage) {
                    $("#"+_inst_oepage.pull_data_id).html("");
                    _inst_oepage.scroll.refresh();
                }
            }, 50);
        }, 
        
        //组合参数
        buildParams:function() {
            var $build_params = "";
            var arr_data = new Array();
            arr_data = [
                    's_catid', 's_orderby',
                ];
            $.each(arr_data, function(i, item) {
                $val = $("#"+item).val();
                if (typeof($val) == "undefined") {
                    $val = "";
                }
                if ($build_params.length == 0 || $build_params == "") {
                    $build_params += item+"="+encodeURIComponent($val);
                }
                else {
                    $build_params += "&"+item+"="+encodeURIComponent($val);
                }
            });
            return $build_params;
        }
        
    }
    _inst_oesearch = new OESearch();
    
});

