客户列表

sso
daiao 5 years ago
parent cccd6d751d
commit 970e8dc7a2

@ -0,0 +1,74 @@
$(document).on('turbolinks:load', function() {
if ($('body.admins-salesmans-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"]')
$addMemberModal.on('show.bs.modal', function(event){
var $link = $(event.relatedTarget);
var salesmanId = $link.data('salesman-id');
$salesmanIdInput.val(salesmanId);
$memberSelect.select2('val', ' ');
});
$memberSelect.select2({
theme: 'bootstrap4',
placeholder: '请输入要添加的销售姓名',
multiple: true,
minimumInputLength: 1,
ajax: {
delay: 500,
url: '/admins/users',
dataType: 'json',
data: function(params){
return { name: params.term };
},
processResults: function(data){
return { results: data.users }
}
},
templateResult: function (item) {
if(!item.id || item.id === '') return item.text;
return $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
},
templateSelection: function(item){
if (item.id) {
}
return item.real_name || item.text;
}
});
$addMemberModal.on('click', '.submit-btn', function(){
$addMemberForm.find('.error').html('');
// var salesmanId = $salesmanIdInput.val();
var memberIds = $memberSelect.val();
if (memberIds && memberIds.length > 0) {
$.ajax({
method: 'POST',
dataType: 'json',
url: '/admins/salesman_customers/batch_add',
data: { user_ids: memberIds },
success: function(){
$.notify({ message: '创建成功' });
$addMemberModal.modal('hide');
setTimeout(function(){
window.location.reload();
}, 500);
},
error: function(res){
var data = res.responseJSON;
$form.find('.error').html(data.message);
}
});
} else {
$addMemberModal.modal('hide');
}
});
}
});

@ -0,0 +1,13 @@
class Admins::SalesmanCustomersController < Admins::BaseController
before_action :set_salesman
def index
@customers = @salesman.salesman_customers.includes(:user, :school)
end
private
def set_salesman
@salesman = Salesman.find params[:salesman_id]
end
end

@ -1,4 +1,22 @@
class SalesmanCustomer < ApplicationRecord
belongs_to :salesman, :touch => true, counter_cache: true
belongs_to :school
belongs_to :user
def name
user.real_name
end
def school_name
school.name
end
def courses_count
CourseMember.where(user_id: id).teachers_and_admin.count
end
def shixuns_count
ShixunMember.where(user_id: id, role: [1, 2]).count
end
end

@ -0,0 +1,15 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb("#{@salesman.name}的客户", admins_salesmans_path) %>
<% end %>
<div class="box search-form-container salesman-customer-list-form rig">
<div class="flex-1">
<%= javascript_void_link '新增客户', class: 'btn btn-primary', data: {salesman_id: @salesman.id, toggle: 'modal', target: '.admin-add-salesman-customer-user-modal' } %>
</div>
</div>
<div class="box admin-list-container salesman-customer-list-container">
<%= render(partial: 'admins/salesman_customers/shared/list') %>
</div>
<%= render 'admins/salesman_customers/shared/add_salesman_customers_user_modal' %>

@ -1,18 +1,25 @@
<div class="modal fade admin-edit-salesman-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade admin-add-salesman-customer-user-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">编辑技术体系</h5>
<h5 class="modal-title">添加客户</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<%= simple_form_for([:admins, salesman], html: { class: 'admin-edit-salesman-form' }, defaults: { wrapper_html: { class: 'offset-md-1 col-md-10' } }) do |f| %>
<%= f.input :name, as: :string, label: '名称' %>
<form class="admin-add-salesman-user-form">
<%= hidden_field_tag(:salesman_id, nil) %>
<div class="form-group d-flex">
<label class="col-form-label">姓名:</label>
<div class="d-flex flex-column-reverse w-75">
<select id="user_ids" name="user_ids" class="form-control salesman-customer-user-select"></select>
</div>
</div>
<div class="error text-danger"></div>
<% end %>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>

@ -0,0 +1,34 @@
<table class="table table-hover text-center salesman-customer-list-table">
<thead class="thead-light">
<tr>
<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>
</tr>
</thead>
<tbody>
<% if @customers.present? %>
<% @customers.each_with_index do |customer, index| %>
<tr class="customer-item salesman-customer-item-<%= customer.id %>">
<td><%= index + 1 %></td>
<td class="text-left">
<span><%= link_to customer.name, user_path(customer), :title => customer.name %></span>
</td>
<td class="text-left">
<span><%= customer.school_name %></span>
</td>
<td class="text-left">
<span><%= customer.courses_count %></span>
</td>
<td>
<%= customer.shixuns_count %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>

@ -3,8 +3,8 @@
<tr>
<th width="6%">序号</th>
<th width="20%" class="text-left">名称</th>
<th width="30%" class="text-left">客户数(点击进入客户列表)</th>
<th width="30%" class="text-left">渠道数(点击进入渠道列表)</th>
<th width="30%" class="text-left">客户数(点击数字客户列表)</th>
<th width="30%" class="text-left">渠道数(点击数字渠道列表)</th>
<th width="14%">操作</th>
</tr>
</thead>

Loading…
Cancel
Save