seleccion-articulos.component.ts 1.69 KB
import { Component, OnInit } from "@angular/core";
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { PromocionComponent } from 'src/app/shared/promocion/promocion.component';

@Component({
  selector: "app-seleccion-articulos",
  templateUrl: "./seleccion-articulos.component.html",
  styleUrls: ["./seleccion-articulos.component.scss"]
})
export class SeleccionArticulosComponent implements OnInit {
  timeoutHandler: any;
  categorias = [
    { id: 1, selected: false },
    { id: 2, selected: false },
    { id: 3, selected: false },
    { id: 4, selected: false },
    { id: 5, selected: false },
    { id: 6, selected: false }
  ];
  modalRef: BsModalRef;

  constructor(
    private modalService: BsModalService,
  ) { }

  ngOnInit() { }

  selectCategoria(index: number) {
    this.categorias.forEach((categoria, i) => {
      categoria.selected = index === i ? true : false;
    });
  }

  elegirArticulo(articulo: any) {
    if (articulo.promo) {
      this.modalRef = this.modalService.show(PromocionComponent, {
        class: 'custom-modal modal-dialog-centered',
        ignoreBackdropClick: true,
      })
    }
  }

  mouseup() {
    if (!this.timeoutHandler) return;
    clearInterval(this.timeoutHandler);
  }

  scrollY(el: HTMLElement, value) {
    el.scroll({ behavior: "smooth", top: value + el.scrollTop });
    this.timeoutHandler = setInterval(() => {
      el.scroll({ behavior: "smooth", top: value + el.scrollTop });
    }, 500);
  }

  scrollX(el: HTMLElement, value) {
    el.scroll({ behavior: "smooth", left: value + el.scrollLeft });
    this.timeoutHandler = setInterval(() => {
      el.scroll({ behavior: "smooth", left: value + el.scrollLeft });
    }, 500);
  }
}