Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

ionic2 - IONIC V1 AWAIT POPUP

I am opening a popup, and I want to click on "Continuar" (in the function "quantDeProdutoPopup") to display two other popup, but the following code will wait for the pop action. I tried to put an "await" and "async" in the function but it didn't work. Someone knows how to solve, my code is as follows:

This is a project of the company I work for, it is in IONIC 1, I don't know the technology well. I tried to find it on other forums, but I didn't get an answer.

$scope.quantDeProdutoPopup = $ionicPopup.show({
            templateUrl: 'templates/popups/quantidade-de-produto.html',
            cssClass: 'composicao-popup',
            title: 'Informe a quantidade',
            scope: $scope,
            buttons: [{
                text: 'Cancelar',
                type: 'button-energized',
                onTap: function (e) {
                    e.stopPropagation();
                    if (visualizandoNaComanda && !verificarQuantidadeDeAcompanhamentos()) {
                        e.preventDefault();
                        return;
                    }
                }
            }, {
                text: '<b>Confirmar</b>',
                type: 'button-positive',
                onTap: async function (e) {

                    if ($scope.temSabores) {
                        await $scope.openModalComposicao('sabores')
                    }
                    if ($scope.temAdicionais) {
                        await $scope.openModalComposicao('adicionais')
                    }

                    e.stopPropagation();

                    var strRemovidos = [];
                    var strAdicionais = [];
                    var strSabores = [];

                    angular.forEach($scope.produto.composicoes, function (i, k) {

                        if ($scope.produto.removidos && $scope.produto.removidos.indexOf(i.id) >= 0) {
                            strRemovidos.push(i.descricao);
                        } else if ($scope.produto.adicionais && $scope.produto.adicionais.indexOf(i.id) >= 0) {
                            if ($scope.produto.quantidadeAcompanhamentos > 0 && k <= $scope.produto.quantidadeAcompanhamentos) {
                                strAdicionais.push(i.descricao);
                            } else {
                                var valor = $filter("currency")(i.valor, "R$ ", 2);
                                strAdicionais.push(i.descricao + " <span class='to-upper'>(" + valor + ")</span>");
                            }
                        }
                        else if ($scope.produto.sabores && $scope.produto.sabores.indexOf(i.id) >= 0) {
                            var valor = $filter("currency")(i.valor, "R$ ", 2);
                            strSabores.push(i.descricao + " <span class='to-upper'>(" + valor + ")</span>");
                        }
                    });

                    $scope.produto.strRemovidos = strRemovidos.join(", ");
                    $scope.produto.strAdicionais = strAdicionais.join(", ");
                    $scope.produto.strSabores = strSabores.join(", ");

                    if ($scope.quant_do_produto == 0) {
                        e.preventDefault();
                        notify.alert("Opps", "Por favor, informe a quantidade.");
                        return;
                    }

                    if (!verificarQuantidadeDeAcompanhamentos()) {
                        e.preventDefault();
                        return;
                    }

                    $scope.produto.quant = $scope.quant_do_produto;

                    if (!$scope.ehCombo) {
                        if (!visualizandoNaComanda) {
                            ComandaService.addProduto($scope.produto);
                            notify.show("Produto adicionado com sucesso!", 800, "ion-checkmark-circled balanced");
                            $scope.$root.$broadcast("evProdutoAdicionado");

                        } else {
                            $log.debug("produto n eh combo e apenas editado");
                            $log.debug($scope.produto);
                        }
                    }
                    else {
                        ComandaService.calculaVlTotalCombo();
                    }

                    if (usandoSimilarEscolhido) {
                        var combo = ComandaService.getComboSelecionado();
                        $scope.produto.similares = true;
                        combo.composicoes[combo.composicaoSimilarIdx] = $scope.produto;
                    }


                    $scope.$root.$broadcast("produtoFoiEditado");

                    //                    else if($scope.ehCombo){
                    //                        var combo = ComandaService.getComboSelecionado();
                    //                        if(combo.composicaoSimilarIdx)
                    //                            combo.composicoes.
                    //                    }

                    $scope.$destroy();

                }

            }]
        });

        $scope.openModalComposicao = async function (tipo) {

            $scope.filterComposicao = "";
            $scope.mostrarValoresDeAdicionais = $scope.produto.quantidadeAcompanhamentos > 0 ? false : true;
            $scope.composicoesSelecionadas = {};
            $scope.limitesPorSabores = [];

            $scope.validarComposicao = function (key) {
                if ($scope.produto.quantidadeAcompanhamentos > 0) {
                    if (tipo == "sabores") {
                        var limite = 0;
                        angular.forEach($scope.composicoesSelecionadas.sabores[key], function (c) {
                            if (c.checked == true)
                                limite++;
                        });

                        if (limite >= $scope.produto.quantidadeAcompanhamentos) {
                            notify.alert("Aten??o!", "Quantidade limite de sabores atingido.");
                            $scope.limitesPorSabores[key] = true;
                        }
                        else
                            $scope.limitesPorSabores[key] = false;
                    }

                } else if (key != "Geral") {
                    var limite = 0;
                    angular.forEach($scope.composicoesSelecionadas.sabores[key], function (c) {
                        if (c.checked == true)
                            limite++;

                        if (c.quantidadeSabores == limite)
                            $scope.limitesPorSabores[key] = true;
                        else
                            $scope.limitesPorSabores[key] = false;

                    });
                }
            };

            $scope.tipoComposicao = tipo;
            var composicoesTemp = angular.copy($scope.produto.composicoes);

            if (tipo == "ingredientes") {
                var title = "INGREDIENTES";
                $scope.composicoesSelecionadas[tipo] = [];
                var olistaTemp = [];
                angular.forEach(composicoesTemp, function (v, i) {
                    if (v.tipo == 1) {

                        if ($scope.produto.removidos) {

                            angular.forEach($scope.produto.removidos, function (pRem) {
                                if (pRem == v.id)
                                    v.checked = true;
                            });
                        }

                        //$scope.composicoesSelecionadas[tipo].push(v);
                        olistaTemp.push(v);
                    }
                });
                $scope.composicoesSelecionadas[tipo] = olistaTemp.groupBy("codigoGrupo");
            } else if (tipo == "adicionais") {
                var title = "ADICIONAIS";
                $scope.composicoesSelecionadas[tipo] = [];
                var olistaTemp = [];
                angular.forEach(composicoesTemp, function (v, i) {
                    if (v.tipo == 2) {

                        if ($scope.produto.adicionais) {

                            angular.forEach($scope.produto.adicionais, function (pRem) {
                                if (pRem == v.id)
                                    v.checked = true;
                            });
                        }

                        //$scope.composicoesSelecionadas[tipo].push(v);
                        olistaTemp.push(v);
                    }
                });
                $scope.composicoesSelecionadas[tipo] = olistaTemp.groupBy("codigoGrupo");
            }
            else if (tipo == "sabores") {
                var title = "SABORES";
                $scope.composicoesSelecionadas[tipo] = [];
                var olistaTemp = [];
                angular.forEach(composicoesTemp, function (v, i) {
                    if (v.tipo == 4) {
                        if ($scope.produto.sabores) {
                            angular.forEach($scope.produto.sabores, function (pRem) {
                                if (pRem == v.id)
                                    v.checked = true;
                            });
                        }
                        //$scope.composicoesSelecionadas[tipo].push(v);
                        olistaTemp.push(v);
                    }
                });

                $scope.composicoesSelecionadas[tipo] = olistaTemp.groupBy("codigoGrupo");

                angular.forEach($scope.composicoesSelecionadas[tipo], function (produtos, key) {
                    $scope.validarComposicao(key);
                });
            }

            $scope.showPopupList = false;
            var popupDynamicH = "auto";
            $scope.popupLoaded = function () {

                $timeout(function () {

                    $scope.showPopupList = true;
                    //                    $scope.$apply();

                }, 100);

            };

            setTimeout(function () {
                $scope.popupComposicoesOpened = true;
            }, 300);

            var composicaoPopup = $ionicPopup.show({
                templateUrl: 'templates/popups/composicoes.html',
                cssClass: 'composicao-popup',
                title: title,
                scope: $scope,
                buttons: [{
                    text: 'Cancelar',
                    type: 'button-energized',
                    onTap: function (e) {
                        e.stopPropagation();
                        $scope.composicoesSelecionadas = {};
                        setTimeout(function () {
                            $scope.popupComposicoesOpened = false;
                            $scope.$apply();
                        }, 800);
                    }
                }, {
                    text: '<b>Confirmar</b>',
                    type: 'button-positive',
                    onTap: async function (e) {

                        e.stopPropagation();


                        if ($scope.tipoComposicao == "ingredientes") {

                            $scope.produto.removidos = [];

                            angular.forEach($scope.composicoesSelecionadas[$scope.tipoComposicao], function (olista, i) {
                                angular.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...