From 53e792918bda655622604c5299309420bb69b19c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Apr 2019 14:48:35 +0800 Subject: [PATCH] 1 --- app/controllers/managements_controller.rb | 49 +++++++++ .../managements/_customer_addUnit.html.erb | 100 ++++++++++++++++++ app/views/managements/customers_list.js.erb | 6 ++ app/views/managements/partners.html.erb | 3 +- config/routes.rb | 2 + 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 app/views/managements/_customer_addUnit.html.erb create mode 100644 app/views/managements/customers_list.js.erb diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index c92ae34d..20e40fc6 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1193,6 +1193,53 @@ end end + # 添加客户 + def customers_list + @search = params[:search] + @province = params[:province] + partner_id = params[:partner] + @partner = Partner.find partner_id + @customers = @partner.customers + customer_id = @customers.present? ? @customers.map(&:id).join(",") : -1 + @schools = School.where("partner_id != ? and customer_id not in(#{customer_id})", @partner.id) + + if params[:search] + @schools = @schools.where("name like ?", "%#{@search}%") + end + + if params[:province] + @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] @@ -1238,6 +1285,8 @@ end + + # 删除部门管理员 def delete_depart_member DepartmentMember.where(:department_id => params[:depart], :user_id => params[:user_id]).destroy_all diff --git a/app/views/managements/_customer_addUnit.html.erb b/app/views/managements/_customer_addUnit.html.erb new file mode 100644 index 00000000..17f31b47 --- /dev/null +++ b/app/views/managements/_customer_addUnit.html.erb @@ -0,0 +1,100 @@ +
+
添加合作伙伴
+
+
+
+ <%= render partial: "managements/partner_search_form" %> +
+ 搜索 +
+
+

+ 单位 + 地区 +

+
+ <%= render :partial => "partners_list" %> +
+

+
+ +
  • + 取消 + 确定 +
  • +
    +
    + \ No newline at end of file diff --git a/app/views/managements/customers_list.js.erb b/app/views/managements/customers_list.js.erb new file mode 100644 index 00000000..5068df4f --- /dev/null +++ b/app/views/managements/customers_list.js.erb @@ -0,0 +1,6 @@ +<% if params[:search] %> + $("#search_user_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 %> diff --git a/app/views/managements/partners.html.erb b/app/views/managements/partners.html.erb index b7471786..7eeb80a0 100644 --- a/app/views/managements/partners.html.erb +++ b/app/views/managements/partners.html.erb @@ -44,7 +44,8 @@
  • 序号 客户名称 - +添加 + +添加 添加时间
  • <% @current_partner.try(:customers).try(:each) do |customer| %> diff --git a/config/routes.rb b/config/routes.rb index 2b826b52..c3ac80c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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