File "selectDinamicoOV-20260419173157.js"

Full Path: C:/wamp64/www/INVENTALMACEN/controller/selectDinamicoOV-20260419173157.js
File size: 3.69 KB
MIME-type: text/plain
Charset: utf-8


$(document).ready(function () {
    let $listLinea = document.querySelector('#listLinea')
    let $listItem = document.querySelector('#listItem')
    let $pesoProm = document.querySelector('#inpPesoProm')


    function cargarLinea() {
        $.ajax({
            type: "GET",
            url: "../models/selectDinamico.php",

            success: function (response) {
                

                const lineas = JSON.parse(response)

                let template = '<option value="" selected disabled hidden>--Seleccione--</option>'

                lineas.forEach(linea => {
                    template += `<option value="${linea.codLinea}">${linea.codLinea}--${linea.nomLinea}</option>`
                });

                $listLinea.innerHTML = template
                $('#listLinea').select2({
                    theme: "bootstrap-5",
                    width: '100%'
                })

            }
        });
    }
    cargarLinea()



    function cargarItems(sendCodigo) {
        $.ajax({
            type: "POST",
            url: "../models/selectDinamico.php",
            data: sendCodigo,

            success: function (response) {
                const items = JSON.parse(response)

                let template = '<option class="form-control" selected disabled>--Seleccione--</option>'

                items.forEach(item => {
                    template += `<option value="${item.codItem}">${item.codItem}--${item.nomItem}</option>`;
                    
                });

                $listItem.innerHTML = template
               

                $('#listItem').select2({
                    theme: "bootstrap-5",
                    width: '100%'
                })


            }
        });
    }

    $('#listLinea').on('change', function () {

        const codLinea = $listLinea.value

        const sendCodigo = {
            'codigoLinea': codLinea
        }

        cargarItems(sendCodigo)
        $pesoProm.value = '';
        if(codLinea == '8214'){
            $("#opGranel").prop("disabled", false);

        }else{
            $("#opGranel").prop("disabled", true);
        
            $("#tpRegistro").val("0").trigger("change");

        }
    })

    function cargarPesoProm(sendItem) {
        $.ajax({
            type: "POST",
            url: "../models/selectDinamico.php",
            data: sendItem,

            success: function (response) {
                
                 const pesoProm = JSON.parse(response)

                let template = 0

                pesoProm.forEach(pPROM => {
                    template = `${pPROM.pesoProm}`;
                    
                });

                $pesoProm.value = template
               
            }
        });
        
    } 
     $('#listItem').on('change',function () {
        const codigoItem = $listItem.value

        const sendItem = {
            'codigoItem' : codigoItem
        }
        cargarPesoProm(sendItem)

        
    }) 


    $('#tpRegistro').change(function () {
        if ($(this).val() === "1") {
            $("#inpPeso").prop("disabled", false);
            $("#inpLote").prop("disabled", false);
            $("#inpUnidad").prop("disabled", true);
        } else if ($(this).val() === "2") {
            $("#inpUnidad").prop("disabled", false);
            $("#inpLote").prop("disabled", false);
            $("#inpPeso").prop("disabled", true);
        } else if ($(this).val() === "3")  {
            $("#inpUnidad").prop("disabled", false);
            $("#inpLote").prop("disabled", false);
            $("#inpPeso").prop("disabled", false);
        }
    })

    


})