import { Component, SimpleChanges,ElementRef,Input,Output,EventEmitter, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Subscription } from 'rxjs'; import { TableEstornoService } from 'src/app/services/table-estorno.service'; import { delegate } from 'utils-decorators'; import { TableEstornoData } from '../../data/table-estorno.data'; import { AuthService } from '../../services/auth.service'; import { BlockService } from '../../services/block.service'; import { LoadingService } from '../../services/loading.service'; import { ToastService } from '../../services/toast.service'; import {Table} from '../../model/table'; @Component({ selector: 'app-table-generica', templateUrl: './tableGenerica.component.html', styleUrls: ['./tableGenerica.component.scss'] }) export class TableGenericaComponent implements OnInit, OnDestroy { @Input() table : Table; // theadTableModal = { proposta: [ "Produto","Proposta","Data","Valor(R$)","Status Proposta"] ,titulo: ["Produto","Título","Série","Status tit"] ,pagamento: ['Produto','Proposta','Data','Valor(R$)','Status Proposta'] ,boleto: ['Vencimento','Valor do Boleto','Pagamento','Valor Recebido'] }; // _object = Object; @Output() click: EventEmitter = new EventEmitter(); // @ViewChild('grid', { static: true }) grid: ElementRef; #sub?: Subscription; constructor( private toast: ToastService, private block: BlockService, private loading: LoadingService, ) { } async ngOnInit() { } ngOnDestroy() { this.#sub?.unsubscribe(); } ngOnChanges(changes : SimpleChanges){ if (changes.table){ console.log(changes.table.currentValue); debugger; } } /* @delegate() async baixarPdf(ficha: TableEstornoData) { this.block.block(this.grid.nativeElement, 'Carregando dados...'); try { const res = await this.fichaService.baixarFicha(ficha); window.open(res.url, '_blank'); } catch (err) { console.log(err); this.toast.danger({ header: 'Não foi possível acessar o PDF', message: 'Tente novamente mais tarde!' }); } finally { this.block.unblock(this.grid.nativeElement, 500); } } */ private carregarGrid( dados : any ) { this.block.block(this.grid.nativeElement, 'Carregando dados...'); try { debugger; //this.setPage(1); //const dados = await this.tableService.listar(page, 10); //this.dadosGrid = dados.dados; //this.quantidadePaginas = dados.totalGeral; } catch (err) { console.error(err); this.toast.danger({ header: 'Não foi possível carregar os dados', message: 'Tente novamente mais tarde!' }); } finally { this.block.unblock(this.grid.nativeElement, 500); } } @delegate() async abreModal(modalLiberacao : any,linha : TableEstornoData) { //await this.loading.present('Carregando dados...'); try { //this.acessarModal.nativeElement.checked = true; debugger; modalLiberacao.abreModal(linha); } catch (err) { console.error(err); this.toast.danger({ header: 'Não foi possível carregar os dados', message: 'Tente novamente mais tarde!' }); } finally { this.loading.dismiss(); } } @delegate() async setPage(page: number) { this.table.registrosPagina = this.table.registros.slice(this.table.tamanhoPagina*(page-1),this.table.tamanhoPagina*page); debugger; } public clicar(row : any){ debugger; console.log("Clicar"); this.click.next(row); } }