diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index d5212ea1..b9a44e7d 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1175,6 +1175,12 @@ end @menu_type = 6 @sub_type = 3 @partners = Partner.includes(:school) + @limit = 10 + @page = params['page'] || 1 + @partners_count = @partners.count + + @total_pages = (@partners_count / 10.0).ceil + @partners = paginateHelper @partners, @limit end def all_partners @@ -1182,7 +1188,6 @@ end @province = params[:province] @schools = School.where("partner_id IS NULL").all - if params[:search] @schools = @schools.where("name like ?", "%#{@search}%") end @@ -1191,12 +1196,11 @@ end @schools = @schools.where("province like ?", "%#{@province}%") end - @page = (params['page'] || 1).to_i + @limit = 10 + @page = params[:page] || 1 @schools_count = @schools.count + @total_pages = (@schools_count / 10.0).ceil - @limit = 10 - @is_remote = true - @schools_pages = Paginator.new @schools_count, @limit, @page @schools = paginateHelper @schools, @limit respond_to do |format| format.js diff --git a/app/views/managements/_partner_addUnit.html.erb b/app/views/managements/_partner_addUnit.html.erb index 11a9c669..6ad69b66 100644 --- a/app/views/managements/_partner_addUnit.html.erb +++ b/app/views/managements/_partner_addUnit.html.erb @@ -2,15 +2,8 @@
@@ -35,27 +28,60 @@ $(function() { unitDownOption(); showprovince("province"); + submit_add_partner(); - get_schools() + var i = 1; //设置当前页数 + var msg_list_loading = false; + $(function() { + var totalpage = <%= @total_pages.to_i %>; //总页数,防止超过总页数继续滚动 + var winH = $(window).height(); //页面可视区域高度 + get_schools(1) + $("#search_user_list").scroll(function() { + if (i < totalpage) { // 当滚动的页数小于总页数的时候,继续加载 + var pageH = $(document.body).height(); - }); - function get_schools() { - $.getJSON("/managements/all_partners",function(schools){ - let s_html = ""; - $.each(schools,function (index,array) { - s_html =s_html+ "
" + - " " + - " " + - " " + - " " + - " \n" + - " \n" + - " "+array["school"]["province"]+"" + - "
" - }) - $("#serch_user_list").html(s_html) - }) - } + var scrollT = $(window).scrollTop(); //滚动条top + var aa = (pageH - winH - scrollT) / winH; + console.log(aa) + if ( !msg_list_loading ){ + if (aa < 0.01 ) { + get_schools(i+1) + } + } + } + }); + }); + function get_schools(page) { + var msg_list = $('#search_user_list'); + var limit_page = 1 + if (page > 1){ + limit_page = page + }else{ + limit_page = 1 + } + if (msg_list.height() + msg_list[0].scrollTop >= msg_list[0].scrollHeight - 60) { + msg_list_loading = true; + $.getJSON("<%= all_path %>?page="+limit_page, function(schools) { + if (schools) { + msg_list_loading = false; + let s_html = ""; + $.each(schools,function (index,array) { + s_html =s_html+ "" + + " " + + " " + + " " + + " " + + " \n" + + " \n" + + " "+array["school"]["province"]+"" + + "
" + }); + $("#search_user_list").html(s_html); + i ++; + } + }); + } + } function submit_add_partner(){ if($("input[name='school[id]']:checked").length==0){ $("#checkNotice").html("请选择需要添加的内容").removeClass("none"); @@ -77,4 +103,8 @@ }) } } + + }); + + \ No newline at end of file diff --git a/app/views/managements/_partner_search_form.html.erb b/app/views/managements/_partner_search_form.html.erb new file mode 100644 index 00000000..629faa11 --- /dev/null +++ b/app/views/managements/_partner_search_form.html.erb @@ -0,0 +1,19 @@ +<%= labelled_form_for @schools, :url =>{:controller=> 'managements', :action => 'add_partners', :type => @type}, :html => {:id => 'partners_search_form'}, :method => "get", :remote => true do |f| %> +