当我推送其他页面时仍然运行默认页面功能

时间:2017-12-10 17:43:42

标签: angularjs firebase ionic-framework firebase-realtime-database

我有一个离子项目,有2个标签菜单。

首先是谷歌地图和第二个(abouts.ts)我正在使用的逻辑过程。

您可以轻松地考虑停车付款应用。

单击按钮IntoParking()时,运行并保存db所需的参数。

该用户在公园后,有一个点击OutParking()功能运行并按PaymentSuccessPage的按钮。

直到这里一切顺利。在PaymentSuccessPage,有评级星级评级服务。当我点击其中一个星星时,我不知道我的IntoParking()和OutParking()函数怎么可能运行并且第二次保存相同的东西......

About.ts。

intoParkingWithDefaultCar() {

let i;
const userId = this.authCtrl.showUser().uid;
let isSubscribe: boolean = false;
let barcodeData = "anlikotopark-park1";
this.firebaseProvider.getOtoparks().subscribe(data => {
  for (i = 0; i < data.length; i++) {
    if (barcodeData == (data[i]['details']['parkqr'])) {
      this.selectedOtopark = data[i];

      if (this.selectedOtopark !== null) {

        for (i = 0; i < this.selectedOtopark.length; i++) {
          if (userId == this.selectedOtopark['subUsers'][i]['userId']) {
            isSubscribe = true;
          }
        }

        if (isSubscribe == true) {

          this.userActivityLoginTime = moment().format('DD/MM/YYYY HH:mm:ss');
          this.userInActivityOnOtopark(
            this.userActivityLoginTime,
            this.selectedOtopark['details']['name'],
            this.userDefaultCarType,
            this.selectedOtopark['details']['parkqr'],
          );

          let alert = this.alertCtrl.create({
            title: 'Teşekkürler!',
            subTitle: 'Abone olduğunuz otoparka başarıyla giriş yaptınız.',
            buttons: [
              {
                text: 'Tamam',
                handler: data => {
                  let loader = this.loadingCtrl.create({
                    content: "Yükleniyor...",
                    duration: 1500
                  });
                  loader.present();
                }
              }
            ]
          });
          alert.present();

        } else {
          this.userActivityLoginTime = moment().format('DD/MM/YYYY HH:mm:ss');
          this.userInActivityOnOtopark(
            this.userActivityLoginTime,
            this.selectedOtopark['details']['name'],
            this.userDefaultCarType,
            this.selectedOtopark['details']['parkqr'],
          );

          let alert = this.alertCtrl.create({
            title: 'Hoşgeldiniz!',
            subTitle: 'Otoparka başarılı bir şekilde giriş yaptınız.',
            buttons: [
              {
                text: 'Tamam',
                handler: data => {
                  let loader = this.loadingCtrl.create({
                    content: "Yükleniyor...",
                    duration: 1500
                  });
                  loader.present();
                }
              }
            ]
          });
          alert.present();
        }
      } else {
        const toast = this.toastCtrl.create({
          message: "Otopark bulunamadı.",
          duration: 1500,
          position: 'bottom'
        });
        toast.present();
      }
    }
  }
});
}

outParking() {
const confirm = this.alertCtrl.create({
  title: 'Çıkış yap',
  message: 'Ödeme yapıp otoparktan ayrılmak istiyor musunuz?',
  buttons: [
    {
      text: 'Hayır',
      handler: () => {
      }
    },
    {
      text: 'Evet',
      handler: () => {
        let i;
        let tempData: any[] = [];
        const userId = this.authCtrl.showUser().uid;
        let isSubscribe: boolean = false;
        let barcodeData = "anlikotopark-park1";

        this.firebaseProvider.getOtoparks().subscribe(data => {
          for (i = 0; i < data.length; i++) {
            if (barcodeData == (data[i]['details']['parkqr'])) {
              this.selectedOtopark = data[i];
            }
          }

          for (let prop in this.selectedOtopark['subUsers']) {
            if (this.selectedOtopark['subUsers'].hasOwnProperty(prop)) {
              tempData.push(this.selectedOtopark['subUsers'][prop]);
            }
          }

          if (tempData.length > 0) {
            for (let i = 0; i < tempData.length; i++) {
              if (tempData[i]['userId'] == userId) {
                if (tempData[i]['status'] == 'active') {
                  isSubscribe = true;
                }
              }
            }
          }

          if (this.selectedOtopark !== undefined) {

            if (isSubscribe == true) {
              this.userActivityLogoutTime = moment().format('DD-MM-YYYY HH:mm:ss');
              this.storageCtrl.set('true', isSubscribe);
              this.userOutActivityOnOtopark(this.userActivityLogoutTime);
              this.navCtrl.setRoot(PaymentSuccessPage);
            } else {

              this.userActivityLogoutTime = moment().format('DD-MM-YYYY HH:mm:ss'); // user çıkış anı

              this.rangeOfUserLoginandLogoutDates = moment(this.userActivityLogoutTime, "DD-MM-YYYY HH:mm:ss")
                .diff(moment(this.userActivityLoginTime, "DD-MM-YYYY HH:mm:ss"));  //user'ın giriş çıkış aralığı ms

              this.rangeAsHours = Math.floor(moment.duration(this.rangeOfUserLoginandLogoutDates).asHours()); //user'ın giriş çıkış aralığı saat

              this.userPayment = this.selectedOtopark['prices']['daily'][`${this.userActivityCarType}`][`${this.rangeAsHours}`];

              if (this.userPayment > this.userProfileWallet) {
                let alert = this.alertCtrl.create({
                  title: 'Yetersiz bakiye!',
                  subTitle: 'Bakiyeniz yetersiz, lütfen bakiye yükleyip tekrar deneyiniz!',
                  buttons: ['Tamam']
                });
                alert.present();
              }
              else {


                this.userProfileWallet = this.userProfileWallet - this.userPayment;


                this.cashUpdate(this.userProfileWallet);
                this.userOutActivityOnOtopark(this.userActivityLogoutTime);
                this.setPaymentToArchive(this.userPayment, this.selectedOtopark['details']['name'],
                  this.userActivityLoginTime, this.userActivityLogoutTime, this.userActivityCarType, this.selectedOtopark['details']['sehir']);


                // Pushing PaymentSuccessPage

                this.navCtrl.push(PaymentSuccessPage, {
                  userPayment: this.userPayment,
                  selectedOtopark: this.selectedOtopark,
                  isSubscribe: isSubscribe
                });
              }

            }
          } else {
            const toast = this.toastCtrl.create({
              message: 'Otopark bulunamadı.',
              duration: 3000,
              position: 'top'
            });
            toast.present();
          }
        });
      }
    }

  ]
});
confirm.present();
}

