{% extends 'obj_form.html' %} {% load i18n %} {% block js %} {{ block.super }} //目前先只考虑指定大区 {% ifequal request.user.company.id 1644 %} $('#subsaldiv_id,.add-subsaldiv,#agent_label,.add-agent').attr('disabled',true); {% else %} {% endifequal %} $('#user_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/user/', dataType: "json", data: { term: $("#user_label").val() ,//搜索栏里的内容 company_id: $('#id_company').val() ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#id_user").val(ui.item.value); $("#user_label").val(ui.item.label); $('#user_name').text(ui.item.user_name); $('#user_group').text(ui.item.groups); return false; } }); $('#saldiv_id').change(function(){ var saldiv_id=$(this).val(); if (saldiv_id==''){ $('#subsaldiv_id').empty(); $('#subsaldiv_id').append('') }else{ get_subdivs(saldiv_id); } }); function get_subdivs(saldiv_id){ var me=$('#subsaldiv_id'); $.ajax({ url: "/obj/ajax/subsaldiv/"+saldiv_id+"/", success: function(data) { $(me).empty(); $.each(data,function(i,d){$(me).append("")}); }, dataType: 'json' }); }; $('#agent_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/agent/', dataType: "json", data: { term: $("#agent_label").val() ,//搜索栏里的内容 company_id: $('#id_company').val() ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#agent_id").val(ui.item.value); $("#agent_label").val(ui.item.label); return false; } }); {% if form.instance.id %} $('#user_label').val('{{form.instance.user.username}}'); $('#user_id').val('{{form.instance.user.id}}'); $('#user_name').text('{{form.instance.user.last_name}}');; var a=[]; {% for g in form.instance.user.groups.all %} a.push('{{g.name}}'); {% endfor %}; if(a.length>0){ $('#user_group').text(a.join(',')); }; {% endif %} $('.add-saldiv').click(function(){ var id=$('#saldiv_id').val(); var label= $('#saldiv_id').find("option:selected").text(); if(id==''){ toastr.error("请先选择营销战区!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-saldiv 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-saldiv').append(""); } }; }); $('.add-subsaldiv').click(function(){ var id=$('#subsaldiv_id').val(); var label=$('#subsaldiv_id').find("option:selected").text(); if(id==''){ toastr.error("请先选择营销片区!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-subsaldiv 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-subsaldiv').append(""); } }; }); $('.add-agent').click(function(){ var id=$('#agent_id').val(); var label=$('#agent_label').val(); if(id==''){ toastr.error("请先选择经销商!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-agent 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-agent').append(""); } }; }); $('.select2_multiple').on('dblclick','option',function(){ $(this).remove(); }); $('.btn-save').click(function(){ event.preventDefault(); var a=[]; $("#sel-saldiv option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_saldiv_ids').val(a.join(',')); }else{ $('#id_saldiv_ids').val(''); }; a=[]; $("#sel-agent option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_agent_ids').val(a.join(',')); }else{ $('#id_agent_ids').val(''); }; a=[]; $("#sel-subsaldiv option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_subsaldiv_ids').val(a.join(',')); }else{ $('#id_subsaldiv_ids').val(''); }; $.SubmitForm('#obj_form form','{{request.path}}'); }); $('.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 subtitle-3 %} {% if form.instance.id %} {% trans "修改" %} {% else %} {% trans "新建" %} {% endif %} {% endblock %} {% block form_content %} {{ block.super }}