必须单击按钮两次才能调用该函数

时间:2021-04-01 17:43:37

标签: javascript vue.js button

点击按钮会调用joinQueue(),joinQueue()会调用getArrivalTime()。但是,该按钮需要单击两次才能调用该函数。我如何更改以在单击一次按钮时调用该函数。

<form @submit.prevent="joinQueue()">

joinQueue: function () {
            var paxGroup = this.getPaxGroup(this.numAdult, this.numChildren);
            var restName = this.restaurantSelected.restaurantName;
            var mallName = this.mallSelected;
            this.getArrivalTime(paxGroup, restName, mallName);
        },

getArrivalTime(paxGroup, restName, mallName) {
            let counter = 0;
            database
            .collection("bookings")
            .get()
            .then((snapshot) => {
                snapshot.docs.forEach((doc) => {
                    var booking = doc.data();
                    if (((booking.paxGroup === paxGroup) && (booking.restaurantName === restName)) 
                    && ((booking.mallName === mallName) && (booking.queueStatus === "waiting"))) {
                        counter += 1;
                    }
                })
            }).then(() => {
                var bookTime = this.getCurrentTime();
                var parsed = (Date.parse(bookTime) + (counter * 2700000));
                var arrTime = (new Date(parsed)).toString();
                database.collection("bookings").add({
                    customerID: this.customerID,
                    mallName: mallName,
                    restaurantName: restName,
                    restaurantMall: restName + " @ " + mallName,
                    numAdult: this.numAdult,
                    numChildren: this.numChildren,
                    paxGroup: paxGroup,
                    queueNumber: this.getQueueNumber(this.numAdult, this.numChildren),
                    babyChair: this.babyChair,
                    wheelChair: this.wheelChair,
                    additionalMessage: this.additionalMessage,
                    queueStatus: "waiting",
                    bookedTiming: bookTime,
                    restaurantId: this.restaurantSelected.id,
                    arrivalTime: arrTime,
                });
                alert(
                    "Successfully joined queue. Please arrive at " + restName + " @ "
                    + mallName + " by " + arrTime + "."
                );
                this.$router.push("/myprofile");
            });
        },

0 个答案:

没有答案