{% load i18n %}


<style>
    #infor span.g{
        color:green;
        display:inline-block;        
        min-width:20px;
        margin-right:10px;
    }
    #tb{
     'margin-top:20px;
    }
    #infor div{
        margin-top:10px;
    }

</style>


<script type="text/javascript">
    $(document).ready(function(){

        var company_id={{request.user.ancestor_id}};        
        //先只限定酒鬼酒
        company_id='1';


        /*

        $('.btn-add').click(function(){
            var data={
                tb_lbl: $('#tb_lbl').val(),
                cap_label: $('#cap_label').val(),
                cap_code: $('#cap_code').val(),
                bottle: $('#lbl_bottle').val(),
                product_id: $('#product_id').val(),
                store_id: $('#store_id').val(),
                pk_id: $('#label_pk_id').val(),
                pk_code: $('#label_pk_code').val(),
                product_name: $('#product').text(),
                line: $('#ln').text(),
                bottle_cnt: $('#bottle_cnt').text(),
                batch_no: $('#batch_no').text(),
                qc: $('#qc').text(),
            };           

            $.ajax({
                type:'POST',
                data:JSON.stringify(data),
                url:'/mes/bottlecap/makeup/'+company_id+'/binding/',                
                dataType:'json',
                success: function(d) {
                    if(data.e){
                        toastr.error(
                            d.e,
                            "操作错误：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );                        
                    }else{

                        console.log(d);

                    
                    }
                }
            });           
        });
        */
        $(".btn-delete").hide();
        $('.btn-delete').click(function(){
            //相关span 置空
            var what=$('#what').val();
            var code=$('#code').val();
            if (what!='' && code!=''){
                $.ajax({
                    type:'GET',
                    url:'/mes/bottlecap/makeup/'+company_id+'/redis_delete/?what='+what+'&code='+code,
                    dataType:'json',
                    success: function(d) {
                    if(d.e){
                        toastr.error(
                            d.e,
                            "操作错误：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    }else{
                        toastr.success(
                            "数据已删除",
                            "操作成功：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    }
                }
            });
        }
            });
        
        
        $('.btn-qry').click(function(){           
            //相关span 置空
            $('#infor span.g').text('');

            var what=$('#what').val();
            var code=$('#code').val();
            if (what!='' && code!=''){            
                $.ajax({
                    type:'GET',                           
                    url:'/mes/bottlecap/makeup/'+company_id+'/redis_query/?what='+what+'&code='+code,                
                    dataType:'json',
                    success: function(d) {  
                        $(".btn-delete").show();
                        if(d.e!=''){
                            toastr.error(
                                d.e,
                                "操作错误：",
                                {timeOut: 800, positionClass: "toast-center-center"}
                            );                           
                        }else{
                            d=d.data;
                            $('#bottle').text(d.bottle);
                            $('#outter').text(d.code);
                            $('#inner').text(d.label);
                            $('#product').text(d.product);
                            $('#tm').text(d.tm);
                            $('#ln').text(d.line);
                            $('#batch_no').text(d.batch_no);   
                        };                        
                        return false;
                    }      
                });
            }else{
                toastr.error(
                    "码值和码类型不能为空！",
                    "操作错误：",
                    {timeOut: 800, positionClass: "toast-center-center"}
                );       
            
            }
        });

    });
</script>


<ol class="breadcrumb">
        <li>{% trans "瓶盖码绑定" %}</li>
        <li>{% trans "Redis数据查询" %}</li>     
</ol>
<form role="form"  class="form-inline">

    
    <div class="col-sm-1 input-group">
        <select class='form-control' id='what'>
            <option value='bottle' selected="selected">瓶标</option>
            <option value='cap'>盖码</option>
        </select>
    </div>  
    <div class="col-sm-4 input-group">        
        <input class="form-control" id="code" placeholder="请输入要查询的号码"/>
    </div>

    <div class="col-sm-2 input-group pull-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>       
    </div>  
    <div class="col-sm-2 input-group pull-right">
        <span class='input-group-btn'>
            <a type="button" class='btn btn-danger btn-delete'>
                <span class='glyphicon' ></span>{% trans '删除' %}
            </a>
        </span>
    </div>

</form>

<div class="x_panel">      
<div id='infor'>        
    <div><span>瓶标:</span><span class='g' id='bottle'>未知</span></div>
    <div><span>盖内码:</span><span class='g' id='inner'>未知</span></div>
    <div><span>盖外码:</span><span class='g' id='outter'>未知</span></div>            
    <div><span>产品名称:</span><span class='g' id='product'>未知</span></div>           
    <div><span>产线:</span><span class='g' id='ln'>未知</span></div>
    <div><span>生产批次:</span><span class='g' id='batch_no'>未知</span></div>
    <div><span>绑定时间:</span><span class='g' id='tm'>未知</span></div>
</div>        
</div>

