define(['jquery', 'bootstrap', 'frontend', 'form', 'template', 'swiper', 'layer'], function($, undefined, Frontend,
                                                                                            Form, Template, Swiper, Layer) {
    var Controller = {
        index: function() {

            $(document).on("click",".tab-wrap .tab-list .tab-item",function(){
                var that = this;
                var category_id = $(this).data("category_id");
                var type = $(this).data("type");
                var url = '';
                if(parseInt(type) ==1){
                     url = 'index/getBasedisplay';
                }else{
                    url = 'index/getAchievements';
                }
                $.ajax({
                    url:url,
                    data:{category_id:category_id},
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        console.log(res.data);
                        var str = '';
                        var data_ = res.data;
                        var data = data_.data;
                        var type = parseInt(data_.type);
                        console.log(data);
                        for (var i =0;i < data.length;i++){
                            if(type==1){

                                str +='<div class="item"><a href="/index/basedisplay/detail/type/1/id/'+data[i].base_id+'.html"><img style="width: 100%; height:100%;object-fit: cover;"  src="'+Config.__SUBDOMAIN__+data[i].image+'" alt=""></a><div class="item-des">'+data[i].base_title+'</div></div>';
                            }else{
                                str +='<div class="item"><a href="/index/basedisplay/detail/type/2/id/'+data[i].achievements_id+'.html"><img style="width: 100%; height:100%;object-fit: cover;"  src="'+Config.__SUBDOMAIN__+data[i].image+'" alt=""></a><div class="item-des">'+data[i].achievements_title+'</div></div>';
                            }
                        }
                        $(that).parent().children().removeClass("cur");
                        $(that).addClass("cur");
                        $(that).parent().parent().next().html(str);
                    }
                });

            });
            $(document).on("click",".moreJ",function(){
                var title = $(this).siblings('.tab-list').children(".cur").text();
                var type = $(this).attr('data-type');
                var id =  $(this).siblings('.tab-list').children(".cur").attr('data-id');
                location.href = "/index/basedisplay/index/type/"+type+"/id/"+id;

            });
        },
        detail:function(){

            console.log($(document).find(".detial_content img"));
            $(document).find(".detial_content img").each(function(i,e){
                var src = $(e).attr("src");
                if(src.search("https://energy.xmu.edu.cn") == -1){
                    $(e).attr("src","https://energy.xmu.edu.cn"+src);
                }
            });
        },
        event_list:function(){
            $(document).on("click",'.like',function(){
                var id = $(this).data("id");
                var that = this;
                $.ajax({
                    url:'index/Ilike_elegant',
                    data:{id:id},
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        if(parseInt(res.code) ===0){
                            var url = res.url;
                            Layer.alert(res.msg,{},function(){
                                window.location.href = url;
                            });
                        }
                        if(parseInt(res.data) ===1){
                            if($(that).find("span").hasClass('bi-hand-thumbs-up') && !$(that).find("span").hasClass("bi-hand-thumbs-up-fill")){
                                $(that).find("span").removeClass('bi-hand-thumbs-up');
                                $(that).find("span").addClass("bi-hand-thumbs-up-fill");
                                var count_like = $(that).find(".count").text();
                                $(that).find(".count").text(parseInt(count_like)+1);
                            }
                        }else if(parseInt(res.data)===2){
                            if(!$(that).find("span").hasClass('bi-hand-thumbs-up') && $(that).find("span").hasClass("bi-hand-thumbs-up-fill")){
                                $(that).find("span").addClass('bi-hand-thumbs-up');
                                $(that).find("span").removeClass("bi-hand-thumbs-up-fill");
                                var count_like_ = $(that).find(".count").text();
                                if(count_like_> 0){
                                    $(that).find(".count").text(parseInt(count_like_)-1);
                                }
                            }
                        }
                    }
                });
            });
        },
        event_detail:function(){
            
            $(document).on("click",'.like',function(){
                var id = $(this).data("id");
                var that = this;
                $.ajax({
                    url:'index/Ilike_elegant',
                    data:{id:id},
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        if(parseInt(res.code) ===0){
                            var url = res.url;
                            Layer.alert(res.msg,{},function(){
                                window.location.href = url;
                            });
                        }
                        if(parseInt(res.data) ===1){
                            if($(that).find("span").hasClass('bi-hand-thumbs-up') && !$(that).find("span").hasClass("bi-hand-thumbs-up-fill")){
                                $(that).find("span").removeClass('bi-hand-thumbs-up');
                                $(that).find("span").addClass("bi-hand-thumbs-up-fill");
                                var count_like = $(that).find(".count").text();
                                $(that).find(".count").text(parseInt(count_like)+1);
                            }
                        }else if(parseInt(res.data)===2){
                            if(!$(that).find("span").hasClass('bi-hand-thumbs-up') && $(that).find("span").hasClass("bi-hand-thumbs-up-fill")){
                                $(that).find("span").addClass('bi-hand-thumbs-up');
                                $(that).find("span").removeClass("bi-hand-thumbs-up-fill");
                                var count_like_ = $(that).find(".count").text();
                                if(count_like_> 0){
                                    $(that).find(".count").text(parseInt(count_like_)-1);
                                }
                            }
                        }
                    }
                });
            });
        }
    }
    return Controller;
});