(function(){

    X.pageLogic['category'] = {
        init : function( parms ){
            var me = this;
            this.parms = parms;
            this.callback = parms.callback; //选择后执行的回调
            var data = parms.extData;//获取到上层弹窗传的数据
            console.log(data);
            // 给条件框赋值
            X.laytpldata("#zhuang-tab-dot",data,'.zhuang_tab ');

            X.laytpldata("#zhuang-conetnt-dot",data,'.zhuang_conetnt ');

            // 搜索框改变事件
            $('.zhuanghu_ss #zhuanghu_txt').bind('input propertychange', function() {
                var arrData = [];
                var tit = $(this).val();
                if(tit != ""){
                    $('.zhuanghu_ss .qingkomg').show();
                    for(let i in data){
                        var Categoryarr =[];
                        for(let j in data[i]['category']){
                            if(data[i]['category'][j]['title'].indexOf(tit) != -1){
                                Categoryarr.push(data[i]['category'][j]);
                            }
                        }
                        if(Categoryarr.length > 0){
                            var arr = {
                                'title':data[i]['title'],
                                'id':data[i]['id'],
                                'category':Categoryarr
                            }
                            arrData.push(arr);
                        }
                    }
                    // $("#zhuang-conetnt-dot").html("");
                    console.log(data);
                    console.log(arrData)
                    X.laytpldata("#zhuang-conetnt-dot",arrData,'.zhuang_conetnt ');
                }else {
                    $('.zhuanghu_ss .qingkomg').hide();
                    X.laytpldata("#zhuang-conetnt-dot",data,'.zhuang_conetnt ');
                }
            });

            //清空搜索框
            $('.zhuanghu_ss .qingkomg').click(function(){
                $('.zhuanghu_ss #zhuanghu_txt').val('');
                X.laytpldata("#zhuang-conetnt-dot",data,'.zhuang_conetnt ');
            })
            var index = 0;
            $(".zhuang_tab_box .zhuang_tab span").click(function(){
                $(".zhuang_tab_box .zhuang_tab span div").removeClass('zhuanghu_xila_xian');
                $(this).find('div').addClass('zhuanghu_xila_xian');
                index = $(this).attr("data-index");
                if(index != 0){
                    var dataArr = [];
                    dataArr.push(data[index])
                    X.laytpldata("#zhuang-conetnt-dot",dataArr,'.zhuang_conetnt ');
                }else {
                    X.laytpldata("#zhuang-conetnt-dot",data,'.zhuang_conetnt ');
                }
            })

            //单击属性
            $(document).off('click','.zhuang_conetnt .ta-pso-line').on('click','.zhuang_conetnt .ta-pso-line',function(){
                // var index = $(this).attr("data-index");
                var indexs = $(this).attr("data-indexs");
                var valdata = {
                    'title':$(this).attr('data-title'),
                    'id':$(this).attr('data-id'),
                    'type':$(this).attr('data-type'),
                    'category': data[index]['category'][indexs]['category'],
                    'table_type':data[index]['id']
                }
                me.callback && me.callback(valdata);

                layer.close( me.parms.layIndex );//获取最新的弹窗关闭
            })
        }
    };
    
})();
