Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import icSearch from '@iconify/icons-ic/twotone-search';
- import { TableRequest } from '../model/simulasi-jumlah-sampling.model';
- import { RepositoryService } from 'src/app/shared/services/repository.service';
- import { samplingVoucherList } from 'src/app/shared/services/uji-tuntas/config';
- import { UjiTuntasService } from 'src/app/shared/services/uji-tuntas/uji-tuntas.service';
- import { ActivatedRoute } from '@angular/router';
- @Component({
- selector: 'vex-rekomen-result-sampling',
- templateUrl: './rekomen-result-sampling.component.html',
- styleUrls: ['./rekomen-result-sampling.component.scss']
- })
- export class RekomenResultSamplingComponent implements OnInit {
- icSearch = icSearch;
- public rows: Array<object> = [];
- public columns: Array<object>;
- public pageSize: number;
- public recordsTotal: number;
- public paramRequest: TableRequest;
- public isLoading = true;
- selectRow: any;
- sort: string;
- search: string;
- token: string;
- debounceTimer: any;
- debounceTime = 500;
- idSelect:any;
- colsName: any = [];
- sortField: string;
- index: any;
- constructor(
- private repositoryService: RepositoryService,
- private ujituntasService: UjiTuntasService,
- private route: ActivatedRoute,
- ) {
- this.route.params.subscribe((params) => {
- this.idSelect = params['id'];
- });
- }
- ngOnInit(): void {
- this.sortField = 'id';
- this.token = localStorage.getItem('token');
- this.columns = [
- { name: 'No Rekening', field: 'noRekening' },
- { name: 'No Nasabah', field: 'noNasabah' },
- { name: 'No Kantor', field: 'namaKantor' },
- { name: ' Kd Kualitas', field: 'kdKualitas' },
- { name: 'Laporan Net', field: 'jmlBulLap' },
- { name: 'Kd Gol Nasabah', field: 'kdGolNasabah' },
- { name: 'Gol Nasabah', field: 'golNasabah' },
- { name: 'Jenis Penggunaan', field: 'jenisPenggunaan' },
- { name: 'Jenis Kredit', field: 'jenisKredit' },
- { name: 'Sampling Cabang', field: 'samplingCabang' },
- { name: 'Sampling Saldo Minimum', field: 'samplingSaldoMinimum' },
- { name: 'Sampling Gol Nasabah',field: 'samplingGolNasabah' },
- { name: 'Sampling Jenis Valuta', field: 'samplingJenisValuta' },
- { name: 'Sampling Jenis Kredit', field: 'samplingFinalDebitur' },
- { name: 'Sampling Final', field: 'samplingFinal' },
- ];
- this.pageSize = 10;
- this.paramRequest = {
- start: 0,
- length: this.pageSize,
- };
- this.getDataJson(this.paramRequest);
- }
- getDataJson(param: TableRequest) {
- const token = localStorage.getItem('token');
- this.isLoading = true;
- const index = this.index ? this.index : 0;
- const formData = new FormData();
- formData.append('start', param.start.toString());
- formData.append('length', param.length.toString());
- formData.append('search[value]', this.search ? this.search.toString() : '');
- formData.append('search[regex]', 'false');
- formData.append('columns['+index+'][data]', index+1);
- formData.append('columns['+index+'][orderable]', 'true');
- formData.append('columns['+index+'][searchable]', 'true');
- formData.append('columns['+index+'][name]', this.sortField);
- formData.append('order[0][column]', index+1);
- formData.append('order[0][dir]', this.sort ? this.sort : 'desc');
- this.repositoryService.postDataWithToken(samplingVoucherList.sampleVouchingRekomenByResultSampling+"/" + this.idSelect,formData, token, null).subscribe((res: any) => {
- this.recordsTotal = res.data.recordsFiltered as number;
- this.colsName = res.data.colsName.split(', ');
- this.rows = res.data.data;
- this.isLoading = false;
- });
- }
- sortPage(page: any) {
- this.index = this.colsName?.findIndex(item => item == page.sortField);
- this.sort = page?.sortOrder === 1 ? 'asc' : 'desc';
- this.sortField = page?.sortField ? page.sortField : 'id';
- }
- updatePage(page: any) {
- if (page && page.sortField && page.sortOrder) {
- this.sortPage(page);
- }
- this.paramRequest = {
- start: page.first / page.rows,
- length: page.rows,
- };
- this.getDataJson(this.paramRequest);
- }
- refresh(){
- this.pageSize = 10;
- this.paramRequest = {
- start: 0,
- length: this.pageSize,
- };
- this.getDataJson(this.paramRequest);
- }
- downloadExcel() {
- this.ujituntasService.downloadXls2(samplingVoucherList.sampleVouchingXlsx+"/" + this.idSelect, this.token,'application/x-www-form-urlencoded')
- .subscribe((value: any) => {
- let url = window.URL.createObjectURL(value);
- let a = document.createElement('a');
- document.body.appendChild(a);
- a.setAttribute('style', 'display: none');
- a.href = url;
- a.download = 'samplevouching.xlsx';
- a.click();
- window.URL.revokeObjectURL(url);
- },
- (err) => {
- console.log(err);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement