You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.8 KiB
74 lines
2.8 KiB
5 years ago
|
$(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');
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|