import { Component, OnInit } from '@angular/core';
import { NzModalService } from 'ng-zorro-antd';
import { MessageService, Config } from 'pz-unit';
import { AuthStatusApi } from 'app/core/authStatus.api';
import { <%= classify(name) %>DialogComponent } from './dialog/<%= dasherize(name) %>-dialog.component';
import { <%= classify(name) %>Api } from 'app/api/<%= dasherize(name) %>.api';
import { <%= classify(name) %>Model } from 'app/api/model/<%= dasherize(name) %>.model';
import { EnumResourceList } from 'app/api/enums/Enum<%= classify(name) %>';

@Component({
    selector: '<%= selector %>',
    templateUrl: './<%= dasherize(name) %>.component.html',
    styleUrls: ['./<%= dasherize(name) %>.component.<%= style %>']
})
export class <%= classify(name) %>Component implements OnInit {
    public pageConfig: any = new Config();

    public constructor(
            private api: <%= classify(name) %>Api,
            private modal: NzModalService,
            private auth: AuthStatusApi,
            private msg: MessageService
    ) {
        }

    public ngOnInit() {
            this.getResource();
    }

    getResource() {
        this.auth.getRouteResource(location.pathname).subscribe(res => {
            this.pageConfig = new Config(res, EnumResourceList);
            if (this.pageConfig.canActive(1)) {
                this.getPage();
            }
        });
    }

    public openDialog(id: string, type: string) {
            this.msg.showLoading();
            // 模态窗放式弹窗
            const modal = this.modal.create({
                nzTitle: '详情内容',
                nzContent: <%= classify(name) %>DialogComponent,
                nzStyle: {top: '20px', padding: '0 20px 20px 20px'},
                nzWidth: '60vw',
                nzFooter: null
            });
            // 抽屉弹窗
            modal.afterOpen.subscribe(() => {
                // 赋值
                if (type === 'update' || type === 'view') {
                    // 更新操作
                    this.msg.hideLoading();
                } else {
                    this.msg.hideLoading();
                }
            });
            modal.afterClose.subscribe((result) => {
                if (result) {
                    this.getPage();
                }
            });
        }

        // 页面加载数据
    public getPage() {
            this.msg.showLoading();
            this.api.getAllList().subscribe(
                (res: any) => {
                    this.msg.hideLoading();
                    console.log(res);
                }
            );
        }
}
