dev_local
cxt 6 years ago
commit 0b76986075

@ -1193,6 +1193,54 @@ end
end
# 添加客户
def customers_list
@search = params[:search]
@province = params[:province]
partner_id = params[:partner_id]
@partner = Partner.find partner_id
@customers = @partner.customers
if @customers.present?
@schools = School.where("(partner_id != ? or partner_id is NULL) and (customer_id is NULL or customer_id not in(#{@customers.map(&:id).join(",")}))", @partner.id)
else
@schools = School.where("partner_id != ? or partner_id is NULL", @partner.id)
end
if params[:search]
@schools = @schools.where("name like ?", "%#{@search}%")
end
if params[:province] && params[:province] != '0'
@schools = @schools.where("province like ?", "%#{@province}%")
end
@limit = 10
@page = params[:page] || 1
@schools_count = @schools.count
@total_pages = (@schools_count / 10.0).ceil
@schools = paginateHelper @schools, @limit
respond_to do |format|
format.js
format.json {
render json: @schools
}
end
end
def add_customers
school_ids = params[:school_ids]
if school_ids.length > 0
school_ids.each do |s|
school = School.where("id = ?",s).first
if school.present?
customer = Customer.new(partner_id: params[:partner_id])
customer.save!
school.update_attributes(:customer_id => customer.id)
end
end
render :json => {status: 1, message: "创建成功!"}
end
end
def all_partners
@search = params[:search]
@province = params[:province]
@ -1237,6 +1285,8 @@ end
# 删除部门管理员
def delete_depart_member
DepartmentMember.where(:department_id => params[:depart], :user_id => params[:user_id]).destroy_all

@ -0,0 +1,100 @@
<div class="task-popup" style="width: 572px;">
<div class="task-popup-title clearfix">添加客户</div>
<div class="task_popup_con">
<div class="clearfix mb5 df">
<div class="flex1">
<%= render partial: "managements/customers_search_form" %>
</div>
<a href="javascript:void(0);" onclick="$('#partners_search_form').submit()" class="white-btn mt6 edu-blueback-btn fl ml15 mt55">搜索</a>
</div>
<div class="mb4 clearfix">
<p class="pl10 color-grey-6 clearfix">
<span class="fl ml25">单位</span>
<span class="fr with30">地区</span>
</p>
<div class="edu-back-skyblue clearfix pl10 over280" id="search_customers_list">
<%= render :partial => "partners_list" %>
</div>
<p class="clearfix" style="height: 20px;"><span class="fl lineh-20 none color-red" id="checkNotice"></span></p>
</div>
<li class="clearfix mt10 edu-txt-center">
<a href="javascript:void(0);" class="task-btn mr10" onclick="hideModal()">取消</a>
<a href="javascript:void(0);" class="task-btn task-btn-orange ml20" onclick="submit_add_partner()">确定</a>
</li>
</div>
</div>
<script>
var i = 1; //设置当前页数
var msg_list_loading = false;
$(function() {
$(function() {
var totalpage = <%= @total_pages.to_i %>; //总页数,防止超过总页数继续滚动
var winH = $(window).height(); //页面可视区域高度
$("#search_customers_list").scroll(function() {
if (i < totalpage) { // 当滚动的页数小于总页数的时候,继续加载
var pageH = $(document.body).height();
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_customers_list');
if (msg_list.height() + msg_list[0].scrollTop >= msg_list[0].scrollHeight - 60) {
msg_list_loading = true;
$.getJSON("<%= all_path %>?partner_id=<%= @partner.id %>page="+page+"&search="+$("#partner_name_search").val()+"&province="+$("#partner_province").val(), function(schools) {
if (schools) {
msg_list_loading = false;
var s_html = "";
$.each(schools,function (index,array) {
s_html = s_html+ "<p class='clearfix mt5'>" +
" <span class='fl with70'>" +
" <span>" +
" <input type='checkbox' name='school[id]' value='"+array["school"]["id"]+"' id='school_'"+array["school"]["id"]+"'class='magic-checkbox'>" +
" <label for='school_'"+array["school"]["id"]+">"+array["school"]["name"]+"</label>" +
" </span>\n" +
" </span>\n" +
" <span class='fl with30'>"+array["school"]["province"]+"</span>" +
" </p>"
});
$("#search_customers_list").append(s_html);
i ++;
}
});
}
}
function submit_add_partner(){
if($("input[name='school[]']:checked").length==0){
$("#checkNotice").html("请选择需要添加的内容").removeClass("none");
return;
}else{
var checked_array = [];
$("input[name='school[]']:checked").each(function () {
checked_array.push($(this).val())
});
$.ajax({
url: "/managements/add_customers",
type: 'POST',
data: {school_ids: checked_array, partner_id: <%= @partner.id %>},
success: function (e) {
if(e.status === 1){
hideModal();
window.location.href = "<%= partners_managements_path(partner: @partner.id) %>";
}
}
})
}
}
</script>

@ -0,0 +1,19 @@
<%= form_for "", :url => {:controller=> 'managements', :action => 'customers_list', :partner_id => @partner.id}, :html => {:id => 'partners_search_form'}, :method => "get", :remote => true do |f| %>
<div class="df">
<span class="fl lineh-35">地区:</span>
<select placeholder="请选择地区" name="province" id="partner_province" class="flex1"></select>
</div>
<div class="df mt15">
<span class="fl lineh-35">单位:</span>
<input type="text" class="input-flex-35" name="search" placeholder="请输入单位关键字" id="partner_name_search"/>
</div>
<% end %>
<script>
$(function () {
unitDownOption();
showprovince("partner_province");
})
</script>

@ -0,0 +1,6 @@
<% if params[:search] %>
$("#search_customers_list").html("<%= j(render :partial => "partners_list") %>")
<% else %>
var html="<%= escape_javascript(render :partial => "managements/customer_addUnit",locals: {all_path: customers_list_managements_path}) %>";
pop_box_new(html,572,500);
<% end %>

@ -15,6 +15,7 @@
<% end %>
</ul>
</div>
<% if @current_partner.present? %>
<div class="with75 fl pl20">
<div class="edu-back-white">
<div>
@ -23,14 +24,12 @@
<div class="clearfix">
<span class="mr45 color-grey-9 fl">管理员</span>
<ul class="manageList">
<% unless @current_partner.nil? %>
<li>
<%= link_to '+', add_partner_member_box_managements_path(:partner => @current_partner.try(:id)), :remote => true, :class => "addManage" %>
</li>
<div id="partner_member_list" class="fl">
<%= render :partial => "partner_member_list", :locals => {partner: @current_partner} %>
</div>
<% end %>
</ul>
</div>
</div>
@ -38,7 +37,8 @@
<li class="clearfix tableHead">
<span>序号</span>
<span>客户名称</span>
<span><a href="javascript:void(0)" class="color-blue">+添加</a></span>
<span><a href="<%= customers_list_managements_path(:partner_id => @current_partner.try(:id)) %>"
data-remote="true" class="color-blue">+添加</a></span>
<span>添加时间</span>
</li>
<% @current_partner.try(:customers).try(:each) do |customer| %>
@ -58,6 +58,8 @@
</div>
</div>
</div>
<% end %>
</div>
</div>
<script>

@ -711,6 +711,8 @@ RedmineApp::Application.routes.draw do ## oauth相关
post 'rename_subject_level'
post 'delete_subject_level'
post 'update_level_for_subject'
post :add_customers
get :customers_list
end
end
# Enable Grack support

Loading…
Cancel
Save