/
RomichN
/
cookies
Обзор
Документация
Войти
/
RomichN
/
cookies
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/app/app.component.ts
85 строк
2 KB
RomichN
two
13 дек 2024, 15:03
13 дек 2024, 15:03
3391809
Код
Авторство
О чём код?
import { Component } from '@angular/core'; import {FormBuilder, Validators} from "@angular/forms"; import {HttpClient} from "@angular/common/http"; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'cookies'; currency = "$"; productsData: any; form = this.fb.group({ product: ["",Validators.required], name: ["",Validators.required], phone: ["",Validators.required] }); constructor(private fb: FormBuilder, private http: HttpClient) { } ngOnInit() { this.http.get('https://testologia.ru/cookies') .subscribe((data: any) => { this.productsData = data; }); } scrollTo(target: HTMLElement, product?: any) { target.scrollIntoView({ behavior: "smooth" }); if (product) { this.form.patchValue({product: product.title + ' (' + product.price + ' ' + this.currency + ')'}); } } switchSugarFree(e: any) { this.http.get("https://testologia.ru/cookies" + (e.currentTarget.checked ? '?sugarfree' : '')) .subscribe(data => this.productsData = data); } changeCurrency() { let newCurrency = "$"; let coefficient = 1; if (this.currency === "$") { newCurrency = "₽"; coefficient = 90; } else if (this.currency === "₽") { newCurrency = "BYN"; coefficient = 3; } else if (this.currency === "₽") { newCurrency = "BYN"; coefficient = 3; } else if (this.currency === 'BYN') { newCurrency = '€'; coefficient = 0.9; } else if (this.currency === '€') { newCurrency = '¥'; coefficient = 6.9; } this.currency = newCurrency; this.productsData.forEach((item: any) => { item.price = (item.basePrice * coefficient).toFixed(1); }); } confirmOrder(){ if (this.form.valid){ this.http.post('https://testologia.ru/cookies-order', this.form.value) .subscribe({ next: (response: any) => { this.form.reset(); alert(response.message); }, error: (response: any) => { alert(response.error.message); } }); } } }