<template>
  <app-layout viewName="emplandashboardview" viewTitle="计划数据看板视图" :isShowCaptionBar="false" :isShowToolbar="false" :className="{ 'view-container': true, 'default-mode-view': true, 'deportalview': true, 'emplan-dashboard-view': true }" layoutMode="VIEW" :isShowUserInfo="isDefaultView()" :openMode="openMode" @close-view="closeView($event)">
    <template slot="headerLeft">
      <div class="view-header-left">

        <div class="view-caption" v-if="isDefaultView()">{{$t(model.srfCaption)}}</div>
        <modal-breadcrumb v-if="isModalView()"/>
      </div>
    </template>
    <template slot="content">
      <div class="view-content-wrapper">
                    <view_dashboard 
                :viewState="viewState"  
                :viewparams="viewparams" 
                :context="JSON.parse(JSON.stringify(context))" 
                :isEnableCustomized = "false"
                name="dashboard"  
                ref='dashboard' 
                @load="dashboard_load($event)"  
                @closeview="closeView($event)">
            </view_dashboard>

      </div>
    </template>
  </app-layout>
</template>

<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { UIActionTool, Util } from '@/utils';
import { VueLifeCycleProcessing, DashboardViewBase } from '@/crm-core';
import EMPlanService from '@/service/emplan/emplan-service';

import PortalViewEngine from '@engine/view/portal-view-engine';


/**
 * 计划数据看板视图基类
 *
 * @export
 * @class EMPlanDashboardViewBase
 * @extends {DashboardViewBase}
 */
@Component({})
@VueLifeCycleProcessing
export default class EMPlanDashboardViewBase extends DashboardViewBase {

    /**
     * 实体服务对象
     *
     * @type {EMPlanService}
     * @memberof EMPlanDashboardViewBase
     */
    public appEntityService: EMPlanService = new EMPlanService;


    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof EMPlanDashboardViewBase
     */    
    public counterServiceArray:Array<any> = [];
    
    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof EMPlanDashboardViewBase
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof EMPlanDashboardViewBase
	 */
	public viewtag: string = '8e734893dc52033a06fa1a7eec14e1df';

    /**
     * 父数据对象
     *
     * @protected
     * @type {*}
     * @memberof EMPlanDashboardViewBase
     */
    protected srfparentdata: any = {};

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof EMPlanDashboardViewBase
	 */
    public customViewNavContexts:any ={
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof EMPlanDashboardViewBase
	 */
    public customViewParams:any ={
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof EMPlanDashboardViewBase
     */
    public model: any = {
        srfCaption: 'entities.emplan.views.dashboardview.caption',
        srfTitle: 'entities.emplan.views.dashboardview.title',
        srfSubTitle: 'entities.emplan.views.dashboardview.subtitle',
        dataInfo: ''
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof EMPlanDashboardViewBase
     */
    public containerModel: any = {
        view_dashboard: { name: 'dashboard', type: 'DASHBOARD' },
    };

    /**
     * 视图状态订阅对象
     *
     * @public
     * @type {Subject<{action: string, data: any}>}
     * @memberof EMPlanDashboardViewBase
     */
    public viewState: Subject<ViewState> = new Subject();


    /**
     * 视图引擎
     *
     * @public
     * @type {Engine}
     * @memberof EMPlanDashboardViewBase
     */
    public engine: PortalViewEngine = new PortalViewEngine();
	

    /**
     * 引擎初始化
     *
     * @public
     * @memberof EMPlanDashboardViewBase
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            dashboard: this.$refs.dashboard,
            keyPSDEField: 'emplan',
            majorPSDEField: 'emplanname',
            isLoadDefault: true,
        });
    }

    

    /**
     * dashboard 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof EMPlanDashboardViewBase
     */
    public dashboard_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('dashboard', 'load', $event);
    }





    /**
     * 销毁视图回调
     *
     * @memberof EMPlanDashboardViewBase
     */
    public destroyed(){
        if(this.viewDefaultUsage){
            let localStoreLength = Object.keys(localStorage);
            if(localStoreLength.length > 0){
                localStoreLength.forEach((item:string) =>{
                if(item.startsWith(this.context.srfsessionid)){
                    localStorage.removeItem(item);
                }
                })
            }
        }
    }

}
</script>

<style lang='less'>
@import './emplan-dashboard-view.less';
</style>