销售人员客户列表

sso
daiao 5 years ago
parent effeb25e45
commit 3dcb5dba9d

@ -1,16 +1,16 @@
$(document).on('turbolinks:load', function() {
if ($('body.admins-salesmans-index-page').length > 0) {
if ($('body.admins-salesman-customers-index-page').length > 0) {
// ============= 添加销售人员 ==============
var $addMemberModal = $('.admin-add-salesman-customer-user-modal');
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-customer-user-form');
var $memberSelect = $addMemberModal.find('.salesman-user-select');
// var $salesmanIdInput = $addMemberForm.find('input[name="salesman_id"]')
var $memberSelect = $addMemberModal.find('.salesman-customer-user-select');
var $salesmanIdInput = $('.salesman-customer-list-form').find(".btn-primary");
$addMemberModal.on('show.bs.modal', function(event){
var $link = $(event.relatedTarget);
var salesmanId = $link.data('salesman-id');
$salesmanIdInput.val(salesmanId);
// var salesmanId = $link.data('salesman_id');
// $salesmanIdInput.val(salesmanId);
$memberSelect.select2('val', ' ');
});
@ -52,7 +52,7 @@ $(document).on('turbolinks:load', function() {
method: 'POST',
dataType: 'json',
url: '/admins/salesman_customers/batch_add',
data: { user_ids: memberIds },
data: { salesman_id: $salesmanIdInput.data("salesman-id"), user_ids: memberIds },
success: function(){
$.notify({ message: '创建成功' });
$addMemberModal.modal('hide');

@ -5,6 +5,21 @@ class Admins::SalesmanCustomersController < Admins::BaseController
@customers = @salesman.salesman_customers.includes(:user, :school)
end
def batch_add
customer_ids = @salesman.salesman_customers.pluck(:user_id)
user_ids = params[:user_ids] - customer_ids
user_ids.each do |user_id|
user = UserExtension.find_by(user_id: user_id)
next if user.blank?
@salesman.salesman_customers.create!(user_id: user.user_id, school_id: user.school_id)
end
render_ok
end
def destroy
@salesman.salesman_customers.find_by!(id: params[:id]).destroy
end
private
def set_salesman
@salesman = Salesman.find params[:salesman_id]

@ -0,0 +1,2 @@
$.notify({ message: '操作成功' },{ type: 'success' });
$("<%= params[:element]%>").remove();

@ -4,8 +4,9 @@
<th width="6%">序号</th>
<th width="20%" class="text-left">名称</th>
<th width="30%" class="text-left">单位</th>
<th width="22%" class="text-left">课堂数</th>
<th width="22%">实训数</th>
<th width="12%" class="text-left">课堂数</th>
<th width="12%">实训数</th>
<th width="20%">操作</th>
</tr>
</thead>
<tbody>
@ -25,6 +26,9 @@
<td>
<%= customer.shixuns_count %>
</td>
<td>
<%= delete_link '删除', admins_salesman_customer_path(customer, salesman_id: customer.salesman_id, element: ".salesman-customer-item-#{customer.id}"), class: 'delete-salesman--action' %>
</td>
</tr>
<% end %>
<% else %>

@ -1,3 +1,2 @@
$.notify({ message: '操作成功' },{ type: 'success' });
console.log()
$(".salesman-item-<%= params[:id]%>").remove();

@ -1361,7 +1361,9 @@ Rails.application.routes.draw do
post :batch_add, on: :collection
end
resources :salesman_channels, only: [:index, :create, :edit, :update, :destroy]
resources :salesman_customers, only: [:index, :create, :edit, :update, :destroy]
resources :salesman_customers, only: [:index, :create, :edit, :update, :destroy] do
post :batch_add, on: :collection
end
end
namespace :cooperative do

Loading…
Cancel
Save