import {Component, OnInit, ViewChild} from '@angular/core';
import {WorkService} from '../work.service';
import {pageSize} from '../../app.constants';
import {Router} from '@angular/router';
import {TypeAsetsComponent} from '../modal/type-asets/type-asets.component';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
  selector: 'smart-asset-part',
  templateUrl: './asset-part.component.html',
  styles: []
})
export class AssetPartComponent implements OnInit {
    @ViewChild('smartTypeAsets') smartTypeAsets:TypeAsetsComponent;

    timeFormat = 'yyyy-MM-dd';
    parentList;
    childrenList;
    timeBegin;
    timeEnd;
    pageCount = pageSize;
    pageNum = 1;
    totalNum;

    obj = {
        pageCount:null,
        pageNum:null,
        searchStr:'',
        type:null,
        status:null,
        source:null,
        startTime:'',
        endTime:'',
    };
    constructor(private workSer:WorkService,private router:Router,
                private messge:NzMessageService) { }

    ngOnInit() {
        this.getList();
    }

    getList(){
        this.workSer.findByParentType().subscribe(
            (res)=>{
                if(res.errCode == 10000){
                    this.parentList = res.data;
                }else{
                    this.messge.error(res.errMsg);
                }
            }
        )
    }

    changeType(e){
        this.workSer.findByParentidCount(e).subscribe(
            (res)=>{
                this.childrenList = res.data;
            }
        )
    }

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

    goToChild(data){
        this.router.navigate(['app/main/assetChild'],
            {
                queryParams:{
                    id:data.id
                }
            })
    }

    showAddModal(){
        this.smartTypeAsets.showAddModal("新增分类");
    }

    showAEditModal(){
        this.smartTypeAsets.showEditModal("编辑分类");
    }

}
