import { Component, OnInit,Input,Output,EventEmitter,AfterViewInit,OnDestroy,ViewContainerRef, ViewChild} from '@angular/core';
import { Subject } from 'rxjs';
import { Http } from '@global/service/Http';
import { AppNotification } from '@global/service/Notification';
import { NavController, ModalController } from '@ionic/angular';
import { App } from '@global/service/App';
import { ComUtil } from '@global/util/ComUtil';
import { AppEnvironment } from 'src/environments/AppEnvironment';
import {OrgUserMobEditViewPage} from '@pages/demo/org-user-mob-edit-view/org-user-mob-edit-view.page';


@Component({
  selector: 'ctrl-db-sysportlet1-portlet',
  templateUrl: './grxx3-portlet.html',
  styleUrls: ['./grxx3-portlet.scss']
})
export class Db_sysportlet1 implements OnInit,AfterViewInit,OnDestroy{

    /**
     * 名称
     *
     * @type {string}
     * @memberof Db_sysportlet1
     */
    @Input() public name: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof Db_sysportlet1
     */
    @Input() public viewState: Subject<ViewState>;


    /**
     * 是否为内嵌视图
     *
     * @type {boolean}
     * @memberof Db_sysportlet1
     */
    @Input() public isembeddedView: boolean;

    /**
     * 是否为模态模式
     *
     * @type {boolean}
     * @memberof Db_sysportlet1
     */
    @Input() public isModalMode: boolean;

    /**
     * 当前部件激活数据
     *
     * @public
     * @type {void}
     * @memberof Db_sysportlet1
     */
    public $activeData: Array<any> = [];

    constructor(private $http: Http, private $notification: AppNotification,private $navCtrl:NavController,private $app:App,private $modalCtrl: ModalController) {

    }


    /**
     * 返回
     *
     * @memberof Db_sysportlet1
     */
    public backView() {
        if (this.isModalMode) {
            let res: any;
            if (this.$activeData && this.$activeData.length > 0) {
                res = { ret: 'OK', result: this.$activeData };
            } else {
                res = { ret: 'NO', result: [] };
            }
            this.$modalCtrl.dismiss(res, 'close');
        } else {
            this.$navCtrl.back();
        }
    }

    public getDatas(): any[] {
        return [];
    }

    public getData(): any {
        return {};
    }

    /**
     * 监听当前列表数据变化
     *
     * @type {Subject}
     * @memberof Db_sysportlet1
     */  
    public curValueSubject = new Subject();


    /**
     * 加载数据
     *
     * @param {*} data
     * @memberof Db_sysportlet1
     */
    public load(data:any) {
        
    }

    ngOnInit() {
        if (this.viewState) {
            this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                this.load(data);
            });
        }
    }

    public ngAfterViewInit(): void {}

    public ngOnDestroy(): void {
        this.curValueSubject.unsubscribe();
    }


}