{% extends 'obj_form.html' %} {% load i18n %} {% load tj_filters %} {% block css %} {{ block.super }} #obj_form .datepicker{ width:100px } #obj_form select.adm{ min-width:100px; margin-left:5px; } #product_label{ min-width:380px; margin-left:15px; margin-right:7px; } #obj_form .btn-del{ float:right; } {% endblock %} {% block js %} {{ block.super }} var dt1,dt2; dt1=new Date(); dt2=new Date(); dt2.setFullYear(dt1.getFullYear(),11,31); $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'}); $('#dt1,#dt1_product').datepicker('setDate',dt1); $('#dt2,#dt2_product').datepicker('setDate',dt2); setDatePickerZh(); $('#product_label').autocomplete({ source: {{products|safe}}, select: function (event, ui) { $("#product_id").val(ui.item.value); $("#product_label").val(ui.item.label); return false; } }); {% ifequal request.user.company.level.sn 0 %} $('#parent_label').autocomplete({ source: {{children|safe}}, select: function (event, ui) { var pid=ui.item.value; $("#id_parent").val(pid); $("#parent_label").val(ui.item.label); $.get( '/company/child/level/'+pid+'/', function(obj){ if (obj.level.id<0){ //bootbox.alert(obj.level.e); toastr.error( obj.level.e, "数据错误:", {timeOut: 800, positionClass: "toast-center-center"} ); }else{ $('#lv').text(obj.level.name); } } ); return false; } }); {% endifequal %} //被删除的授权ID var auth_del_ids=[]; var auth_del_ids_product=[]; $("#province").change(function() { var province_id = $(this).val(); getCity(province_id); }); $("#city").change(function() { var city_id = $(this).val(); getArea(city_id); }); function getCity(province_id) { var me=$("#city"); $.ajax({ url: "http://117.34.70.23:32176/gis/adm/2/"+province_id+"/", success: function(data) { $(me).empty(); $('#area').empty(); $.each(data,function(i,d){$(me).append("")}); $(me).append(""); }, dataType: 'jsonp', jsonp: 'callback' }); }; function getArea(city_id) { var me=$('#area'); $.ajax({ url: "http://117.34.70.23:32176/gis/adm/3/"+city_id+"/", success: function(data) { $(me).empty(); $.each(data,function(i,d){$(me).append("")}); $(me).append(""); }, dataType: 'jsonp', jsonp: 'callback' }); }; $('#tb_auth input[type="checkbox"]').removeClass('form-control'); // 列表中是否已有指定 adm_id function has_adm(id){ var b=0; $(".adm_id").each(function(i,el){ if($(el).val()==id){ b=1; return; }; }); return b; }; $("#tb_auth").on("click",".btn-del",function(){ var id=$(this).closest('tr').find('.auth_id').val(); if (id!=''){ auth_del_ids.push(parseInt(id)); }; $(this).closest('tr').remove(); }); // 列表中是否已有指定 product_id function has_product(id){ var b=0; $(".product_id").each(function(i,el){ if($(el).val()==id){ b=1; return; }; }); return b; }; $("#tb_auth_product").on("click",".btn-del",function(){ var id=$(this).closest('tr').find('.auth_id').val(); if (id!=''){ auth_del_ids_product.push(id); }; $(this).closest('tr').remove(); }); //添加销售区域授权 $('.btn-add').click(function(){ var id=''; if(!$.isEmpty($('#area').val())){ id=$('#area').val(); } else { if (!$.isEmpty($('#city').val())){ id=$('#city').val(); }else{ if(!$.isEmpty($('#province').val())){ id=$('#province').val(); } } } if(id==''){ //bootbox.alert("{% trans '请先选择授权区域!' %}"); toastr.error( "请先选择授权区域!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }; if (has_adm(id)){ //bootbox.alert("{% trans '当前授权区域已在列表中!' %}"); toastr.error( "当前授权区域已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }; var html=''+ ''+ ''+ ''+ ''+ ''+$('#province').find("option:selected").text()+''+ ''+$('#city').find("option:selected").text()+''+ ''+$('#area').find("option:selected").text()+''+ ''+$('#dt1').val()+''+$('#dt2').val()+''+ '{% trans '删除' %} '+ ''; $('#tb_auth tbody').append(html); }); //添加授权产品 $('.btn-add-product').click(function(){ var id=$('#product_id').val(); if(id==''){ //bootbox.alert("{% trans '请先选择要授权的产品!' %}"); toastr.error( "请先选择要授权的产品!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }; if (has_product(id)){ //bootbox.alert("{% trans '当前授权的产品已在列表中!' %}"); toastr.error( "当前授权的产品已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }; var html=''+ ''+ ''+ ''+ ''+ ''+$('#product_label').val()+''+ ''+$('#dt1_product').val()+''+$('#dt2_product').val()+''+ '{% trans '删除' %} '+ ''; $('#tb_auth_product tbody').append(html); }); $('.btn-save').click(function(){ $('.btn').hide(); //保存删除的区域授权ID var cnt=$('#tb_auth tbody').find("tr").length; var s=''; if (auth_del_ids.length>0){ s=auth_del_ids.join(','); }; $('#obj_form form').append(''); $('#obj_form form').append(''); //保存删除的产品授权ID var cnt_product=$('#tb_auth_product tbody').find("tr").length; var s=''; if (auth_del_ids_product.length>0){ s=auth_del_ids_product.join(','); }; $('#obj_form form').append(''); $('#obj_form form').append(''); //修改授权区域 name后缀 $('#tb_auth tbody tr').each(function(i,d){ $(this).find('.auth_id').attr('name','auth_id_'+i); $(this).find('.adm_id').attr('name','adm_id_'+i); $(this).find('.dt_fr').attr('name','dt_fr_'+i); $(this).find('.dt_to').attr('name','dt_to_'+i); }); //修改授权品 name后缀 $('#tb_auth_product tbody tr').each(function(i,d){ $(this).find('.auth_id').attr('name','cp_auth_id_'+i); $(this).find('.product_id').attr('name','cp_product_id_'+i); $(this).find('.dt_fr').attr('name','cp_dt_fr_'+i); $(this).find('.dt_to').attr('name','cp_dt_to_'+i); }); $.SubmitForm('#obj_form form','{{request.path}}'); }); //经销商可以设置其下经销商为终端店 $('#is_terminal').change(function(){ if($(this).prop("checked") == true){ $('#id_level').val('3'); }else{ $('#id_level').val(''); } }); {% ifequal level.id 3 %} $('#is_terminal').prop('checked',true); {% endifequal %} $('#id_division').change(function(){ var me=$('#id_sub_division'); var d=$(this).val(); $('#id_sub_division').empty(); if (d!=''){ $.ajax({ url: "/company/json/subdivision/"+d+"/", success: function(data) { data=data.details; $.each(data,function(i,d){$(me).append("")}); $(me).append(""); } }); } }); {% if jg_ty %} $('[name="sync_ty"]').closest('label').removeClass('active'); {% ifequal sync_ty '1' %} $("#ty_yes") .prop('checked', true) .closest('label').addClass('active'); {% else %} $('#ty_no') .prop('checked', false) .closest('label').addClass('active'); {% endifequal %} {% endif %} {% if form.instance %} {% if form.instance.parent %} $('#id_parent').val({{form.instance.parent_id}}); $('#parent_label').val('{{form.instance.parent.name}}'); {% else %} $('#id_parent').val({{parent.id}}); $('#parent_label').val('{{parent.name}}'); {% endif %} {% endif %} {% endblock %} {% block subtitle-1 %} {% trans '经销商管理' %} {% endblock %} {% block subtitle-2 %} {% trans '经销商信息' %} {% endblock %} {% block form_content %} {{ block.super }} {% if parent.has_external_code %}
{{ form.external_code }}
{% endif %}
{{ form.name }}
{% if request.user.company.is_microboss %} {% else %} {% ifequal request.user.company.level.sn 0 %}
{% if form.instance.id %} {{ form.instance.level.name }} {% else %} {{parent.child_level.name}} {% endif %}
{{ form.division }}
{{ form.sub_division }}
{% else %}
{% endifequal %} {% endif %}
{{ form.cell_phone }}
{{ form.address }}
{% trans '保存' %}
{% endblock %}