{% extends 'obj_form.html' %} {% load i18n %} {% block js %} {{ block.super }} $('#user_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/salesman_lastname/', dataType: "json", data: { term: $("#user_label").val() ,//搜索栏里的内容 company_id: '{{request.user.company.id}}' ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#user_id").val(ui.item.value); $("#user_label").val(ui.item.label); return false; } }); $('.add-user').click(function(){ var id=$('#user_id').val(); var label=$('#user_label').val(); if(id==''){ toastr.error("请先选择经销商!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-users option").each(function(){ if($(this).val() == id){ e=true; return false; } }); if(e){ toastr.error(label+"已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ $('#sel-users').append(""); } }; }); $('.select2_multiple').on('dblclick','option',function(){ $(this).remove(); }); $('.btn-save').click(function(){ event.preventDefault(); var a=[]; $("#sel-users option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_user_ids').val(a.join(',')); }else{ $('#id_user_ids').val(''); }; $("#obj_form form").ajaxSubmit({ type: 'post', url: '/company/saleman/manage/?obj=sharegroup', success: function(html) { // 在saleman.html里面定义 refresh_tb('sharegroup') $('#bg-modal').modal('hide') }, error: function(XMLHttpRequest, textStatus, errorThrown) { $('.btn-save').show(); alert('连接服务器失败'); } }); }); $('.btn-delete').click(function(){ event.preventDefault(); $.ajax({ url: "/company/edit/staffdiv/{{form.instance.id}}/delete/", type: 'POST', headers:{'X-CSRFToken': $('input[name="csrfmiddlewaretoken"]').val()}, success:function(data){ jQuery.RefreshContent('/company/list/staffdiv/'); } }); }); {% endblock %} {% block subtitle-1 %} {% trans "业务员管理" %} {% endblock %} {% block subtitle-2 %} {% trans "共享小组" %} {% endblock %} {% block form_content %} {{ block.super }}