appointments_frontend/ng-seed/src/app/end-user/payment/payment.component.ts
2023-04-18 14:44:13 +05:30

100 lines
3.0 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { EndUserService } from '../end-user.service';
@Component({
selector: 'app-payment',
templateUrl: './payment.component.html',
styleUrls: ['./payment.component.scss']
})
export class PaymentComponent implements OnInit {
form: FormGroup;
bookedAppointment_servicemap: any;
busName: string;
constructor(private router:Router,public enduser:EndUserService, private route: ActivatedRoute, ) {
this.enduser.appointmentBooked_observable$.subscribe((res) => {
console.log('booked', res);
if(res.length>0){
this.bookedAppointment_servicemap=res[0].id;
}else{
let URL = this.router.url;
console.log(URL)
let URL_AS_LIST = URL.split('/');
console.log(URL_AS_LIST);
//this.router.navigate(['customer/business/'+URL_AS_LIST[3]])
this.router.navigate(['customer/'+URL_AS_LIST[2]+'/'+URL_AS_LIST[3]])
}
})
}
ngOnInit(): void {
this.busName = localStorage.getItem('busName')
this.form = new FormGroup({
cardName: new FormControl('', [Validators.required]),
cardNo: new FormControl('', [Validators.required, Validators.maxLength(16)]),
cvv: new FormControl('', [Validators.required, Validators.maxLength(3)]),
expiryDate: new FormControl('', [Validators.required]),
});
}
public myError = (controlName: string, errorName: string) =>{
return this.form.controls[controlName].hasError(errorName);
}
submit(){
console.log(this.form.value)
let slot_array = JSON.parse(localStorage.getItem("slotData"))
let service = localStorage.getItem("servicedetails")
let serviceDetails = JSON.parse(service)
console.log(serviceDetails)
let URL = this.router.url;
console.log(URL,slot_array)
let URL_AS_LIST = URL.split('/');
console.log(URL_AS_LIST);
let paramsmap= {
"serviceId": ""+serviceDetails.serviceId+"",
"userId": serviceDetails.userId,
"busId": serviceDetails.busId
}
this.enduser.CreatecusServicesMapDetails(paramsmap).subscribe(res => {
if (res.status == 200) {
console.log(res)
let serviceMap = res['data'][0].id
let time = new Date().toLocaleTimeString()
let params= {
"busId": serviceDetails.busId,
"cusId": URL_AS_LIST[9],
"appoinmentDate": slot_array[0].date,
"appoinmentTime": time,
"serviceMap": serviceMap,
"appoinmentSlots": slot_array[0].slots,
//"servicemap" :this.bookedAppointment_servicemap
}
console.log(params)
this.enduser.CreateAppoinmentsCus(params).subscribe(res => {
if (res.status == 200) {
console.log(res)
this.enduser.summmarylist.next(res.data)
// localStorage.setItem('summarylist',JSON.stringify(res.data))
this.router.navigate([URL+"/bts"])
}
})
}
})
}
}