(function(){
    X.pageLogic['dropdownlist3'] = {
        init : function(parms){
            var me = this;
            this.parms = parms;
            this.callback = parms.callback;
            var data = parms.extData.data;
            var comparator = parms.extData.comparator;
            console.log('aaa',listdata);
            var listdata = [];
            if(data[0]['title']){
                listdata = data;
            }else {
                for(let i in data){
                    var arr = {
                        title: data[i],
                        id: data[i]
                    }
                    listdata.push(arr);
                }
            }


            X.laytpldata("#dropdownlist-con-box-dot",listdata,".dropdownlist-con-box");

            // $(document).off("bind",'.dropdownlist-input').on("bind",".dropdownlist-input",function(){
            //     var title = $(this).val();
            //     console.log(title);
            // });

            $('.dropdownlist-input').bind('input propertychange', function() {
                var title = $(this).val();
                if(title != ""){
                    var filteringdata = [];
                    for(let i in listdata){
                        if(listdata[i]['title'].indexOf(title) != -1 || listdata[i]['id'].indexOf(title) != -1){
                            filteringdata.push(listdata[i]);
                        }
                    }
                    // console.log(filteringdata);
                    X.laytpldata("#dropdownlist-con-box-dot",filteringdata,".dropdownlist-con-box");
                }else{
                    X.laytpldata("#dropdownlist-con-box-dot",listdata,".dropdownlist-con-box");
                }
            })

            var dataArr=[];
            $(document).off('click','.dropdownlist-list').on('click','.dropdownlist-list',function(){
                var index = $(this).attr("data-index");
                var id = $(this).attr("data-id");
                var title = $(this).attr("data-title");
                var type = 0;
                if(comparator == 'in'){
                    for(let i in dataArr){
                        if(dataArr[i]['id'] == id){
                            type = 1;
                            dataArr.splice(i,1)
                            break;
                        }else {
                            type = 0;
                        }
                    }
                    if(type == 0 ){
                        $(this).addClass("dropdownlist-list-on");
                        for(let i in listdata){
                            if(listdata[i]['id'] == id && title == listdata[i]['title']){
                                dataArr.push(listdata[i]);
                            }
                        };
                    }else {
                        $(this).removeClass("dropdownlist-list-on");
                    }
                }else{
                    $(".dropdownlist-list").removeClass("dropdownlist-list-on");
                    $(this).addClass("dropdownlist-list-on");
                    for(let i in listdata){
                        if(listdata[i]['id'] == id && title == listdata[i]['title']){
                            dataArr[0]=listdata[i];
                        }
                    };
                }
                
            });

            $(document).off('click','.dropdownlist-but-qd').on('click','.dropdownlist-but-qd',function(){
                var strftv='',ftv='';
                for(let i in dataArr){
                    strftv += (i==0) ? dataArr[i]['title']:','+dataArr[i]['title'];
                    ftv+= (i==0) ? dataArr[i]['id']:','+dataArr[i]['id'];
                }
                var arr ={
                    'title':strftv,
                    'id':ftv
                }
                me.callback && me.callback(arr);
                layer.close( me.parms.layIndex );
            });

            $(document).off('click','.dropdownlist-but-qx').on('click','.dropdownlist-but-qx',function(){
                layer.close( me.parms.layIndex );
            });
            

        }
    };
})();
