{% load i18n %}

<style>
    #tb-dlg thead tr th{
        valign:middle;
        text-align:center;
        vertical-align:middle; 
    }
    
</style>




<script type="text/javascript">
    $(document).ready(function(){  
       
       
        var table=$('#tb-dlg').DataTable({
            //"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
            //"bLengthChange":true,
            dom: 'Bfrtip',
            autoWidth: false,
            buttons: [{extend:'excelHtml5',text:'导出到Excel'}],           
            language:lng,           
            destroy:true,
            data:{{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();
                }
            });
        });         

        $('#sel-status').on('change',function(){
            $('.btn-save').removeClass('disabled');
            if($(this).val()=='{{order.status.id}}'){
                $('.btn-save').addClass('disabled');
            }else{
                $('.btn-save').removeClass('disabled');
            }
        });
        

        $('#sel-status').val('{{order.status.id}}');
        $('.btn-save').click(function(){            
             $.ajax({
                type:'POST',
                data: {'status_id':$('#sel-status').val()},
                url:'/mes/edit/order_status/{{order.id}}/',
                success:function(data){   
                    $("#bg-modal").modal('hide');
                    $.RefreshContent($('#url_list_order').val());
                }                       
            });        
        });
    });
</script>
<div style='font-size:15px;'>
    <div>
        <span class='lbl_tt'>订单编号:</span>
        <span style='min-width:150px;display:inline-block;color:green;'>{{order.code}}</span>
        <span class='lbl_tt'>客户名称:</span>
        <span style='min-width:150px;display:inline-block;color:green;'>{{order.agent.name}}</span>    
    </div>
    <div>
        <span class='lbl_tt'>交货日期:</span>
        <span  style='min-width:150px;display:inline-block;color:green;'>{{order.dt_delivery}}</span>
        <span class='lbl_tt'>当前状态:</span>
        <span style='min-width:150px;display:inline-block;color:green;'>
            <select id="sel-status">
                {% for s in data.status %}
                    <option value='{{s.0}}'>{{s.1}}</option>         
                {% endfor %}
            </select>
            <a class='btn btn-sm btn-primary btn-save disabled' >保存</a>
        </span>    
    </div>
</div>

<div class="clearfix"></div>
<div id="inventory-list" class="table-responsive">
    <div class='x_panel'>    
    <table id="tb-dlg" class="table table-striped table-bordered dt-responsive" width="100%" >
        {% if request.user.company.cfg_company.mes_inbound_qc_check_needed %}
            <thead>
            <tr>
                <th colspan=3>物料</th>
                <th rowspan=2>当前订单用量</th>
                <th colspan=2>库存量</th>
                <th colspan=2>未完成订单</th>
                <th rowspan=2>实际可用量</th>
            </tr>
            <tr>
                <th>类别</th>
                <th>名称</th>
                <th>单位</th>
                <th>现有库存</th>
                <th>待质检</th>
                <th>用量</th>
                <th>已领用</th>
            </tr>                             
            </thead>
            <tbody></tbody>
            <tfoot>
            {% for c in data.clmns %}
                <th><input type="text" placeholder="{{c}}"></th>            
            {% endfor %}   
            </tfoot>
        {% else %}
            <thead>
            <tr>
                <th colspan=3>物料</th>
                <th rowspan=2>订单用量</th>
                <th rowspan=2>现库存量</th>
                <th colspan=2>其它未完成订单</th>
                <th rowspan=2>实际可用量</th>
            </tr>
            <tr>
                <th>类别</th>
                <th>名称</th>
                <th>单位</th>
                <th>用量</th>
                <th>已领用</th>
            </tr>                             
            </thead>
            <tbody></tbody>
            <tfoot>
            {% for c in data.clmns %}
                <th><input type="text" placeholder="{{c}}"></th>            
            {% endfor %}   
            </tfoot>
        {% endif %}
    </table>   
    </div>
</div>
