[list]Bom dia pessoal,
Tenho uma dúvida e gostaria de uma ajuda.
Esta grid é basicamente a montagem de pedido de uma lanchonete.
O preenchimento dela é feito começando pelo produto, busco na base o produto(autocomplete) e vou adicionado acréscimos para aquele produto, depois clico em “Adicionar o produto”. Feito isso minha grid já está pronta, porém preciso inserir um acréscimo em uma segunda instância, ou seja, o produto já está na grid, para adicionar mais um acréscimo eu teria que excluir todo o produto e montar ele novamente com o novo acréscimo. Para não perder tempo refazendo o procedimento normal, inseri um botão de adicionar acréscimos(+), com o propósito de adicionar mais uma linha de acréscimo com um input auto-complete. O problema está ai, quando clico no botão deve aparecer uma linha depois do ultimo acréscimo daquele produto clicado, é o que não acontece, ele insere a linha na ultima linha da grid, desprezando o produto.
Vou colocar aqui a função que preeenche a grid em primeira instãncia e a função que insere uma nova linha de acréscimos.
Se alguém puder ajudar... Grato desde já.
function addProdutoCompleto(id,nome,preco,idcat,qtde){
id = arrayProduto[0];
nome = arrayProduto[1];
preco = arrayProduto[2];
//idproduto = $('#IDGenero').val();
var obs = $("#obsProd").val();
//alert('arrayProduto.length: '+arrayProduto.length);33
if(arrayProduto.length != 0){
arrayProdutoN[arrayProdutoN.length] = new Array(id, nome, preco, arrayProdutoN.length,count, obs);
var indice = arrayProdutoN.length-1;
//Função onde é inserido o produto na grid
var html = "<tr class='even'>";
//html += "<td><a href='javascript:void(0);' onclick=\"deletarProduto($(this), '"+count+"');\" >" +id+"-"+count+ "<img src='buttons/cross.png' border=0 style='margin-left:10px;'/></a></td>";
html += "<td><a href='javascript:void(0);' onclick=\"deletarProduto($(this), '"+count+"');\" >'"+id+"' - '"+count+"'<img src='buttons/cross.png' border=0 style='margin-left:10px;'/></a><a><img onclick=\"adicionaAcrescimo($(this),'"+indice+"');\" src='buttons/adicionar.png' border=0 style='margin-left:10px;'/></a></td>";
// html += "<td><a href='javascript:void(0);' onclick=\"exibeCaixaObs("+(arrayProdutoN.length-1)+",'"+nome+"');\" ><img src='buttons/anotacoes.png' border=0 style='margin-left:10px;'/></a></td>"
html += "<td></td>";
html += "<td><input indice='"+indice+"' type='hidden' name='IDGenero[]' id='IDGenero[]' class='field' value='"+id+"'/><b>"+nome+"</b></td>";
html += "<td><input type='text' name='obsProduto"+count+"' id='obsProduto"+count+"' value='"+obs+"' /></td>";
html += "<td><input type='text' name='Qtdea"+count+"' id='Qtdea"+count+"' onkeypress='alteraBordaQtde(this);' class='field' style='text-align:center;' size='6' value='"+qtde+"' onkeyup='calcularSubTotal();' onblur='calcularSubTotal();' /></td>";
html += "<td style='padding-left:23px;'>R$<input type='text' name='Valor"+count+"' id='Valora"+count+"' class='field' size='6' value='"+parseFloat(preco).toFixed(2)+"' style='background:#DBE5F1; border:0px;' readonly/></td>";
html += "<td style='padding-left:15px;'>R$<input type='text' name='SubTotala"+count+"' id='SubTotala"+count+"' class='field' size='6' value='0' style='background:#DBE5F1; border:0px;' readonly/></td>";
html += "</tr>";
html +="<script>id_acrescimo = "+idcat+";";
html +="$('#tb-ficha tbody td').addClass('separator');";
html +="$('#tb-ficha tbody tr').mouseover(function(){";
html +="$(this).addClass('over');";
html +="}).mouseout(function(){";
html +="$(this).removeClass('over');";
html +="});";
html +="<\/script>";
//Fim
$("#tb-ficha").append(html);
calcularSubTotal(arrayProdutoN.length-1);
subtotal1 = 0;
cont = 0;
//Adiciona acrescimo na grid
for(var i =0; i < arrayAcrescimo.length; i++)
{
arrayAcrescimoN[arrayAcrescimoN.length] = new Array(arrayAcrescimo[i][0], arrayAcrescimo[i][1],arrayAcrescimo[i][2], arrayAcrescimo[i][3], count, cont);
var html = "<tr class='acrescimo acresc"+(id)+"' id='acresc"+count+"'>";
html += "<td></td>";
html += "<td></td>";
html += "<td><input type='hidden' name='IDGenero[]' id='IDGenero[]' class='field' value='"+arrayAcrescimo[i][0]+"'/>      <a href='javascript:void(0);' onclick=\"deletarAcrescimoGrid($(this), '"+count+"','qwerty'); calcularSubTotalb(); \" >" +arrayAcrescimo[i][0]+"-"+count+ "<img src='buttons/cross.png' border=0 style='right:7px; height:9px; width:9px;'/> </a>"+arrayAcrescimo[i][1]+" </td>";
html += "<td></td>";
html += "<td><input type='text' name='Qtdeb"+count+cont+"' id='Qtdeb"+count+cont+"' class='field' style='text-align:center;' size='6' value='"+qtde+"' onkeyup='calcularSubTotalb();' onblur='calcularSubTotalb();' /></td>";
html += "<td style='padding-left:23px;'>R$<input type='text' name='SubTotalb"+count+cont+"' id='SubTotalb"+count+cont+"' class='"+count+"' size='6' value='"+parseFloat(arrayAcrescimo[i][3]).toFixed(2)+"' style='background:#e7f5e2; border:0px;' readonly/></td>";
html += "<td posicaoPai='"+count+"' style='padding-left:23px;'><input type='hidden' name='Valorb"+(arrayAcrescimoN.length-1)+"' id='Valorb"+(arrayAcrescimoN.length-1)+"' class='"+count+"' size='6' value='"+parseFloat(arrayAcrescimo[i][3]).toFixed(2)+"' style='background:#e7f5e2; border:0px;' readonly/></td>";
html += "</tr>";
html +="<script>id_acrescimo = "+idcat+";";
html +="$('#tb-ficha tbody td').addClass('separator');";
html +="$('#tb-ficha tbody tr').mouseover(function(){";
html +="$(this).addClass('over');";
html +="}).mouseout(function(){";
html +="$(this).removeClass('over');";
html +="});";
html +="<\/script>";
$("#tb-ficha").append(html);
cont++;
calcularSubTotalb();
}
count++;
}
else{
alert('Você deve selecionar ao menos um produto para inserir no pedido');
document.getElementById('tf_produto').style.border='2px solid red';
document.getElementById('tf_produto').focus();
}
}
function adicionaAcrescimo(e,idProduto){
var tr = e.parents('tr').eq(0);
var genero = tr.find("input[name*=indice").val();
// $(this).closest('tr').find('IDGenero'){
//
// alert('TR: '+tr.find('IDGenero'));
count = idProduto;
for(var i =0; i < arrayAcrescimo.length; i++)
{
var a = i;
}
cont = a +1;
alert('@@@@@: '+arrayProdutoN.length);
//alert('Total Acrescimos: '+genero);
//alert('AQUI 0 => '+arrayAcrescimo[a][0]+'AQUI 1 => '+arrayAcrescimo[a][1]+'AQUI 2 => '+arrayAcrescimo[a][2]+'AQUI 3 => '+arrayAcrescimo[a][3]);
// id nome
arrayAcrescimoN[arrayAcrescimoN.length] = new Array(arrayAcrescimo[a][0], arrayAcrescimo[a][1],arrayAcrescimo[a][2], arrayAcrescimo[a][3], count, cont);
var html = "<tr class='acrescimo acresc"+(cont)+"' id='acresc"+count+"'>";
html += "<td></td>";
html += "<td></td>";
html += "<td><a href='javascript:void(0);' onclick=\"deletarAcrescimoGrid($(this), '"+count+"','qwerty'); calcularSubTotalb(); \" >      " +arrayAcrescimo[a][0]+"-"+count+ "<img src='buttons/cross.png' border=0 style='right:7px; height:9px; width:9px;'/> </a><input onClick='addAcrescimosProduto();' type='text' name='tf_acrescimo1' id='tf_acrescimo1' class='field' style='margin-left: 0px; width: 430px;' value='' /><a href='javascript:void(0);' onclick=\"deletarAcrescimoGrid($(this), '"+count+"','qwerty'); calcularSubTotalb(); \" > </a></td>";
//html += "<td></td>";
html += "<td><input type='hidden' name='IDGenero[]' id='IDGenero[]' class='field' value=''/></td>";
html += "<td><input type='text' name='Qtdeb1"+count+cont+"' id='Qtdeb1"+count+cont+"' class='field' style='text-align:center;' size='6' value='' onkeyup='calcularSubTotalb();' onblur='calcularSubTotalb();' /></td>";
html += "<td style='padding-left:23px;'>R$<input type='text' name='SubTotalb1"+count+cont+"' id='SubTotalb1"+count+cont+"' class='"+count+"' size='6' value='' style='background:#e7f5e2; border:0px;' readonly/></td>";
html += "<td posicaoPai='"+count+"' style='padding-left:23px;'><input type='hidden' name='Valorb1"+(arrayAcrescimoN.length-1)+"' id='Valorb1"+(arrayAcrescimoN.length-1)+"' class='"+count+"' size='6' value='' style='background:#e7f5e2; border:0px;' readonly/></td>";
html += "</tr>";
html +="<script>";
html +="$('#tb-ficha tbody td').addClass('separator');";
html +="$('#tb-ficha tbody tr').mouseover(function(){";
html +="$(this).addClass('over');";
html +="}).mouseout(function(){";
html +="$(this).removeClass('over');";
html +="});";
html +="<\/script>";
$("#tb-ficha").append(html);
cont++;
calcularSubTotalb();
count++;
}
- Davkidovguada likes this



Postagens
Male
