<template>
  <app-layout viewName="emeqtypepickuptreeview" viewTitle="设备类型" :isShowCaptionBar="false" :isShowToolbar="false" :className="{ 'view-container': true, 'default-mode-view': true, 'depickuptreeview': true, 'emeqtype-pickup-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' 
            :isSingleSelect="isSingleSelect"
            :selectedData="selectedData"
            @nodedblclick="tree_nodedblclick($event)"
            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, PickupTreeViewBase } from '@/crm-core';
import EMEQTypeService from '@/service/emeqtype/emeqtype-service';

import PickupTreeViewEngine from '@engine/view/pickup-tree-view-engine';


/**
 * 设备类型基类
 *
 * @export
 * @class EMEQTypePickupTreeViewBase
 * @extends {PickupTreeViewBase}
 */
@Component({})
@VueLifeCycleProcessing
export default class EMEQTypePickupTreeViewBase extends PickupTreeViewBase {

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


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

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof EMEQTypePickupTreeViewBase
	 */
	public viewtag: string = 'a6606bb729380753fc447984af7c29ed';

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

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

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

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

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

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


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

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

    

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


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





    /**
     * 销毁视图回调
     *
     * @memberof EMEQTypePickupTreeViewBase
     */
    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 EMEQTypePickupTreeViewBase
     */
    @Prop() public selectedData?: string;

    /**
     * 是否单选
     *
     * @type {boolean}
     * @memberof EMEQTypePickupTreeViewBase
     */
    @Prop() public isSingleSelect?: boolean;

    /**
     * 是否显示按钮
     *
     * @type {boolean}
     * @memberof EMEQTypePickupTreeViewBase
     */
    @Prop({default: true}) public isShowButton!: boolean;

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

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

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

}
</script>

<style lang='less'>
@import './emeqtype-pickup-tree-view.less';
</style>