PaymentSuccessPage.html

<ion-content padding>
<div text-center>
<div>
  <div text-center>
    <img class="imageTick" src="assets/images/success.png"/>
  </div>
</div>

<div text-center class="paymentsInfo" [hidden]="isSubscribe == true">
  <h2>
    <small>Ödenen Ücret:</small>
    {{userPayment | number}} ₺
  </h2>
  <p class="odemeSayfasiP">Ödemeniz başarıyla tamamlandı.</p>
</div>

<div text-center class="paymentsInfo" [hidden]="isSubscribe == false">
  <p class="odemeSayfasiP">Abonman çıkış başarıyla tamamlandı.</p>
</div>

<div [hidden]="htmlStatusValue == false">
  <ion-grid class="gridPoll">
    <ion-row>
      <ion-col col-2>
        <ion-icon name="alert" color="color1" class="largerIcon"></ion-icon>
      </ion-col>
      <ion-col col-10>
        <p class="odemeSayfasiP">
          Aldığınız hizmetin kalitesini oylamak ister misiniz?
        </p>
      </ion-col>
    </ion-row>
  </ion-grid>

  <rating [(ngModel)]="rate" (ngModelChange)="getRate($event)"
          readOnly="false" max="5" emptyStarIconName="star-outline" halfStarIconName="star-half" starIconName="star"
          nullable="true"></rating>
</div>

<div text-center="" [hidden]="htmlStatusValue == true">
  <h4 class="thanks-vote-text">Oylamanız için teşekkürler!</h4>
  <p>Değerlendirmenizi daha sonra profiliniz üzerinden yapabilirsiniz.</p>
</div>

<div class="container">
  <button color="color1" block="" ion-button (click)="rotateAboutPage()">Anasayfa</button>
  <button color="color1" block="" ion-button (click)="rotatePaymentsPage()">Ödemelerim</button>
</div>

PaymentSuccessPage.ts

constructor(public navCtrl: NavController,
          public alertCtrl: AlertController,
          private storageCtrl: Storage,
          private firebaseProvide: FirebaseProvider,
          private afDatabase: AngularFireDatabase,
          private navParams: NavParams) {


this.isSubscribe = this.navParams.get('isSubscribe');
this.selectedOtopark = this.navParams.get('selectedOtopark');
this.userPayment = this.navParams.get('userPayment')

console.log(this.isSubscribe, this.selectedOtopark, this.userPayment);
}

ionViewWillLoad() {
}

getRate($event) {
let sum: any;
let count: any;
let average: any;

sum = this.selectedOtopark['rates']['sum'];
sum = sum + $event;
count = this.selectedOtopark['rates']['count'];
count++;
average = sum / count;

  this.afDatabase.database.ref(`parks/${this.selectedOtopark['details']['parkqr']}/rates`).update({
    sum: sum,
    count: count,
    average: average
  });
 }

图片:https://imgur.com/a/DwfSn

如果你想帮助我发送源代码。

感谢。

1 个答案:

答案 0 :(得分:0)

我认为这可能是因为Firebase会调用每次数据更改时订阅的功能。您正在订阅的intoParkingoutParking内部功能可以从Firebase接收数据。之后,在getRates函数中更新firebase中的对象,这会导致调用先前的函数。

你应该取消订阅以避免它。