commit
b699322b15
@ -0,0 +1,74 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-salesman-channels-index-page').length > 0) {
|
||||||
|
|
||||||
|
// ============= 添加销售人员 ==============
|
||||||
|
var $addMemberModal = $('.admin-add-salesman-channel-user-modal');
|
||||||
|
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-channel-user-form');
|
||||||
|
var $memberSelect = $addMemberModal.find('.salesman-channel-user-select');
|
||||||
|
var $salesmanIdInput = $('.salesman-channel-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);
|
||||||
|
|
||||||
|
$memberSelect.select2('val', ' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
$memberSelect.select2({
|
||||||
|
theme: 'bootstrap4',
|
||||||
|
placeholder: '请输入要添加的单位',
|
||||||
|
multiple: true,
|
||||||
|
minimumInputLength: 1,
|
||||||
|
ajax: {
|
||||||
|
delay: 500,
|
||||||
|
url: '/admins/schools',
|
||||||
|
dataType: 'json',
|
||||||
|
data: function(params){
|
||||||
|
return { keyword: params.term };
|
||||||
|
},
|
||||||
|
processResults: function(data){
|
||||||
|
return { results: data.schools }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
templateResult: function (item) {
|
||||||
|
if(!item.id || item.id === '') return '';
|
||||||
|
return $("<span>" + item.name + "</span>");
|
||||||
|
},
|
||||||
|
templateSelection: function(item){
|
||||||
|
if (item.id) {
|
||||||
|
}
|
||||||
|
return item.name || '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$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_channels/batch_add',
|
||||||
|
data: { salesman_id: $salesmanIdInput.data("salesman-id"), school_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,28 @@
|
|||||||
|
class Admins::SalesmanChannelsController < Admins::BaseController
|
||||||
|
before_action :set_salesman
|
||||||
|
|
||||||
|
def index
|
||||||
|
@channels = SalesmanChannel.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def batch_add
|
||||||
|
channel_ids = @salesman.salesman_channels.pluck(:school_id)
|
||||||
|
school_ids = params[:school_ids] - channel_ids
|
||||||
|
school_ids.each do |school_id|
|
||||||
|
school = School.find_by(id: school_id)
|
||||||
|
next if school.blank?
|
||||||
|
@salesman.salesman_channels.create!(school_id: school.id)
|
||||||
|
end
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@salesman.salesman_channels.find_by!(id: params[:id]).destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_salesman
|
||||||
|
@salesman = Salesman.find params[:salesman_id]
|
||||||
|
end
|
||||||
|
end
|
@ -1,3 +1,27 @@
|
|||||||
class SalesmanChannel < ApplicationRecord
|
class SalesmanChannel < ApplicationRecord
|
||||||
belongs_to :salesman, :touch => true, counter_cache: true
|
belongs_to :salesman, :touch => true, counter_cache: true
|
||||||
|
belongs_to :school
|
||||||
|
|
||||||
|
def school_name
|
||||||
|
school.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def teacher_count
|
||||||
|
UserExtension.where(school_id: school_id).where.not(identity: 1).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def student_count
|
||||||
|
UserExtension.where(school_id: school_id, identity: 1).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def course_count
|
||||||
|
Course.where(school_id: school_id).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def shixuns_count
|
||||||
|
ShixunMember.joins("join user_extensions on user_extensions.user_id = shixun_members.user_id")
|
||||||
|
.where(user_extensions: {school_id: school_id}).pluck(:shixun_id).uniq.count
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
$.notify({ message: '操作成功' },{ type: 'success' });
|
||||||
|
$("<%= params[:element]%>").remove();
|
@ -0,0 +1,15 @@
|
|||||||
|
<% define_admin_breadcrumbs do %>
|
||||||
|
<% add_admin_breadcrumb("#{@salesman.name}的渠道", admins_salesmans_path) %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="box search-form-container salesman-channel-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-channel-user-modal' } %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box admin-list-container salesman-channel-list-container">
|
||||||
|
<%= render(partial: 'admins/salesman_channels/shared/list') %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render 'admins/salesman_channels/shared/add_salesman_channels_user_modal' %>
|
@ -0,0 +1,30 @@
|
|||||||
|
<div class="modal fade admin-add-salesman-channel-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>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<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-channel-user-select"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="error text-danger"></div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-primary submit-btn">确认</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,42 @@
|
|||||||
|
<table class="table table-hover text-center salesman-channel-list-table">
|
||||||
|
<thead class="thead-light">
|
||||||
|
<tr>
|
||||||
|
<th width="6%">序号</th>
|
||||||
|
<th width="17%" class="text-left">名称</th>
|
||||||
|
<th width="15%" class="text-left">教师数</th>
|
||||||
|
<th width="15%" class="text-left">学生数</th>
|
||||||
|
<th width="15%">课堂数</th>
|
||||||
|
<th width="15%">实训数</th>
|
||||||
|
<th width="17%">操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% if @channels.present? %>
|
||||||
|
<% @channels.each_with_index do |channel, index| %>
|
||||||
|
<tr class="channel-item salesman-channel-item-<%= channel.id %>">
|
||||||
|
<td><%= index + 1 %></td>
|
||||||
|
<td class="text-left">
|
||||||
|
<span><%= channel.school_name %></span>
|
||||||
|
</td>
|
||||||
|
<td class="text-left">
|
||||||
|
<span><%= channel.teacher_count %></span>
|
||||||
|
</td>
|
||||||
|
<td class="text-left">
|
||||||
|
<span><%= channel.student_count %></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= channel.course_count %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= channel.shixuns_count %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= delete_link '删除', admins_salesman_channel_path(channel, salesman_id: channel.salesman_id, element: ".salesman-channel-item-#{channel.id}"), class: 'delete-salesman-action' %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= render 'admins/shared/no_data_for_table' %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
@ -0,0 +1,6 @@
|
|||||||
|
json.count @total_count
|
||||||
|
json.schools do
|
||||||
|
json.array! @schools.each do |school|
|
||||||
|
json.extract! school, :id, :name
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddCodeHaltToCourseGroup < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :course_groups, :invite_code_halt, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in new issue