{% load i18n %}

<ol class="breadcrumb">
    <li>  {% trans "经销商出入库查询" %}</li>
</ol>

<script type="text/javascript">
        
        


    $(document).ready(function(){
        $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});        
        setDatePickerZh()

        $('#dt_fr').val('{{dt_fr}}');
        $('#dt_to').val('{{dt_to}}');

        var table=$('#tb').DataTable({
            dom: 'Bfrtip',
            autoWidth: false,
            buttons: [{extend:'excelHtml5',text:'导出到Excel'}],
            language:lng,
            data:{{ data|safe }}
        });

        table.columns().every( function () {
            var that = this;
            $('input', this.footer() ).on( 'keyup change clear', function () {
                if ( that.search() !== this.value ) {
                    that.search( this.value ).draw();
                }
            });
        });
        $('#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() ,//额外参数
                        query_all:1
                    },
                    success: function(data) {
                        response(data);
                    }
                });
            },

            select: function (event, ui) {
                $("#agent_id").val(ui.item.value);
                $("#agent_label").val(ui.item.label);
                return false;
             }
        });

        $('#tb').on("click","td a",function(){
            event.preventDefault();
            //var cname=$(this).text();
            $.OpenDlg($(this).attr('href'),"经销商库存明细列表-"+$('#agent_label').val(),1100,700);
        });

        $('.btn-qry').click(function(){
            var agent_id,agent_label,date_fr,date_to;
            agent_id=$('#agent_id').val();
            date_fr=$('#dt_fr').val();
            date_to=$('#dt_to').val();
            var params=[];

            if(date_fr!=''){params.push('date_fr='+date_fr)};
            if(date_to!=''){params.push('date_to='+date_to)};
            if(agent_id!=''){params.push('agent_id='+agent_id)};

            if(params.length==0){
                bootbox.alert("{% trans '请先输入查询条件！'%}");
            }else{
                $.RefreshContent('{{request.path}}?'+params.join('&'));
            }
        });

    });
</script>






<form role="form"  class="form-inline" style="margin-top:0px;">
    <div class='col-sm-4 input-group'>
            <span class="input-group-addon">{% trans "经销商名称"%}</span>
            <input  class='form-control' id="agent_label" placeholder='经销商名称' value="{{agent.name}}"/>
            <input type="hidden" id="agent_id" value="{{agent.id}}"/>
    </div>
    <div class='col-sm-3 input-group'>
        <input class="datepicker form-control col-sm-1" id="dt_fr" />
        <span class="input-group-addon">{% trans " 到 "%}</span>
        <input class="datepicker form-control col-sm-1" id="dt_to" />
    </div>


    <div style="float:right;">
        <span class='input-group-btn'>
            <a type="button" class='btn btn-primary btn-qry'>
                <span class='glyphicon glyphicon-search' style='padding-right:5px;'></span>{% trans '查找' %}
            </a>
        </span>
        <!--
        <button class="btn btn-sm btn-primary btn-qry" type="button"><i class="fa fa-search"></i> {% trans '查找' %}</button>
        -->
    </div>
</form>
<div class="form-group col-sm-2" style="padding-left:0px;">
    <span>{% trans '经销商层级:' %}</span>
    <span style="color:green;">{{agent.level.name}}</span>
</div>
<div  class="form-group col-sm-3">
    <span>{% trans '父级经销商:' %} </span>
    <span  style="color:green;">{{ agent.parent.name }}</span>
</div>

<div class="clearfix"></div>
<div id="inventory-list" class="table-responsive">
    <div class='x_panel'>
    <table id="tb" class="table table-striped table-bordered dt-responsive" width="100%"  style='font-size:90%;'>
        <thead>
            <tr>
                <th rowspan=2>{% trans "产名称" %}</th>
                <th colspan=2>{% trans "入库" %}</th>
                <th colspan=2>{% trans "销售出库" %}</th>
                <th colspan=2>{% trans "销售退库" %}</th>                
            </tr>
            <tr>
                {% for c in clmns %}
                    <th>{{c}}</th>
                {% endfor %}
            </tr>
        </thead>
        <tbody></tbody>
        <tfoot><tr>
            <th><input type='text' placeholder='{% trans "产名称" %}'</th>
            {% for c in clmns %}
                <th><input type='text' placeholder='{{c}}' /></th>
            {% endfor %}            
        </tr></tfoot>
    </table>
    </div>
</div>

