Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component } from '@angular/core';
  2. import { IonicPage, NavController, NavParams, ViewController, ModalController } from 'ionic-angular';
  3. import { Common } from '../../providers/common';
  4. import { AuthService } from '../../providers/auth-service';
  5. import moment from 'moment';
  6.  
  7. @IonicPage()
  8. @Component({
  9.   selector: 'page-schedule-tab-car-modal',
  10.   templateUrl: 'schedule-tab-car-modal.html',
  11. })
  12. export class ScheduleTabCarModalPage {
  13.  
  14.   appointments: any = []
  15.   response: any;
  16.   dbData: any;
  17.   minDate: any;
  18.     maxDate: any;
  19.  
  20.   constructor(
  21.     public navCtrl: NavController,
  22.     public navParams: NavParams,
  23.     public view: ViewController,
  24.     public modalCtrl: ModalController,
  25.     public authService: AuthService,
  26.     public common: Common
  27.   ) { }
  28.  
  29.   ionViewDidLoad() {
  30.     this.add()
  31.   }
  32.  
  33.   ngOnInit() {
  34.     var now = new Date();
  35.         now.setHours(9, 0, 0, 0);
  36.         this.minDate = moment(now).add(1, 'days').toISOString(true);
  37.         this.maxDate = moment(now).add(1, 'years').toISOString();
  38.   }
  39.  
  40.   add() {
  41.     this.appointments.push({
  42.       'user_id': localStorage.getItem("user_id"),
  43.       'address': '',
  44.       'myaddress': true,
  45.       'date': '',
  46.       'price_id': '',
  47.       'price': '',
  48.       'price2': '',
  49.       'address2': localStorage.getItem("user_address")
  50.     });
  51.   }
  52.  
  53.   remove(index) {
  54.     this.appointments.splice(index, 1);
  55.   }
  56.  
  57.   submit() {
  58.     this.common.presentLoading("Loading...");
  59.     this.authService.postData(this.appointments, "new_car").then(
  60.       result => {
  61.         this.response = result;
  62.         this.dbData = this.response.data
  63.  
  64.         if (this.dbData.success === false) {
  65.           this.common.presentToast(this.dbData.msg);
  66.           this.common.closeLoading();
  67.           return false;
  68.         }
  69.         this.common.presentToast("success");
  70.         this.close_modal();
  71.         this.common.closeLoading();
  72.       },
  73.       err => {
  74.         this.common.presentToast('Connection failed');
  75.         console.log(err);
  76.         this.common.closeLoading();
  77.       });
  78.   }
  79.  
  80.   prices(idx) {
  81.     this.common.presentLoading("Loading...");
  82.     this.common.closeLoading();
  83.     const modal = this.modalCtrl.create("ScheduleTabCarModalPricePage", {
  84.       'idx': idx
  85.     });
  86.     modal.present();
  87.  
  88.     modal.onDidDismiss((data) => {
  89.       if (data) {
  90.         this.appointments[data.idx].price_id = data.price_id;
  91.         this.appointments[data.idx].type = data.type;
  92.         this.appointments[data.idx].price = data.price;
  93.       }
  94.     });
  95.   }
  96.  
  97.   close_modal() {
  98.     this.view.dismiss();
  99.   }  
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement