diff --git a/app/assets/javascripts/admins/salesmans/index.js b/app/assets/javascripts/admins/salesmans/index.js new file mode 100644 index 000000000..c7d4b416b --- /dev/null +++ b/app/assets/javascripts/admins/salesmans/index.js @@ -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 $("" + item.real_name + " " + item.school_name + ' ' + item.hidden_phone + ""); + }, + 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 + }); + }); + } +}); \ No newline at end of file diff --git a/app/controllers/admins/salesmans_controller.rb b/app/controllers/admins/salesmans_controller.rb new file mode 100644 index 000000000..436f16262 --- /dev/null +++ b/app/controllers/admins/salesmans_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/salesman.rb b/app/models/salesman.rb new file mode 100644 index 000000000..a1a025776 --- /dev/null +++ b/app/models/salesman.rb @@ -0,0 +1,7 @@ +class Salesman < ApplicationRecord + belongs_to :user + # 渠道 + has_many :salesman_channels, dependent: :destroy + # 客户 + has_many :salesman_customers, dependent: :destroy +end diff --git a/app/models/salesman_channel.rb b/app/models/salesman_channel.rb new file mode 100644 index 000000000..473cdbba9 --- /dev/null +++ b/app/models/salesman_channel.rb @@ -0,0 +1,3 @@ +class SalesmanChannel < ApplicationRecord + belongs_to :salesman, :touch => true, counter_cache: true +end diff --git a/app/models/salesman_customer.rb b/app/models/salesman_customer.rb new file mode 100644 index 000000000..cfa732b1e --- /dev/null +++ b/app/models/salesman_customer.rb @@ -0,0 +1,4 @@ +class SalesmanCustomer < ApplicationRecord + belongs_to :salesman, :touch => true, counter_cache: true + belongs_to :school +end diff --git a/app/views/admins/repertoires/shared/_list.html.erb b/app/views/admins/repertoires/shared/_list.html.erb deleted file mode 100644 index c014f6e09..000000000 --- a/app/views/admins/repertoires/shared/_list.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -
序号 | -技术体系 | -操作 | -
---|---|---|
<%= index + 1 %> | -- <%= link_to repertoire.name, admins_sub_repertoires_path(repertoire_id: repertoire), :title => repertoire.name %> - | -- <%= 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' %> - | -