model-batch.component.ts 1.9 KB
Newer Older
1
import { Component, OnInit } from '@angular/core';
2
import {ApiService} from '../../api.service';
J
Jason 已提交
3
import {NzTableQueryParams} from 'ng-zorro-antd';
J
Jason 已提交
4
import {Router} from '@angular/router';
5
import {TabRef} from '../tabs/tabs.component';
6 7

@Component({
J
Jason 已提交
8 9 10
  selector: 'app-model-batch',
  templateUrl: './model-batch.component.html',
  styleUrls: ['./model-batch.component.scss']
11
})
J
Jason 已提交
12
export class ModelBatchComponent implements OnInit {
13 14 15 16 17 18 19 20 21 22 23 24 25 26

  batches: [];
  total = 0;
  pageIndex = 1;
  pageSize = 10;
  sortField = null;
  sortOrder = null;
  filters = [];
  keyword = '';
  loading = false;

  statusFilters = [{text: '启动', value: 1}];


J
Jason 已提交
27 28
  constructor(private as: ApiService, private router: Router, private tab: TabRef) {
    tab.name = '批量采集';
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  }

  ngOnInit(): void {
  }

  reload(): void {
    this.pageIndex = 1;
    this.keyword = '';
    this.load();
  }

  load(): void {
    this.loading = true;
    this.as.post('batches', {
      offset: (this.pageIndex - 1) * this.pageSize,
      length: this.pageSize,
      sortKey: this.sortField,
      sortOrder: this.sortOrder,
      filters: this.filters,
      keyword: this.keyword,
    }).subscribe(res => {

      this.batches = res.data;
      this.total = res.total;
    }, error => {
      console.log('error', error);
    }, () => {
      this.loading = false;
    });
  }

J
Jason 已提交
60
  create(): void {
61
    this.router.navigate(['/admin/project-batch-create']);
J
Jason 已提交
62 63 64
  }

  edit(c): void {
65
    this.router.navigate(['/admin/project-project-batch-edit/' + c.id]);
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  }

  onTableQuery(params: NzTableQueryParams): void {
    const {pageSize, pageIndex, sort, filter} = params;
    this.pageSize = pageSize;
    this.pageIndex = pageIndex;
    const currentSort = sort.find(item => item.value !== null);
    this.sortField = (currentSort && currentSort.key) || null;
    this.sortOrder = (currentSort && currentSort.value) || null;
    this.filters = filter;
    this.load();
  }

  search(): void {
    this.pageIndex = 1;
    this.load();
  }
}