parent
583052173e
commit
cccd6d751d
@ -0,0 +1,99 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-salesmans-index-page').length > 0) {
|
||||||
|
|
||||||
|
// ============= 添加销售人员 ==============
|
||||||
|
var $addMemberModal = $('.admin-add-salesman-user-modal');
|
||||||
|
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-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/salesmans/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');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".salesman-list-container").on("change", '.salesman-sync-course', function () {
|
||||||
|
var s_id = $(this).attr("data-id");
|
||||||
|
var json = {};
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/salesmans/" + s_id + "/update_sync_course",
|
||||||
|
type: "POST",
|
||||||
|
dataType:'script',
|
||||||
|
data: json
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".salesman-list-container").on("change", '.salesman-sync-form', function () {
|
||||||
|
var s_id = $(this).attr("data-id");
|
||||||
|
var s_value = $(this).val();
|
||||||
|
var s_name = $(this).attr("name");
|
||||||
|
var json = {};
|
||||||
|
json[s_name] = s_value;
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/salesmans/" + s_id,
|
||||||
|
type: "PUT",
|
||||||
|
dataType:'script',
|
||||||
|
data: json
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,29 @@
|
|||||||
|
class Admins::SalesmansController < Admins::BaseController
|
||||||
|
before_action :set_salesman, except: [:index, :batch_add]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@salesmans = Salesman.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@salesman.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
# 批量增加销售人员
|
||||||
|
def batch_add
|
||||||
|
salesman_user_ids = Salesman.where(id: params[:user_ids]).pluck(:user_id)
|
||||||
|
user_ids = params[:user_ids] - salesman_user_ids
|
||||||
|
user_ids.each do |user_id|
|
||||||
|
user = User.find_by(id: user_id)
|
||||||
|
next if user.blank?
|
||||||
|
Salesman.create!(user_id: user.id, name: user.real_name)
|
||||||
|
end
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_salesman
|
||||||
|
@salesman = Salesman.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,7 @@
|
|||||||
|
class Salesman < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
# 渠道
|
||||||
|
has_many :salesman_channels, dependent: :destroy
|
||||||
|
# 客户
|
||||||
|
has_many :salesman_customers, dependent: :destroy
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
class SalesmanChannel < ApplicationRecord
|
||||||
|
belongs_to :salesman, :touch => true, counter_cache: true
|
||||||
|
end
|
@ -0,0 +1,4 @@
|
|||||||
|
class SalesmanCustomer < ApplicationRecord
|
||||||
|
belongs_to :salesman, :touch => true, counter_cache: true
|
||||||
|
belongs_to :school
|
||||||
|
end
|
@ -1,27 +0,0 @@
|
|||||||
<table class="table table-hover text-center repertoires-list-table">
|
|
||||||
<thead class="thead-light">
|
|
||||||
<tr>
|
|
||||||
<th width="6%">序号</th>
|
|
||||||
<th width="54%" class="text-left">技术体系</th>
|
|
||||||
<th width="16%">操作</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<% if @repertoires.present? %>
|
|
||||||
<% @repertoires.each_with_index do |repertoire, index| %>
|
|
||||||
<tr class="repertoire-item discipline-item-<%= repertoire.id %>">
|
|
||||||
<td><%= index + 1 %></td>
|
|
||||||
<td class="text-left">
|
|
||||||
<span><%= link_to repertoire.name, admins_sub_repertoires_path(repertoire_id: repertoire), :title => repertoire.name %></span>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<%= link_to '编辑', edit_admins_repertoire_path(repertoire), remote: true, class: 'action' %>
|
|
||||||
<%= delete_link '删除', admins_repertoire_path(repertoire, element: ".repertoire-item-#{repertoire.id}"), class: 'delete-repertoire-action' %>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
|
||||||
<%= render 'admins/shared/no_data_for_table' %>
|
|
||||||
<% end %>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
@ -0,0 +1,3 @@
|
|||||||
|
$.notify({ message: '操作成功' },{ type: 'success' });
|
||||||
|
console.log()
|
||||||
|
$(".salesman-item-<%= params[:id]%>").remove();
|
@ -0,0 +1,15 @@
|
|||||||
|
<% define_admin_breadcrumbs do %>
|
||||||
|
<% add_admin_breadcrumb('销售数据列表', admins_salesmans_path) %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="box search-form-container salesman-list-form rig">
|
||||||
|
<div class="flex-1">
|
||||||
|
<%= javascript_void_link '新增销售人员', class: 'btn btn-primary', data: { toggle: 'modal', target: '.admin-add-salesman-user-modal' } %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box admin-list-container salesman-list-container">
|
||||||
|
<%= render(partial: 'admins/salesmans/shared/list') %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render 'admins/salesmans/shared/add_salesman_user_modal' %>
|
@ -1,18 +1,20 @@
|
|||||||
<div class="modal fade admin-create-repertoire-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
<div class="modal fade admin-add-salesman-user-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<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">
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form class="admin-create-repertoire-form" data-url="<%= admins_repertoires_path %>">
|
<form class="admin-add-salesman-user-form">
|
||||||
|
<%= hidden_field_tag(:salesman_id, nil) %>
|
||||||
|
|
||||||
<div class="form-group d-flex">
|
<div class="form-group d-flex">
|
||||||
<label for="new_mirror_id" class="col-form-label">名称:</label>
|
<label class="col-form-label">姓名:</label>
|
||||||
<div class="w-75 d-flex flex-column">
|
<div class="d-flex flex-column-reverse w-75">
|
||||||
<%= text_field_tag(:name, nil, class: 'form-control', placeholder: '请输入名称') %>
|
<select id="user_ids" name="user_ids" class="form-control salesman-user-select"></select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -0,0 +1,37 @@
|
|||||||
|
<table class="table table-hover text-center salesman-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="30%" class="text-left">渠道数(点击进入渠道列表)</th>
|
||||||
|
<th width="14%">操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% if @salesmans.present? %>
|
||||||
|
<% @salesmans.each_with_index do |salesman, index| %>
|
||||||
|
<tr class="salesman-item salesman-item-<%= salesman.id %>">
|
||||||
|
<td><%= index + 1 %></td>
|
||||||
|
<td class="text-left">
|
||||||
|
<span><%= link_to salesman.name, admins_salesman_path(salesman), :title => salesman.name %></span>
|
||||||
|
</td>
|
||||||
|
<td class="text-left">
|
||||||
|
<span><%= link_to salesman.salesman_customers_count.to_i,
|
||||||
|
admins_salesman_customers_path(salesman_id: salesman), :title => "点击进入客户列表" %></span>
|
||||||
|
</td>
|
||||||
|
<td class="text-left">
|
||||||
|
<span><%= link_to salesman.salesman_channels_count.to_i, admins_salesman_channels_path(salesman_id: salesman),
|
||||||
|
:title => "点击进入渠道列表" %></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= delete_link '删除', admins_salesman_path(salesman, element: ".salesman-item-#{salesman.id}"),
|
||||||
|
class: 'delete-salesman-action' %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= render 'admins/shared/no_data_for_table' %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
@ -0,0 +1,11 @@
|
|||||||
|
class CreateSalesmen < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :salesmen do |t|
|
||||||
|
t.references :user
|
||||||
|
t.string :name
|
||||||
|
t.integer :salesman_channels_count
|
||||||
|
t.integer :salesman_customers_count
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,9 @@
|
|||||||
|
class CreateSalesmanChannels < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :salesman_channels do |t|
|
||||||
|
t.references :salesman
|
||||||
|
t.references :school
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,10 @@
|
|||||||
|
class CreateSalesmanCustomers < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :salesman_customers do |t|
|
||||||
|
t.references :salesman
|
||||||
|
t.references :user
|
||||||
|
t.references :school
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe SalesmanChannel, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe SalesmanCustomer, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Salesman, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in new issue