<template>
  <app-layout viewName="emitemtypepickuptreeview" viewTitle="物品类型选择树视图" :isShowCaptionBar="false" :isShowToolbar="false" :className="{ 'view-container': true, 'default-mode-view': true, 'depickuptreeview': true, 'emitem-type-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 EMItemTypeService from '@/service/emitem-type/emitem-type-service';

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


/**
 * 物品类型选择树视图基类
 *
 * @export
 * @class EMItemTypePickupTreeViewBase
 * @extends {PickupTreeViewBase}
 */
@Component({})
@VueLifeCycleProcessing
export default class EMItemTypePickupTreeViewBase extends PickupTreeViewBase {

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


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

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

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

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

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

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

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

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


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

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

    

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


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





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

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

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

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

    /**
     * 快速搜索
     *
     * @returns {void}
     * @memberof EMItemTypePickupTreeViewBase
     */
    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 EMItemTypePickupTreeViewBase
     */
    public tree_nodedblclick($event: any, $event2?: any) {
        this.engine.onCtrlEvent('tree', 'nodedblclick', $event);
    }

}
</script>

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