import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { NzModalService } from 'ng-zorro-antd'; import { AnalysisService } from '../shared/analysis.service'; import { AnalysisFormComponent } from '../analysis-form/analysis-form.component'; import { AnalysisChartConfigComponent } from '../analysis-chart-config/analysis-chart-config.component'; @Component({ selector: 'analysis-detail', templateUrl: './analysis-detail.component.html', styleUrls: ['./analysis-detail.component.less'] }) export class AnalysisDetailComponent implements OnInit { _allChecked = false; _disabledButton = true; checkedRecordList = []; uuids = []; // 选中的数据记录的uuid // _displayData = []; recordList = []; _indeterminate = false; analysisId: number; analysisName: string; analysisDescription: string; dataBaseId: number; tableId: number; chartSetting = { chartType: 1 }; constructor(private router: Router, private routerInfo: ActivatedRoute, private analysisServ: AnalysisService, private modalServ: NzModalService) { } _displayDataChange($event: any[]) { this.recordList = $event; } _checkAll(value: any) { if (value) { this.recordList.forEach(data => data.checked = true); } else { this.recordList.forEach(data => data.checked = false); } this._refreshStatus(); } _refreshStatus() { const allChecked = this.recordList.every(value => value.checked === true); const allUnChecked = this.recordList.every(value => !value.checked); this._allChecked = allChecked; // 部分选中 this._indeterminate = (!allChecked) && (!allUnChecked); // 选中的数据记录 this.uuids = this.recordList.filter(value => value.checked).map(record => record.uuid); } ngOnInit() { this.analysisId = this.routerInfo.snapshot.params.analysisId; this.getAnalysisDetail(this.analysisId); } getAnalysisDetail(id: number) { this.analysisServ.getAnalysis(id).subscribe(data => { this.recordList = data.data.recordList || []; // this._displayData = this.recordList; this.analysisName = data.data.name; this.analysisDescription = data.data.description; this.tableId = data.data.tableId; this.dataBaseId = data.data.databaseId; this.chartSetting = data.data.chartSetting || {}; }); } parsePath(pathList: any) { let path = ''; pathList.forEach(item => { path += `${item.cnName}>`; }); return path.slice(0, -1); } showChartConfig() { const subscription = this.modalServ.open({ title: '图表配置', content: AnalysisChartConfigComponent, footer: false, componentParams: { analysisId: this.analysisId, tableId: this.tableId, chartSetting: this.chartSetting } }); subscription.subscribe(result => { if (result == 'success') { subscription.destroy(); // this.router.navigate(['chart']) } else if (result === 'nodata') { console.log('no data'); } }); } toChartResult() { // if (!this.chartSetting.hasOwnProperty('chartType')) { // this.modalServ.warning({ // content: '请先配置!' // }); // return; // } this.router.navigate(['./', 'chart'], { queryParams: { uuids: this.uuids } }); } editAnalysis() { const subscription = this.modalServ.open({ title: '编辑分析', content: AnalysisFormComponent, footer: false, componentParams: { id: this.analysisId, name: this.analysisName, description: this.analysisDescription, dataBaseId: this.dataBaseId, tableId: this.tableId } }); subscription.subscribe(result => { if (result === 'success') { subscription.destroy(); this.getAnalysisDetail(this.analysisId); } }); } tableCompare() { } chartCompare() { } deleteRecord(uuid?: string) { // const uuids = uuid ? [uuid] : this.uuids; const that = this; if (this.uuids.length === 0) { const modal = this.modalServ.warning({ title: '请选择条目' }); setTimeout(() => modal.destroy(), 1000); return; } this.modalServ.confirm({ title: '确认要删除?', content: '删除后将无法恢复', showConfirmLoading: true, onOk() { that.analysisServ.deleteRecordFromAnalysis(that.analysisId, this.uuids).subscribe(data => { that.getAnalysisDetail(that.analysisId); }); } }); } }