<template>
  <app-layout viewName="emobjmaplocationtreeview" viewTitle="位置信息" :isShowCaptionBar="false" :isShowToolbar="false" :className="{ 'view-container': true, 'default-mode-view': true, 'detreeview': true, 'emobj-map-location-tree-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">
        
<div class="tree-contant">
    <view_tree 
    :viewState="viewState"  
    :viewparams="viewparams" 
    :context="context" 
    :showBusyIndicator="true"
    updateAction='Update' 
    removeAction='Remove' 
    loadAction='Get' 
    createAction='Create' 
    name="tree"  
    ref='tree' 
    @selectionchange="tree_selectionchange($event)"  
    @load="tree_load($event)"  
    @closeview="closeView($event)">
</view_tree>
</div>


      </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, TreeViewBase } from '@/crm-core';
import EMObjMapService from '@/service/emobj-map/emobj-map-service';

import TreeViewEngine from '@engine/view/tree-view-engine';


/**
 * 位置信息基类
 *
 * @export
 * @class EMObjMapLocationTreeViewBase
 * @extends {TreeViewBase}
 */
@Component({})
@VueLifeCycleProcessing
export default class EMObjMapLocationTreeViewBase extends TreeViewBase {

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


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

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof EMObjMapLocationTreeViewBase
	 */
	public viewtag: string = '3b9ed2292d3adb1fa915a4d69e587056';

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

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

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

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

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof EMObjMapLocationTreeViewBase
     */
    public containerModel: any = {
        view_tree: { name: 'tree', type: 'TREEVIEW' },
    };

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


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

    /**
     * 引擎初始化
     *
     * @public
     * @memberof EMObjMapLocationTreeViewBase
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            tree: this.$refs.tree,
            keyPSDEField: 'emobjmap',
            majorPSDEField: 'emobjmapname',
            isLoadDefault: true,
        });
    }

    

    /**
     * tree 部件 selectionchange 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof EMObjMapLocationTreeViewBase
     */
    public tree_selectionchange($event: any, $event2?: any) {
        this.engine.onCtrlEvent('tree', 'selectionchange', $event);
    }


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





    /**
     * 销毁视图回调
     *
     * @memberof EMObjMapLocationTreeViewBase
     */
    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);
                }
                })
            }
        }
    }


    /**
     * 节点过滤值
     *
     * @type {string}
     * @memberof EMObjMapLocationTreeViewBase
     */
    public srfnodefilter: string = '';

    /**
     * 快速搜索
     *
     * @returns {void}
     * @memberof EMObjMapLocationTreeViewBase
     */
    public onSearch(): void {
        if (!this.viewState) {
            return;
        }
        this.viewState.next({ tag: 'tree', action: 'filter', data: { srfnodefilter: this.srfnodefilter } });
    }
    
}
</script>

<style lang='less'>
@import './emobj-map-location-tree-view.less';
</style>