<div class="tab-pane p-20" id="messages8" role="tabpanel">

    <div class="col-lg-12">
        <div class="card-block">
            <form action="<?php echo base_url(); ?>manutencao/adicionarPecasAPreventiva" method="post"
                  name="formAddPecaAPreventiva" id="formAddPecaAPreventiva"
                  class="floating-labels m-t-40">
                <div class="form-body">
                    <input type="hidden" id="peca_id" name="peca_id">
                    <input type="hidden" id="preventiva_id" name="preventiva_id"
                           value="<?php echo $preventivaEditar->ID_PREVENTIVA ?>">
                    <div class="row p-t-20 ">

                        <div class="form-group col-sm-1" style=" color: #00aff0">
                            <i class="fa fa-search"></i>
                        </div>
                        <div class="form-group col-lg-5" style="margin-left: -6%; ">
                            <input type="text" class="form-control" id="pecadesc" name="pecadesc"
                                   required onchange="habilitarBotaoPecaServico();">
                            <span class="bar"></span>
                            <label for="input1">Descrição da Peça</label>
                        </div>

                        <div class="form-group col-lg-2">
                            <input type="text" class="form-control text-center"
                                   id="quantidade"
                                   name="quantidade"
                                   required>
                            <span class="">Quantidade</span>
                        </div>


                        <div class="form-group col-lg-1">
                            <input type="text" class="form-control inputmask text-center"
                                   id="garantia"
                                   name="garantia"
                                   data-inputmask="'alias': 'numeric', 'digits': 0, 'suffix': ' \\Mês\\s', 'rightAlign': false, 'allowMinus': false, 'radixPoint': ','"
                                   required
                                   readonly
                            >
                            <span class="">Garantia</span>
                        </div>

                        <div class="form-group col-lg-2">
                            <input type="text" class="form-control " id="grupo"

                                   name="grupo"
                                   readonly>Grupo</span>
                        </div>


                        <div class="form-group col-lg-1 ">
                            <button type="submit" id="botaoPecasPreventiva" class="btn btn-info"
                                    disabled><i
                                    class="fa fa-save"></i> Adicionar
                            </button>
                        </div>


                    </div>


                </div>

            </form>
        </div>
    </div>
    <hr>

    <div class="col-12">
        <div class="card">
            <div class="card-block">
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>#</th>
                            <th>Descrição</th>
                            <th>Grupo</th>
                            <th>Garantia</th>
                            <th>Vida Útil</th>
                            <th>Valor</th>
                            <th class="text-nowrap">Ações</th>
                        </tr>
                        </thead>
                        <tbody>

                        <?php foreach ($pecasPorPreventiva as $r) {?>
                            <tr>
                                <td><?php echo $r->ID_PECAS_PREVENTIVA ?></td>
                                <td><?php echo $r->DS_DESCRICAO_PECA ?></td>
                                <td><?php echo $r->DS_GRUPO ?></td>
                                <td><?php echo $r->NU_MESES_GARANTIA.' Meses' ?></td>
                                <td><?php echo $r->NU_MESES_VIDA_UTIL .' Meses' ?></td>
                                <td><?php echo $r->VL_PECA ?></td>
                                <td>
                                    <a href="#"
                                       pecaItem="<?php echo $r->ID_PECAS_PREVENTIVA ?>"
                                       preventivaEditar="<?php echo $preventivaEditar->ID_PREVENTIVA ?>"
                                       data-toggle="modal" data-target="#modalExluirItem"
                                    > <i
                                                class="fa fa-trash-o text-danger"></i> </a>
                                </td>
                            </tr>
                        <?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>


<!--    <div class="modal-footer">-->
<!--        <a href="--><?php //echo base_url()?><!--preventiva" class="btn btn-default"><i-->
<!--                class="icon-arrow-left"></i> Voltar</a>-->
<!--    </div>-->
</div>

<script>
    $("#pecadesc").autocomplete({
        source: "<?php echo base_url(); ?>pecas/autoCompletePecas",
        minLength: 3,
        select: function (event, ui) {
            $("#peca_id").val(ui.item.peca_id);
            $("#garantia").val(ui.item.garantia);
            $("#grupo").val(ui.item.grupo);
            $("#valorPeca").val(ui.item.valorPeca);
        }
    });

    function habilitarBotaoPecaServico() {
        if ($("#peca_id").val() && $("#preventiva_id").val()) {
            $('#botaoPecasPreventiva').removeAttr('disabled');
        }
    }

</script>


<script type="text/javascript">

    $(document).on('click', 'a', function (event) {
        if ($(this).attr('pecaItem')) {
            $('#idItemExcluir').val($(this).attr('pecaItem'));
            $('#idItemAoEditar').val($(this).attr('preventivaEditar'));
            $("#excluirItem").attr("action", "<?php echo base_url() ?>manutencao/excluirPecaPreventiva");
        }
    });

</script>

<?php $this->load->view("sistema/modais/exluirItemGerericosModal"); ?>