import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NzModalService } from 'ng-zorro-antd';
import { AnalysisService } from '../analysis.service';
import { parseResponse } from '../../../shared/util';
import { AnalysisFormComponent } from '../analysis-form/analysis-form.component';
@Component({
selector: 'analysis-list',
templateUrl: './analysis-list.component.html',
styleUrls: ['./analysis-list.component.less']
})
export class AnalysisListComponent implements OnInit {
_allChecked = false;
_disabledButton = true;
_checkedNumber = 0;
// _displayData: string[]= [];
_dataSet = [];
_indeterminate = false;
_loading = false;
constructor(private router: Router,
private modalServ: NzModalService,
private analysisServ: AnalysisService) { }
addAnalysis(): void {
const subscription = this.modalServ.open({
title: '新建分析',
content: AnalysisFormComponent,
footer: false,
});
subscription.subscribe(result => {
if (result === 'success') {
subscription.destroy();
this.getAnalysisList();
}
});
}
getAnalysisList(pageNum?: number, pageSize?: number): void {
this._loading = true;
this.analysisServ.getAnalysisList(pageNum, pageSize).subscribe(data => {
const dataObj = parseResponse(data);
this._dataSet = dataObj.data.results;
this._loading = false;
}, err => console.log(err));
}
toDetail(analysisId: number): void {
console.log(analysisId);
this.router.navigate([`${analysisId}`]);
}
deleteAnalysis(id?: number): void {
const that = this;
const ids = id ? [id] : [];
this._dataSet.forEach((data, index) => {
if (data.checked) {
ids.push(data.id);
}
});
if (ids.length === 0) {
const modal = this.modalServ.warning({
title: '请选择条目'
});
setTimeout(() => modal.destroy(), 1000);
return;
}
this.modalServ.confirm({
title: '确认要删除?',
content: '删除后将无法恢复',
showConfirmLoading: true,
onOk() {
that.analysisServ.deleteAnalysis(ids.join(',')).subscribe(data => {
const dataObj = parseResponse(data);
that.getAnalysisList();
});
}
});
}
_displayDataChange($event: object[]) {
// this._displayData = $event;
}
_checkAll(value: any) {
if (value) {
this._dataSet.forEach(data => data.checked = true);
} else {
this._dataSet.forEach(data => data.checked = false);
}
this._refreshStatus();
}
_refreshStatus() {
const allChecked = this._dataSet.every(value => value.checked === true);
const allUnChecked = this._dataSet.every(value => !value.checked);
this._allChecked = allChecked;
// 部分选中
this._indeterminate = (!allChecked) && (!allUnChecked);
this._disabledButton = !this._dataSet.some(value => value.checked);
this._checkedNumber = this._dataSet.filter(value => value.checked).length;
}
ngOnInit() {
this.getAnalysisList();
}
}
|