$(function(){
    reset_tr_num();
});
function reset_tr_num(){
    $('table').each(function() {
        var i = 1;
        $(this).find('td.o_n').each(function () {
            $(this).html(i);
            i++;
        });
    });
}
function searchgoodslist(){
    var goods_sn=$('#goods_sn').val().trim();//商品输入框
    if (goods_sn==''){
        $.showErr('商品不能为空',0,'hc');
        return false;
    }
    var query = new Object();
    query.goods_sn = goods_sn;  //商品关键词
    $.ajax({
        url: APP+"InvoicingOrder/search_goods",
        data:query,
        type:"post",
        dataType:"json",
        success: function(data){
            var html = "<option value='0'>==请选择商品==</option>";
            if(data.status == 1){
                for(var i=0;i<data.list.length;i++){
                    html += "<option value='"+data.list[i]['id']+"'>"+data.list[i]['goods_name']+"("+data.list[i]['goods_sn']+")</option>";
                }
            }else{
                $.showErr(data.msg,0,'hc');
            }
            $("#goods_list").html(html);
            return false;
        }
    });
}
/*盘点报损操作开始*/
function stock_confirm_order(id,type,status){
    var query = new Object();
    query.id = id; //订单id
    query.type = type;  //订单类型
    query.status = status; //审核状态
    query.audit_remarks = $('#remarks').val();
    $.ajax({
        url: APP+"InvoicingOrder/stock_confirm_order",
        data:query,
        type:"post",
        dataType:"json",
        success: function(data){
            if(data.status==1){
                $.showSuccess(data.msg,1,'hc',function(){
                    if(type==1 || type==2) {
                        window.location.href = APP + "InvoicingOrder/bad_list.html";
                    }else{
                        window.location.href = APP + "InvoicingOrder/stocktaking_list.html";
                    }
                },function(){
                    if(type==1 || type==2) {
                        window.location.href = APP + "InvoicingOrder/bad_list.html";
                    }else{
                        window.location.href = APP + "InvoicingOrder/stocktaking_list.html";
                    }
                });
            }else{
                $.showErr(data.msg,1,'hc');
            }
        }
    });
}
function add_bad(){
    window.location.href=APP + "InvoicingOrder/bad_add.html";
}
function add_pan(){
    window.location.href=APP + "InvoicingOrder/pan_add.html";
}
/*盘点报损操作结束*/