{% load i18n %}


<script type="text/javascript">
    $(document).ready(function(){  
        $('#company_old_name').autocomplete({
            source: {{company|safe}},
            select: function (event, ui) {
                $("#company_old_id").val(ui.item.value);
                $("#company_old_name").val(ui.item.label);
                return false;
            }
        });


        $('#company_old_id').val('0');
        $('#company_new_id').val('0');


        
        $('#company_new_name').autocomplete({
            source: {{company|safe}},
            select: function (event, ui) {              
                $("#company_new_id").val(ui.item.value);
                $("#company_new_name").val(ui.item.label);
                return false;
            }
        });          
           
        $('.btn-transfer').click(function(){
            var id_n=$('#company_new_id').val();
            var id_o=$('#company_old_id').val();
            if(id_n=='0' || id_o=='0'){   
                toastr.error(
                    "请先选择要转出和转入库存的经销商！",
                    "操作错误：",
                    {timeOut: 1000, positionClass: "toast-center-center"}
                );                
                
            }else{
                var title="{% trans  '转移经销商库存' %}";
                var content="您确定要将 <span style='color:red;font-weight:bold;'>"+
                    $('#company_old_name').val()+"</span>"+
                    " 下的库存转移到 "+"<span style='color:green;font-weight:bold;'>"+
                    $('#company_new_name').val()+"</span> 吗?";                
                $.OpenCfmDlg(title,content);
                
            }
        });
    });
    $('#confirm-modal .btn-confirm').click(function(){      
        var id_n=$('#company_new_id').val();
        var id_o=$('#company_old_id').val();
        $('#data-content .btn').hide();
        
        $.ajax({
            type:'POST',            
            data:{company_id_old:id_o,company_id_new:id_n,csrfmiddlewaretoken: '{{ csrf_token }}'},      
            url:'{{request.path}}',
            success:function(res){
                $("#confirm-modal").modal('hide');
                $('#data-content .btn').show();
                toastr.success(
                    "经销商库存转移完成("+res.cnt+")！",
                    "操作成功：",
                    {timeOut: 1200, positionClass: "toast-center-center"}
                );
                return;
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                $("#confirm-modal").modal('hide');
                $('#data-content .btn').show();
                toastr.error(
                    "连接服务器失败！",
                    "网络错误：",
                    {timeOut: 1000, positionClass: "toast-center-center"}
                );
                return;
            }
        });  
    });
</script>





    <ol class="breadcrumb">
        <li>{% trans "物流工具" %}</li>
        <li>{% trans "经销商库存转移" %}</li>
    </ol>




<div class='x_panel'>
<br/>
<div class="x_content">
<div id="obj_form"  >   
    <form> {% csrf_token %}
    <div class="col-md-12 form-group has-feedback">
        <input id='company_old_id' type='hidden' name='company_old_id' />
        <input type="text" class="form-control has-feedback-left" id="company_old_name" placeholder='{% trans "要转出库存的经销商名称"   %}' />
        <span class="fa fa-minus-circle form-control-feedback left" aria-hidden="true"></span>
    </div>

    <div class="col-md-12 form-group has-feedback">
        <input id='company_new_id' type='hidden' name='company_new_id' />
        <input type="text" class="form-control has-feedback-left"  id="company_new_name" placeholder='{% trans "要转入库存的经销商名称" %}'/>
        <span class="fa fa-plus-circle form-control-feedback left" aria-hidden="true"></span>
    </div>  
      

    <br/>
    <div class="col-md-12 form-group ">
        <span class="btn btn-primary btn-transfer">{% trans "转移经销商库存" %}</span>
    </div>
    </form>
    
</div>
</div>
</div>











