Skip to content
asset-manage.component.ts 5.76 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, OnInit, ViewChild} from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import {DatePipe} from '@angular/common';
import {InfomationService} from '../infomation.service';
import {UploadComponent} from '../../work/modal/upload/upload.component';
import {pageSize} from '../../app.constants';
import {CommonService} from '../../shared/common/common.service';
import {asset_type} from '../information.constans';
wangqinghua's avatar
wangqinghua committed
import {UploadAssetComponent} from '../modal/upload-asset/upload-asset.component';
wangqinghua's avatar
wangqinghua committed
import {CreatePropertyComponent} from '../modal/create-property/create-property.component';
wangqinghua's avatar
wangqinghua committed
import {MonitorService} from '../../monitor/monitor.service';
wangqinghua's avatar
wangqinghua committed

@Component({
wangqinghua's avatar
wangqinghua committed
    selector: 'smart-asset-manage',
    templateUrl: './asset-manage.component.html',
    styles: []
wangqinghua's avatar
wangqinghua committed
})
export class AssetManageComponent implements OnInit {
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartUploadAsset') smartUploadAsset: UploadAssetComponent;
wangqinghua's avatar
wangqinghua committed
    @ViewChild('smartCreateProperty') smartCreateProperty: CreatePropertyComponent;
wangqinghua's avatar
wangqinghua committed

    allChecked = false;
    disabledButton = true;
    indeterminate = false;

    dataSet;
    typeList = asset_type;

    isLoading = false;
    pageCount = pageSize;
    pageNum = 1;
    totalNum;
wangqinghua's avatar
wangqinghua committed
    isDownload;
wangqinghua's avatar
wangqinghua committed

    obj = {
        type: null,
wangqinghua's avatar
wangqinghua committed
        classification: null,
wangqinghua's avatar
wangqinghua committed
        no: null,
        name: null,
        attributionProject: '',
        contacts: '',
wangqinghua's avatar
wangqinghua committed
    };
wangqinghua's avatar
wangqinghua committed
    selectList = [];
wangqinghua's avatar
wangqinghua committed

    constructor(private infoSer: InfomationService, private message: NzMessageService,
wangqinghua's avatar
wangqinghua committed
                private monitorSer: MonitorService,
wangqinghua's avatar
wangqinghua committed
                private router: Router, private commonSer: CommonService, private datePipe: DatePipe) {
    }

    ngOnInit() {
        this.getList();
    }

    checkAll(value: boolean): void {
        this.dataSet.forEach(data => data.checked = value);
        this.refreshStatus();
    }

    refreshStatus(): void {
        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);
    }

    //获取列表
    getList() {
        this.isLoading = true;
        const obj = {
            pageCount: this.pageCount,
            pageNum: this.pageNum,
wangqinghua's avatar
wangqinghua committed
            obj: this.obj,
wangqinghua's avatar
wangqinghua committed
        };
        this.infoSer.propertyPage(obj).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.dataSet = res.data.data;
                    this.totalNum = res.data.totalNum;
                }
wangqinghua's avatar
wangqinghua committed
                this.isLoading = false;
wangqinghua's avatar
wangqinghua committed
            }
        );
    }

    //翻页
    change(e) {
        this.pageNum = e;
        this.getList();
    }

    //查看详情
    lookEvent(item) {
        this.router.navigate(['app/main/handleDetail'], {
            queryParams: {
                eventId: item.id
            }
        });
    }

    //处理事件
    goToHandle(item) {
        this.router.navigate(['app/main/handleEvent'], {
            queryParams: {
                eventId: item.id
            }
        });
    }

    //新增事件
    showAddModal() {
wangqinghua's avatar
wangqinghua committed
        this.smartCreateProperty.showAddModal('新增资产');
wangqinghua's avatar
wangqinghua committed
    }

    //编辑事件
    showEditModal(item) {
wangqinghua's avatar
wangqinghua committed
        this.smartCreateProperty.showEditModal('编辑资产', item.id);
    }

    selectItem(item, e) {
        if (e) {
            this.selectList.push(item);
        } else {
            this.selectList.forEach((value, index) => {
                if (value.id == item.id) {
                    this.selectList.splice(index, 1);
                }
            });
        }
        this.refreshStatus();
    }

    //批量删除
    batchDelete() {
        if (this.selectList.length == 0) {
            this.message.warning('请选择需要删除的资产');
            return false;
        }
        this.isLoading = true;
        const data = {
            ids: this.selectList.map(e => {
                return e.id;
            })
        };
        this.commonSer.confirmThing('批量删除', '确定删除选择的资产?', () => {
            this.infoSer.propertyDelete(data).subscribe(
                (res) => {
                    if (res.errCode == 10000) {
                        this.getList();
                        this.message.success('删除资产成功');
                    }
                    this.isLoading = false;
                }
            );
        });
wangqinghua's avatar
wangqinghua committed
    }

    //删除资产
    deleteHandle(data) {
        const arr = {
            ids: []
        };
        arr.ids.push(data.id);
        this.commonSer.confirmThing('删除', '确定删除该资产', () => {
            this.infoSer.propertyDelete(arr).subscribe(
                (res) => {
wangqinghua's avatar
wangqinghua committed
                    if (res.errCode == 10000) {
                        this.message.success('删除成功');
                        this.getList();
wangqinghua's avatar
wangqinghua committed
                        this.deleteMonitor(data.id);
wangqinghua's avatar
wangqinghua committed
                    }
wangqinghua's avatar
wangqinghua committed
                }
            );
        });
    }

wangqinghua's avatar
wangqinghua committed
    deleteMonitor(id) {
        this.monitorSer.assetDelete(id, null).subscribe(
            (res) => {

            }
        );
    }

wangqinghua's avatar
wangqinghua committed
    //转派
    showTransforModal(item) {
        // this.smartTransfor.showTransforModal('事件转派', item.id);
    }

    //搜索
    search() {
        this.pageNum = 1;
        this.getList();
    }

    //上传资产
    showUploadModal() {
wangqinghua's avatar
wangqinghua committed
        this.smartUploadAsset.showModal('导入资产');
wangqinghua's avatar
wangqinghua committed
    }

    //导出资产
    downLoad() {
wangqinghua's avatar
wangqinghua committed
        this.isDownload = true;
        this.infoSer.propertyExport().subscribe(
wangqinghua's avatar
wangqinghua committed
            (res) => {
wangqinghua's avatar
wangqinghua committed
                this.isDownload = false;
wangqinghua's avatar
wangqinghua committed
                this.commonSer.downloadFile('资产管理.xlsx', res);
wangqinghua's avatar
wangqinghua committed
            }
        );
    }
wangqinghua's avatar
wangqinghua committed
}