Skip to content
sys-change-count.component.ts 6.97 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, OnInit} from '@angular/core';
import {AnalysisService} from '../analysis.service';
import {NzMessageService} from 'ng-zorro-antd';
import {DatePipe} from '@angular/common';
import {OverAllService} from '../../overAll/overAll.service';
import {WorkService} from '../../work/work.service';
import {CommonService} from '../../shared/common/common.service';
import {change_level} from '../../system-change/system-change.constants';
import {SystemChangeService} from '../../system-change/system-change.service';

@Component({
    selector: 'smart-sys-change-count',
    templateUrl: './sys-change-count.component.html',
    styles: []
})
export class SysChangeCountComponent implements OnInit {

    startTime;
    endTime;
wangqinghua's avatar
wangqinghua committed
    timeType = '4';
wangqinghua's avatar
wangqinghua committed
    isLoading = false;
wangqinghua's avatar
wangqinghua committed
    change_level = [{label: '全部', value: ''}, ...change_level];
wangqinghua's avatar
wangqinghua committed

    chartTopOption;
    topList;

    //显示无数据图片
    data = {
        left: false,
        right: false,
    };

    chartLastOption;
    lastList;

    obj = {
        classifyId: null,
        type: null,
        startTime: '',
        endTime: ''
    };
    typeList;

    isDownload = false;

    constructor(private analysisSer: AnalysisService, private message: NzMessageService, private datePipe: DatePipe,
                private systemChangeSer: SystemChangeService,
                private overAllSer: OverAllService, private workSer: WorkService, private commonSer: CommonService) {
    }

    ngOnInit() {
wangqinghua's avatar
wangqinghua committed
        this.obj.startTime = this.commonSer.getTimeByType('4').startTime;
        this.obj.endTime = this.commonSer.getTimeByType('4').endTime;
wangqinghua's avatar
wangqinghua committed
        this.getType();
        this.getTopEcharts();
wangqinghua's avatar
wangqinghua committed
        this.getLastEcharts();
wangqinghua's avatar
wangqinghua committed
    }

    //变更分类
    getType() {
        this.systemChangeSer.findByType('sys_change_type').subscribe(
            (res) => {
                if (res.data) {
                    this.typeList = res.data;
                } else {
                    this.message.warning('暂无变更类型');
                }
            }
        );
    }

    //获取Top图表  变更状态统计
    getTopEcharts() {
        this.analysisSer.statusReport(this.obj).subscribe(
            (res) => {
                this.isLoading = false;
                if (res.errCode == 10000) {
wangqinghua's avatar
wangqinghua committed
                    res.data.forEach(e => {
                        if (e.status == 1) e.name = '待提交';
                        if (e.status == 2) e.name = '待审核';
                        if (e.status == 3) e.name = '审核通过';
                        if (e.status == 4) e.name = '审核未通过';
                        if (e.status == 5) e.name = '退回关闭';
                        if (e.status == 6) e.name = '处理中';
                        if (e.status == 7) e.name = '变更完成';
                    });
wangqinghua's avatar
wangqinghua committed
                    if (res.data.length > 0) {
                        this.data.left = false;
                        this.topList = res.data;
                        this.setTopEcharts();
                    } else {
                        this.data.left = true;
                    }
                }
            }
        );
    }

    //变更状态统计
    setTopEcharts() {
        this.chartTopOption = {
            title: {
                text: '变更状态统计'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器,坐标轴触发有效
                    type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                },
wangqinghua's avatar
wangqinghua committed
                formatter: '{b}:{c}'
wangqinghua's avatar
wangqinghua committed
            },
wangqinghua's avatar
wangqinghua committed
            toolbox: {
                feature: {
                    saveAsImage: {}
wangqinghua's avatar
wangqinghua committed
                }
            },
            xAxis: {
                type: 'category',
                data: this.topList.map(e => {
wangqinghua's avatar
wangqinghua committed
                    return e.name;
wangqinghua's avatar
wangqinghua committed
                }),

            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    show: true,
                    interval: 'auto',
                },
            },
            series: [{
                name: '变更状态统计',
                data: this.topList.map(e => {
                    return e.count;
                }),
                type: 'bar'
            }]
        };
        this.isLoading = false;
    }

    //获取last图表
    getLastEcharts() {
        this.analysisSer.dateReport(this.obj).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    if (res.data.length > 0) {
                        this.data.right = false;
                        this.lastList = res.data;
                        this.setLastEcharts();
                    } else {
                        this.data.right = true;
                        this.isLoading = false;
                    }
                }
            }
        );
    }

    //设置last图表
    setLastEcharts() {
        this.chartLastOption = {
            title: {
                text: '数量变化趋势'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器,坐标轴触发有效
wangqinghua's avatar
wangqinghua committed
                    type: 'line'        // 默认为直线,可选为:'line' | 'shadow'
wangqinghua's avatar
wangqinghua committed
                },
wangqinghua's avatar
wangqinghua committed
                formatter: '{b} : {c}'
wangqinghua's avatar
wangqinghua committed
            },
wangqinghua's avatar
wangqinghua committed
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
wangqinghua's avatar
wangqinghua committed
            },
            xAxis: {
                type: 'category',
                data: this.lastList.map(e => {
                    return e.createDate;
                })
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    show: true,
                    interval: 'auto',
                },
            },
            series: [{
                name: '数量变化趋势',
                data: this.lastList.map(e => {
                    return e.count;
                }),
wangqinghua's avatar
wangqinghua committed
                type: 'line'
wangqinghua's avatar
wangqinghua committed
            }]
        };
        this.isLoading = false;
    }

    //时间改变
    changeType() {
wangqinghua's avatar
wangqinghua committed
        if(this.timeType =='99') return ;
wangqinghua's avatar
wangqinghua committed
        this.obj.startTime = this.commonSer.getTimeByType(this.timeType).startTime;
        this.obj.endTime = this.commonSer.getTimeByType(this.timeType).endTime;
wangqinghua's avatar
wangqinghua committed
    }

    //搜索
    search() {
        this.isLoading = true;
wangqinghua's avatar
wangqinghua committed
        if (this.timeType == '99') {
wangqinghua's avatar
wangqinghua committed
            this.obj.startTime = this.datePipe.transform(this.startTime, 'yyyy-MM-dd HH:mm:ss');
            this.obj.endTime = this.datePipe.transform(this.endTime, 'yyyy-MM-dd HH:mm:ss');
        }
        this.getLastEcharts();
        this.getTopEcharts();
    }

    //导出 可用性
    downLoadCommon() {
        this.isDownload = true;
wangqinghua's avatar
wangqinghua committed
        //下载文件
        const d = {
            format: 'excel'
wangqinghua's avatar
wangqinghua committed
        };
wangqinghua's avatar
wangqinghua committed
        this.systemChangeSer.sysChangeExport(d).subscribe(
wangqinghua's avatar
wangqinghua committed
            (res) => {
wangqinghua's avatar
wangqinghua committed
                this.isDownload = false;
                this.commonSer.downloadFile('变更.xlsx', res);