
{% load i18n %}
    <ol class="breadcrumb">
        <li>{% trans "存货管理" %}</li>
        <li>{% trans "发货TXT上传" %}</li>
    </ol>
<script type="text/javascript">
    $(document).ready(function(){

        $('#obj_form form .form-group').css('min-height','35px');

    $('input[name="info"]').change(function(){
        info=$('input[name="info"]:checked').attr('value');
        if(info=='custom'){
            $('#fahuo_info').show(400);
        }else{
            $('#fahuo_info').hide(400);
        }
    });
    $('#xFile').change(function(){
        $('#info table').html('');
        $('#info .info').html('');
        $('#errinfo_null_rec').html('');
        $('#errinfo_delivered_rec').html('');
        $('#errinfo_different_rec').html('');
        var xhr= new XMLHttpRequest();
        var file = document.getElementById('xFile').files;
        var formDat;
        var cnt=0;
        formData = new FormData();
        for(i=0;i<file.length;i++){
            var fn=file[i].name.substr(0,2).toUpperCase();
            formData.append("files", file[i]);
            cnt=cnt+1;
        }
        if(cnt==0){
            //bootbox.alert("{% trans '没有可上传的文件!' %}", function() {});
            toastr.error(
                "{% trans '没有可上传的文件!' %}",
                "操作错误：",
                {timeOut: 800, positionClass: "toast-center-center"}
            );
            return;
        };
        formData.append("voucher_id",$("#vtype_id").val());

        $('#msg').remove();
        $('.btn-upload').addClass('disabled');
        $('#ajax_loading2').show();
        var si='';
        xhr.open('POST','/inventory/upload/inv/txt/');
        xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
        xhr.send(formData);
        xhr.onreadystatechange=(function(_xhr) {
            return function() {
                if (_xhr.readyState == 4){
                    if(_xhr.status == 200) {
                        $('#ajax_loading2').hide();
                        $('.btn-upload').removeClass('disabled');
                        var d = eval('('+_xhr.responseText+')');
                        if(d.e!=''){
                            //bootbox.alert(d.e, function() {});
                            toastr.error(
                                d.e,
                                "上传失败：",
                                {timeOut: 800, positionClass: "toast-center-center"}
                            );
                            return;
                        };

                        toastr.success(
                            d.ok,
                            {timeOut: 1600, positionClass: "toast-center-center"}
                        );
                    }else{
                        $('.btn-upload').removeClass('disabled');
                        $('#ajax_loading2').hide();
                        //bootbox.alert("{% trans '通讯错误!' %}", function() {});
                        toastr.error(
                            "通讯错误!",
                            "上传失败：",
                            {timeOut: 800, positionClass: "toast-center-center"}
                        );
                    }
                }
            }
        })(xhr);
        xhr.timeout = 300000;
        xhr.ontimeout = function(event){            　　
            $('#ajax_loading2').hide();
            //bootbox.alert("{% trans '请求超时！' %}", function() {});
            toastr.error(
                    "请求超时",
                    "操作失败：",
                    {timeOut: 800, positionClass: "toast-center-center"}
            );

        }
    });

});
</script>


<div id="obj_form"  class=''>
    <form>

    <div class="form-group ">
        <div class="col-sm-1" style="height: 34px;line-height: 32px;font-weight: 600;">{% trans '单据类型:' %} </div>
        <div class="col-sm-5">
            <select id="vtype_id" class='form-control'>
                <option value=2 seleted="selected">销售出库</option>

{#                <option value=4>销售退库</option>#}
{#                <option value=3>成品转库</option>#}
{#                <option value=1>成品入库</option>#}
            </select>
        </div>
    </div>


    <div class="form-group">
{#        <label class="col-sm-1 control-label">{% trans "标签所在列:" %}</label>#}
{#        <div class="col-sm-1"><input id="column" value="4"  class="form-control"/></div>#}
        <div class="col-sm-10">
            <label class="btn btn-primary btn-upload" for="xFile">{% trans "上传文件" %}</label>
        </div>
    </div>
    <input type="file" id="xFile" accept="text/plain"  multiple="multiple" style="position:absolute;clip:rect(0 0 0 0);">

    </form>

</div>

