File "selectDinamico.js"

Full Path: C:/wamp64/www/INVENTAPP/controller/selectDinamico.js
File size: 3.73 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.codID}"  >${linea.codLitem}--${linea.nomLitem}</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 selected value="${item.codItem}" >${item.codLinea}--${item.nomLinea}</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", false);

            $("#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);
        }

        const codigoItem = $listItem.value

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




})