<template>
<div class="view-container dewfdynaexpgridview ibizsample0021-wfdyna-exp-grid-view">
    <app-studioaction :viewTitle="$t(model.srfCaption)" viewName="ibizsample0021wfdynaexpgridview"></app-studioaction>
    <card class='view-card  ' :disHover="true" :padding="0" :bordered="false">
<div slot='title' class="header-container">
    <span class='caption-info' :title="$t(model.srfCaption)">{{$t(model.srfCaption)}}</span>
</div>
    <div slot="extra">
        <div class='toolbar-container'>
            <tooltip :transfer="true" :max-width="600" v-for="(linkItem, index) in linkModel" :key="index">
                    <i-button :disabled="linkItem.disabled" @click="dynamic_toolbar_click(linkItem, $event)">
                        <span class='caption'>{{linkItem.sequenceFlowName}}</span>
                    </i-button>
                <div slot='content'>{{linkItem.sequenceFlowName}}</div>
            </tooltip>
        </div>
    </div>
    <split id="ibizsample0021wfdynaexpgridview" v-model="split" mode="horizontal">
        <div slot='left'>
            <el-tree ref="tree" :data="wfStepModel" node-key="userTaskId" :highlight-current="true" :props="defaultProps" @node-click="handleNodeClick">
                 <span class="custom-tree-node" slot-scope="{ node, data }">
                   <span class="tree-node-label">{{data.userTaskName}}</span>
                   <span class="tree-node-count"><badge :count="data.cnt"></badge></span>
                </span>
            </el-tree>
        </div>
        <div slot="right">
            <div class="content-container">
            <view_searchform 
    :viewState="viewState"  
    :viewparams="viewparams" 
    :context="context"
    :pViewCtx="viewCtx"
    :showBusyIndicator="true"
    v-show="isExpandSearchForm"
    loaddraftAction="FilterGetDraft"
    loadAction="FilterGet"

    name="searchform"  
    ref='searchform' 
    @search="searchform_search($event)"  
    @load="searchform_load($event)"  
    @save="searchform_save($event)"  
    @closeview="closeView($event)">
</view_searchform>
            <view_grid 
    :viewState="viewState"  
    :viewparams="viewparams" 
    :context="context"
    :pViewCtx="viewCtx"
    :isSingleSelect="isSingleSelect"
    :showBusyIndicator="true"
    updateAction=""
    removeAction="Remove"
    loaddraftAction=""
    loadAction=""
    createAction=""
    fetchAction="FetchDefault"
    :opendata="opendata"
    name="grid"  
    ref='grid' 
    @rowdblclick="grid_rowdblclick($event)"  
    @selectionchange="grid_selectionchange($event)"  
    @remove="grid_remove($event)"  
    @load="grid_load($event)"  
    @beforeload="grid_beforeload($event)"  
    @closeview="closeView($event)">
</view_grid>
            </div>
        </div>
    </split>
    </card>
</div>
</template>
// 基于 @VIEW/实体工作流动态导航表格视图/VIEW-BASE.vue.ftl 生成

<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch,Inject } from 'vue-property-decorator';
import { UIActionTool, Util } from '@/utils';
import axios from 'axios';
import { AppMessageBox } from '@/utils/app-message-box/app-message-box';
import NavDataService from '@/service/app/navdata-service';
import { Subject,Subscription } from 'rxjs';
import IBIZSample0021Service from '@/service/ibizsample0021/ibizsample0021-service';
import IBIZSample0021AuthService from '@/authservice/ibizsample0021/ibizsample0021-auth-service';

import WFDynaExpGridViewEngine from '@engine/view/wfdyna-exp-grid-view-engine';

import IBIZSample0021UIService from '@/uiservice/ibizsample0021/ibizsample0021-ui-service';


@Component({
    components: {
    },
})
export default class IBIZSample0021WFDynaExpGridViewBase extends Vue {

    /**
     * 实体服务对象
     *
     * @type {IBIZSample0021Service}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public appEntityService: IBIZSample0021Service = new IBIZSample0021Service();

    /**
     * 实体UI服务对象
     *
     * @type IBIZSample0021UIService
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public appUIService: IBIZSample0021UIService = new IBIZSample0021UIService();
    
    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

    /**
     * 传入视图上下文
     *
     * @type {string}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Prop() public viewdata!: string;

    /**
     * 传入视图参数
     *
     * @type {string}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Prop() public viewparam!: string;

    /**
     * 视图默认使用
     *
     * @type {boolean}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Prop({ default: true }) public viewDefaultUsage!: boolean;

    /**
     * 视图默认使用
     *
     * @type {string}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Inject({from:'navModel',default: 'tab'})
    public navModel!:string;

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof IBIZSample0021WFDynaExpGridViewBase
	 */
	public viewtag: string = '270a2cdf7072febc156805c6c967c010';

    /**
	 * 视图类型
	 *
	 * @type {string}
	 * @memberof IBIZSample0021WFDynaExpGridViewBase
	 */
	public viewType: string = 'DEWFDYNAEXPGRIDVIEW';

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

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

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

    /**
     * 视图参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Watch('viewparam',{immediate: true, deep: true})
    onParamData(newVal: any, oldVal: any) {
        if(newVal){
            this.viewparams = {};
            if(typeof newVal == 'string') {
                Object.assign(this.viewparams, JSON.parse(this.viewparam));
            }else{
                this.viewparams = Util.deepCopy(this.viewparam);
            }
            
        } 
    }

    /**
     * 处理应用上下文变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Watch('viewdata')
    onViewData(newVal: any, oldVal: any) {
        const _this: any = this;
        
        if (!Object.is(newVal, oldVal) && _this.engine) {
            this.$nextTick(()=>{
              _this.parseViewParam();
              _this.engine.load();
            });
        } else if(!Object.is(newVal, oldVal) && _this.refresh && _this.refresh instanceof Function) {
            _this.refresh();
        }
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public containerModel: any = {
        view_searchform: { name: 'searchform', type: 'SEARCHFORM' },
        view_toolbar: { name: 'toolbar', type: 'TOOLBAR' },
        view_grid: { name: 'grid', type: 'GRID' },
        wflinks: [],
    };

    /**
     * 视图操作参数
     *
     * @type {*}
     * @readonly
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public viewCtx: any = {};

    /**
     * 视图刷新
     *
     * @param {*} args
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public refresh(args?: any): void {
        const refs: any = this.$refs;
        if (refs && refs.grid) {
            refs.grid.refresh();
        }
    }
    /**
     *  计数器刷新
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public counterRefresh(){
        const _this:any =this;
        if(_this.counterServiceArray && _this.counterServiceArray.length >0){
            _this.counterServiceArray.forEach((item:any) =>{
                if(item.refreshData && item.refreshData instanceof Function){
                    item.refreshData();
                }
            })
        }
    }

    /**
     * 视图状态订阅对象
     *
     * @public
     * @type {Subject<{action: string, data: any}>}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public viewState: Subject<ViewState> = new Subject();
    /**
     * 工具栏模型
     *
     * @type {*}
     * @memberof IBIZSample0021WFDynaExpGridView
     */
    public toolBarModels: any = {
        tbitem19: { name: 'tbitem19', actiontarget: 'NONE', caption: '编辑', disabled: false, type: 'DEUIACTION', visabled: true,noprivdisplaymode:2,dataaccaction: '', uiaction: { tag: 'Edit', target: 'SINGLEKEY' } },

        tbitem22: {  name: 'tbitem22', type: 'SEPERATOR', visabled: true, dataaccaction: '', uiaction: { } },
        tbitem11: { name: 'tbitem11', actiontarget: 'NONE', caption: '导出', disabled: false, type: 'DEUIACTION', visabled: true,noprivdisplaymode:2,dataaccaction: '', uiaction: { tag: 'ExportExcel', target: '' }, MaxRowCount: 1000  },

    };



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

    /**
     * 引擎初始化
     *
     * @public
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            opendata: (args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any) => {
                this.opendata(args,fullargs, params, $event, xData);
            },
            grid: this.$refs.grid,
            searchform: this.$refs.searchform,
            keyPSDEField: 'ibizsample0021',
            majorPSDEField: 'ibizsample0021name',
            isLoadDefault: true,
        });
    }

    /**
     * 应用导航服务
     *
     * @type {*}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public  navDataService = NavDataService.getInstance();

    /**
    * 导航服务事件
    *
    * @public
    * @type {(Subscription | undefined)}
    * @memberof IBIZSample0021WFDynaExpGridViewBase
    */
    public serviceStateEvent: Subscription | undefined;

    /**
     * 门户部件状态对象
     *
     * @type {*}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Prop() public portletState?: any;

   /**
   * 门户部件状态事件
   *
   * @public
   * @type {(Subscription | undefined)}
   * @memberof IBIZSample0021WFDynaExpGridViewBase
   */
    public portletStateEvent: Subscription | undefined;

    /**
    * 门户部件状态事件
    *
    * @public
    * @type {(Subscription | undefined)}
    * @memberof IBIZSample0021WFDynaExpGridViewBase
    */
    public formDruipartEvent: Subscription | undefined;

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public context:any = {};

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public viewparams:any = {};

    /**
     * 视图缓存数据
     *
     * @type {*}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public viewCacheData:any;


    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */    
    public counterServiceArray:Array<any> = [];

    /**
     * 解析视图参数
     *
     * @public
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public parseViewParam(inputvalue:any = null): void {
        for(let key in this.context){
            delete this.context[key];
        }
        if(this.$store.getters.getAppData() && this.$store.getters.getAppData().context){
            Object.assign(this.context,this.$store.getters.getAppData().context);
        }
        if (!this.viewDefaultUsage && this.viewdata && !Object.is(this.viewdata, '')) {
            if(typeof this.viewdata == 'string') {
                Object.assign(this.context, JSON.parse(this.viewdata));
            }
            if(this.context && this.context.srfparentdename){
                Object.assign(this.viewparams,{srfparentdename:this.context.srfparentdename});
            }
            if(this.context && this.context.srfparentkey){
                Object.assign(this.viewparams,{srfparentkey:this.context.srfparentkey});
            }
            this.handleCustomViewData();
            return;
        }
        const path = (this.$route.matched[this.$route.matched.length - 1]).path;
        const keys: Array<any> = [];
        const curReg = this.$pathToRegExp.pathToRegexp(path, keys);
        const matchArray = curReg.exec(this.$route.path);
        let tempValue: Object = {};
        keys.forEach((item: any, index: number) => {
            if(matchArray[index + 1]){
                Object.defineProperty(tempValue, item.name, {
                    enumerable: true,
                    value: decodeURIComponent(matchArray[index + 1])
                });
            }
        });
        this.$viewTool.formatRouteParams(tempValue,this.$route,this.context,this.viewparams);
        if(inputvalue){
            Object.assign(this.context,{'ibizsample0021':inputvalue});
        }
        //初始化视图唯一标识
        Object.assign(this.context,{srfsessionid:this.$util.createUUID()});
        this.handleCustomViewData();
        //初始化导航数据
        this.initNavDataWithRoute();
    }

    /**
     * 处理自定义视图数据
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
	public handleCustomViewData(){
		if(Object.keys(this.customViewNavContexts).length > 0){
			Object.keys(this.customViewNavContexts).forEach((item:any) =>{
				let tempContext:any = {};
				let curNavContext:any = this.customViewNavContexts[item];
				this.handleCustomDataLogic(curNavContext,tempContext,item);
				Object.assign(this.context,tempContext);
			})
		}
		if(Object.keys(this.customViewParams).length > 0){
			Object.keys(this.customViewParams).forEach((item:any) =>{
				let tempParam:any = {};
				let curNavParam:any = this.customViewParams[item];
				this.handleCustomDataLogic(curNavParam,tempParam,item);
				Object.assign(this.viewparams,tempParam);
			})
		}
	}

    /**
     * 处理自定义视图数据逻辑
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
	public handleCustomDataLogic(curNavData:any,tempData:any,item:string){
		// 直接值直接赋值
		if(curNavData.isRawValue){
			if(Object.is(curNavData.value,"null") || Object.is(curNavData.value,"")){
                Object.defineProperty(tempData, item.toLowerCase(), {
                    value: null,
                    writable : true,
                    enumerable : true,
                    configurable : true
                });
            }else{
                Object.defineProperty(tempData, item.toLowerCase(), {
                    value: curNavData.value,
                    writable : true,
                    enumerable : true,
                    configurable : true
                });
            }
		}else{
			// 先从导航上下文取数，没有再从导航参数（URL）取数，如果导航上下文和导航参数都没有则为null
			if(this.context[(curNavData.value).toLowerCase()] != null){
				Object.defineProperty(tempData, item.toLowerCase(), {
					value: this.context[(curNavData.value).toLowerCase()],
					writable : true,
					enumerable : true,
					configurable : true
				});
			}else{
				if(this.viewparams[(curNavData.value).toLowerCase()] != null){
					Object.defineProperty(tempData, item.toLowerCase(), {
						value: this.viewparams[(curNavData.value).toLowerCase()],
						writable : true,
						enumerable : true,
						configurable : true
					});
				}else{
					Object.defineProperty(tempData, item.toLowerCase(), {
						value: null,
						writable : true,
						enumerable : true,
						configurable : true
					});
				}
			}
		}
	}

    /**
     * 初始化导航数据(路由模式)
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public initNavDataWithRoute(data:any = null, isNew:boolean = false,  isAlways:boolean = false){
        if( isAlways || (this.viewDefaultUsage && Object.is(this.navModel,"route")) ){
            this.navDataService.addNavData({id:'ibizsample0021-wfdyna-exp-grid-view',tag:this.viewtag,srfkey:isNew ? null : this.context.ibizsample0021,title:this.$t(this.model.srfCaption),data:data,context:this.context,viewparams:this.viewparams,path:this.$route.fullPath});
        }
    }

    /**
     * 初始化导航数据(分页模式)
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public initNavDataWithTab(data:any = null,isOnlyAdd:boolean = true, isAlways:boolean = false){
        if( isAlways || (this.viewDefaultUsage && !Object.is(this.navModel,"route")) ){
            this.navDataService.addNavDataByOnly({id:'ibizsample0021-wfdyna-exp-grid-view',tag:this.viewtag,srfkey:this.context.ibizsample0021,title:this.$t(this.model.srfCaption),data:data,context:this.context,viewparams:this.viewparams,path:this.$route.fullPath},isOnlyAdd);
        }
    }
	

    /**
     * Vue声明周期
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public created() {
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */    
    public afterCreated(){
        let _this:any = this;
        const secondtag = _this.$util.createUUID();
        _this.$store.commit('viewaction/createdView', { viewtag: _this.viewtag, secondtag: secondtag });
        _this.viewtag = secondtag;
        _this.parseViewParam();
        _this.serviceStateEvent = _this.navDataService.serviceState.subscribe(({ action,name, data }:{ action:string,name:any,data:any }) => {
            if(!Object.is(name,'ibizsample0021-wfdyna-exp-grid-view')){
                return;
            }
            if (Object.is(action, 'viewrefresh')) {
                _this.$nextTick(()=>{
                    _this.parseViewParam(data);
                    if(_this.engine){
                        _this.engine.load();
                    }
                }); 
            }
        });
        if(_this.portletState){
            _this.portletStateEvent = _this.portletState.subscribe((res:any) =>{
                if(!Object.is(res.name,'IBIZSample0021WFDynaExpGridView')){
                    return;
                }
                if(Object.is(res.action,'refresh') && _this.refresh && _this.refresh instanceof Function){
                    _this.refresh();
                }
            })
        }
        _this.initViewCtx();
    }

    /**
     * 初始化视图操作参数
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */  
    initViewCtx() {
        Object.assign(this.viewCtx, {
            app: this.$root,
            view: this,
            viewGlobal: {},
            viewNavData: {},
            viewNavContext: this.context,
            viewNavParam: this.viewparams,
            messagebox: AppMessageBox.getInstance(),
        });
        Object.assign(this.viewCtx, { appGlobal: this.$store.getters.getAppGlobal() });
        if (this.$store.getters.getRouteViewGlobal(this.context.srfsessionid)) {
            Object.assign(this.viewCtx, { routeViewGlobal: this.$store.getters.getRouteViewGlobal(this.context.srfsessionid) });
        } else {
            this.$store.commit('addRouteViewGlobal', { tag: this.context.srfsessionid, param: {} });
            Object.assign(this.viewCtx, { routeViewGlobal: this.$store.getters.getRouteViewGlobal(this.context.srfsessionid) });
        }
        if (!this.viewDefaultUsage && this.viewdata && !Object.is(this.viewdata, '')) {
            //  嵌入视图
            Object.assign(this.viewCtx, {
                topview: this.$store.getters.getView(this.context.srfsessionid)
            });
        } else {
            //  顶层视图
            this.$store.commit('addView', { tag: this.context.srfsessionid, param: this });
            Object.assign(this.viewCtx, { topview: this });
        }
    }

    /**
     * 销毁之前
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public beforeDestroy() {
        this.$store.commit('viewaction/removeView', this.viewtag);

        let _this: any = this
        if (_this.serviceStateEvent) {
            _this.serviceStateEvent.unsubscribe();
        }
        if (_this.portletStateEvent) {
            _this.portletStateEvent.unsubscribe();
        }
        if (_this.formDruipartEvent) {
            _this.formDruipartEvent.unsubscribe();
        }
        if (_this.engine) {
            _this.engine.destroy();
        }
    }

    /**
     * Vue声明周期(组件初始化完毕)
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public mounted() {
        this.afterMounted();
    }

    /**
     * 执行mounted后的逻辑
     * 
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public afterMounted(){
        const _this: any = this;
        _this.engineInit();
            if (_this.loadModel && _this.loadModel instanceof Function) {
                _this.loadModel();
            }
    }

    /**
     * searchform 部件 search 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public searchform_search($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'search', $event);
    }
    /**
     * searchform 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public searchform_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'load', $event);
    }
    /**
     * searchform 部件 save 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public searchform_save($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'save', $event);
    }
    /**
     * toolbar 部件 click 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public toolbar_click($event: any, $event2?: any) {
        if (Object.is($event.tag, 'tbitem19')) {
            this.toolbar_tbitem19_click(null, '', $event2);
        }
        if (Object.is($event.tag, 'tbitem11')) {
            this.toolbar_tbitem11_click(null, '', $event2);
        }
        if (Object.is($event.tag, 'tbitem13')) {
            this.toolbar_tbitem13_click(null, '', $event2);
        }
    }
    /**
     * grid 部件 rowdblclick 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public grid_rowdblclick($event: any, $event2?: any) {
        this.engine.onCtrlEvent('grid', 'rowdblclick', $event);
    }
    /**
     * grid 部件 selectionchange 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public grid_selectionchange($event: any, $event2?: any) {
        this.engine.onCtrlEvent('grid', 'selectionchange', $event);
    }
    /**
     * grid 部件 remove 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public grid_remove($event: any, $event2?: any) {
        this.engine.onCtrlEvent('grid', 'remove', $event);
    }
    /**
     * grid 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public grid_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('grid', 'load', $event);
    }
    /**
     * grid 部件 beforeload 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public grid_beforeload($event: any, $event2?: any) {
        this.engine.onCtrlEvent('grid', 'beforeload', $event);
    }


    /**
     * 逻辑事件
     *
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @memberof 
     */
    public toolbar_tbitem19_click(params: any = {}, tag?: any, $event?: any) {
        // 参数
        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let paramJO:any = {};
        let contextJO:any = {};
        xData = this.$refs.grid;
        if (xData.getDatas && xData.getDatas instanceof Function) {
            datas = [...xData.getDatas()];
        }
        if(params){
          datas = [params];
        }
        // 界面行为
        this.Edit(datas, contextJO,paramJO,  $event, xData,this,"IBIZSample0021");
    }

    /**
     * 逻辑事件
     *
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @memberof 
     */
    public toolbar_tbitem11_click(params: any = {}, tag?: any, $event?: any) {
        // 参数
        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let paramJO:any = {};
        let contextJO:any = {};
        xData = this.$refs.grid;
        if (xData.getDatas && xData.getDatas instanceof Function) {
            datas = [...xData.getDatas()];
        }
        if(params){
          datas = [params];
        }
        // 界面行为
        this.ExportExcel(datas, contextJO,paramJO,  $event, xData,this,"IBIZSample0021");
    }

    /**
     * 逻辑事件
     *
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @memberof 
     */
    public toolbar_tbitem13_click(params: any = {}, tag?: any, $event?: any) {
        // 参数
        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let paramJO:any = {};
        let contextJO:any = {};
        xData = this.$refs.grid;
        if (xData.getDatas && xData.getDatas instanceof Function) {
            datas = [...xData.getDatas()];
        }
        if(params){
          datas = [params];
        }
        // 界面行为
        this.Print(datas, contextJO,paramJO,  $event, xData,this,"IBIZSample0021");
    }

    /**
     * 打开编辑数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof IBIZSample0021WFDynaExpGridView
     */
    public opendata(args: any[],fullargs?:any,params?: any, $event?: any, xData?: any) {
        if(!this.viewDefaultUsage){
            if(Object.is(this.navModel,"route")){
                this.initNavDataWithRoute(this.viewCacheData, false, true);
            }else{
                this.initNavDataWithTab(this.viewCacheData, false, true);
            }
        }
        let localContext:any = null;
        let localViewParam:any =null;
        const data: any = {};
        let tempContext = JSON.parse(JSON.stringify(this.context));
        if(args.length >0){
            Object.assign(tempContext,args[0]);
        }
        if(this.viewparams && this.viewparams.userTaskId){
            Object.assign(data,{'userTaskId':this.viewparams.userTaskId})
        }
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'ibizsample0021s', parameterName: 'ibizsample0021' },
            { pathName: 'wfdynaeditview', parameterName: 'wfdynaeditview' },
        ];
        const _this: any = this;
        if (fullargs && fullargs.length > 0) {
            const _args = fullargs[0];
            if (_args['srfprocessdefinitionkey'] && _args['srftaskdefinitionkey']) {
                Object.assign(data, {
                    processDefinitionKey: _args['srfprocessdefinitionkey'],
                    taskDefinitionKey: _args['srftaskdefinitionkey']
                });
                if (_args['srftaskid']) {
                    Object.assign(data, { 'srftaskid': _args['srftaskid'] });
                }
            }
        }
        if(fullargs && fullargs.copymode){
            Object.assign(data,{copymode:true});
        }
        const openIndexViewTab = (data: any) => {
            const routePath = this.$viewTool.buildUpRoutePath(this.$route, tempContext, deResParameters, parameters, args, data);
            this.$router.push(routePath);
        }
        openIndexViewTab(data);
    }


    /**
     * 编辑
     *
     * @param {any[]} args 当前数据
     * @param {any} contextJO 行为附加上下文
     * @param {*} [params] 附加参数
     * @param {*} [$event] 事件源
     * @param {*} [xData]  执行行为所需当前部件
     * @param {*} [actionContext]  执行行为上下文
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public Edit(args: any[],contextJO?:any, params?: any, $event?: any, xData?: any,actionContext?:any,srfParentDeName?:string) {
        if (args.length === 0) {
            return;
        }
        const _this: any = this;
        if (_this.opendata && _this.opendata instanceof Function) {
            const data: any = { };
            if (args.length > 0) {
                Object.assign(data, { ibizsample0021: args[0].ibizsample0021 })
            }
            _this.opendata([{ ...data }], args, params, $event, xData);
        } else {
            _this.$Notice.error({ title: '错误', desc: 'opendata 视图处理逻辑不存在，请添加!' });
        }
    }
    /**
     * 导出
     *
     * @param {any[]} args 当前数据
     * @param {any} contextJO 行为附加上下文
     * @param {*} [params] 附加参数
     * @param {*} [$event] 事件源
     * @param {*} [xData]  执行行为所需当前部件
     * @param {*} [actionContext]  执行行为上下文
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public ExportExcel(args: any[],contextJO?:any, params?: any, $event?: any, xData?: any,actionContext?:any,srfParentDeName?:string) {
        const _this: any = this;
        if (!xData || !(xData.exportExcel instanceof Function) || !$event) {
            return ;
        }
        xData.exportExcel($event.exportparms);
    }
    /**
     * 打印
     *
     * @param {any[]} args 当前数据
     * @param {any} contextJO 行为附加上下文
     * @param {*} [params] 附加参数
     * @param {*} [$event] 事件源
     * @param {*} [xData]  执行行为所需当前部件
     * @param {*} [actionContext]  执行行为上下文
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public Print(args: any[],contextJO?:any, params?: any, $event?: any, xData?: any,actionContext?:any,srfParentDeName?:string) {
        let _this:any = this;
        if (!xData || !(xData.print instanceof Function) || !$event) {
            return ;
        }
        xData.print();
    }

    /**
     * 关闭视图
     *
     * @param {any[]} args
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public closeView(args: any[]): void {
        let _view: any = this;
        if (_view.viewdata) {
            _view.$emit('viewdataschange', Array.isArray(args)?args:[args]);
            _view.$emit('close', Array.isArray(args)?args:[args]);
        } else if (_view.$tabPageExp) {
            _view.$tabPageExp.onClose(_view.$route.fullPath);
        }
    }

    /**
     * 销毁视图回调
     *
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public destroyed(){
        this.afterDestroyed();
    }

    /**
     * 执行destroyed后的逻辑
     * 
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public afterDestroyed(){
        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);
                    }
                    })
                }
                if(Object.is(this.navModel,"tab")){
                    this.navDataService.removeNavDataByTag(this.viewtag);
                }
            }
            // 销毁计数器定时器
            if(this.counterServiceArray && this.counterServiceArray.length >0){
                this.counterServiceArray.forEach((item:any) =>{
                    if(item.destroyCounter && item.destroyCounter instanceof Function){
                        item.destroyCounter();
                    }
                })
            }
    }
        /**
     * 分割宽度
     *
     * @type {number}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public split: number = 0.2;

    /**
     * 视图引用数据
     * 
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public viewRefData:any = {
        "EDITDATA":{viewname:"ibizsample0021-wfdyna-edit-view",title:"entities.ibizsample0021.views.wfdynaeditview.caption", width: 800, height: 500},
        "NEWDATA":{viewname:"ibizsample0021-edit-view",title:"entities.ibizsample0021.views.editview.caption", width: 800, height: 500},
        "WFACTION@WFDynaActionView":{viewname:"ibizsample0021-wfdyna-action-view",title:"entities.ibizsample0021.views.wfdynaactionview.caption", width: 800, height: 500},
        "WFUTILACTION@ADDSTEPAFTER":{viewname:"ibizsample0021-addstepafterwfdyna-action-view",title:"entities.ibizsample0021.views.addstepafterwfdynaactionview.caption", width: 800, height: 500},
        "WFUTILACTION@ADDSTEPBEFORE":{viewname:"ibizsample0021-addstepbeforewfdyna-action-view",title:"entities.ibizsample0021.views.addstepbeforewfdynaactionview.caption", width: 800, height: 500},
        "WFUTILACTION@REASSIGN":{viewname:"ibizsample0021-reassignwfdyna-action-view",title:"entities.ibizsample0021.views.reassignwfdynaactionview.caption", width: 800, height: 500},
        "WFUTILACTION@SENDBACK":{viewname:"ibizsample0021-sendbackwfdyna-action-view",title:"entities.ibizsample0021.views.sendbackwfdynaactionview.caption", width: 800, height: 500}
    };

    /**
     * 树导航栏数据
     *
     * @type {any}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public wfStepModel: Array<any> = [];

    /**
     * 是否展开搜索表单
     *
     * @type {any}
     * @memberof  IBIZSample0021WFDynaExpGridViewBase
     */
    public isExpandSearchForm:boolean = true;

    /**
     * 是否单选
     *
     * @type {any}
     * @memberof  IBIZSample0021WFDynaExpGridViewBase
     */
    public isSingleSelect:boolean = false;

    /**
     * 工具栏模型数据
     * 
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public linkModel:Array<any> = [];

    /**
     * 左侧树的默认配置
     *
     * @type {any}
     * @memberof  IBIZSample0021WFDynaExpGridViewBase
     */
    public defaultProps:any ={
         children: 'children',
         label: 'userTaskName'
    };

    /**
     * 左侧树当前选中节点
     *
     * @type {any}
     * @memberof  IBIZSample0021WFDynaExpGridViewBase
     */
    public curSelectedNode:any;

    /**
     * 获取树导航栏数据
     *
     * @memberof  IBIZSample0021WFDynaExpGridViewBase
     */
    public getWFStepModel():Promise<any>{
        return new Promise((resolve:any, reject:any) =>{
            this.appEntityService.WFGetWFStep().then((response:any) =>{
                if (response && response.status === 200) {
                    this.wfStepModel = response.data;
                    if(this.wfStepModel && this.wfStepModel.length > 0){
                        if(!this.curSelectedNode){
                            this.curSelectedNode = this.wfStepModel[0];
                        }else{
                            let tempCopySelectedNode:any = Util.deepCopy(this.curSelectedNode);
                            this.curSelectedNode = this.wfStepModel.find((item:any) =>{
                                return item.userTaskId === tempCopySelectedNode.userTaskId && item.processDefinitionKey === tempCopySelectedNode.processDefinitionKey;
                            })
                        }
                    }
                    if(this.curSelectedNode){
                        Object.assign(this.viewparams,{'userTaskId':this.curSelectedNode['userTaskId'],'processDefinitionKey':this.curSelectedNode['processDefinitionKey']});
                        this.setTreeNodeHighLight(this.curSelectedNode);
                        this.getWFLinkModel({'userTaskId':this.curSelectedNode['userTaskId'],'processDefinitionKey':this.curSelectedNode['processDefinitionKey']});
                    }
                    resolve(response.data);
                }
                }).catch((response: any) => {
                    if (response && response.status) {
                        this.$Notice.error({ title: '错误', desc: response.message });
                        return;
                    }
                    if (!response || !response.status || !response.data) {
                        this.$Notice.error({ title: '错误', desc: '系统异常' });
                        return;
                    }
                });
        })
    }

    /**
     * 获取工具栏按钮
     * 
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public getWFLinkModel(data:any){
        this.appEntityService.getWFLinks(JSON.parse(JSON.stringify(this.context)),data,true).then((response:any) =>{
            if (response && response.status === 200) {
                this.linkModel = response.data;
                if(this.linkModel.length >0){
                    this.linkModel.forEach((item:any) =>{
                        item.disabled = true;
                    })
                }
            }
        }).catch((response: any) => {
            if (response && response.status) {
                this.$Notice.error({ title: '错误', desc: response.message });
                return;
            }
            if (!response || !response.status || !response.data) {
                this.$Notice.error({ title: '错误', desc: '系统异常' });
                return;
            }
        });
    }

    /**
     * 工具栏点击事件
     * 
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public dynamic_toolbar_click(linkItem:any, $event:any){
        let datas: any[] = [];
        let xData: any = this.$refs.grid;
        if (xData.getDatas && xData.getDatas instanceof Function) {
            datas = [...xData.getDatas()];
        }
        const submitBatchData:Function = (submitdata:any,linkItem:any) =>{
            xData.submitbatch(submitdata,linkItem).then((response: any) => {
                if (!response || response.status !== 200) {
                    return;
                }
                const { data: _data } = response;
                this.engine.load();
                if (this.viewdata) {
                    this.$emit('viewdataschange', [{ ..._data }]);
                }
            });
        }
        if(linkItem && linkItem.sequenceflowview && this.viewRefData[`WFACTION@${linkItem.sequenceflowview}`]){
            let tempContext:any = Util.deepCopy(this.context);
            let tempViewParam:any = {actionView:linkItem.sequenceflowview,actionForm:linkItem.sequenceflowform};
            let targetView:any = this.viewRefData[`WFACTION@${linkItem.sequenceflowview}`];
            const appmodal = this.$appmodal.openModal({viewname:targetView.viewname, title:(this.$t(targetView.title) as string), height: targetView.height, width: targetView.width}, tempContext,tempViewParam);
            appmodal.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                let tempSubmitData:any = Util.deepCopy(datas);
                tempSubmitData.forEach((element:any) => {
                    element.viewparams = result.datas && result.datas[0];
                });
                submitBatchData(tempSubmitData,linkItem);
            });
        }else{
            submitBatchData(datas,linkItem);
        }
    }

    /**
     * 左侧树选中节点
     *
     * @type {any}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public handleNodeClick(data:any) {
        this.curSelectedNode = data;
        this.setTreeNodeHighLight(this.curSelectedNode);
        Object.assign(this.viewparams,{'userTaskId':data['userTaskId'],'processDefinitionKey':data['processDefinitionKey']});
        this.getWFLinkModel({'userTaskId':this.curSelectedNode['userTaskId'],'processDefinitionKey':this.curSelectedNode['processDefinitionKey']});
        (this.$refs.searchform as any).onSearch();
    }

    /**
     * 设置选中高亮
     *
     * @param {*} data
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    public setTreeNodeHighLight(data: any): void {
        this.$nextTick(() =>{
            const tree: any = this.$refs.tree;
            if(tree) {
                tree.setCurrentKey(data.userTaskId);
            }
        })
    }

    /**
     * 刷新数据
     *
     * @readonly
     * @type {(number | null)}
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    get refreshdata(): number | null {
        return this.$store.getters['viewaction/getRefreshData'](this.viewtag);
    }

    /**
     * 监控数据变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @returns
     * @memberof IBIZSample0021WFDynaExpGridViewBase
     */
    @Watch('refreshdata')
    onRefreshData(newVal: any, oldVal: any) {
        if (newVal === null || newVal === undefined) {
            return;
        }
        if (newVal === 0) {
            return;
        }
        const grid: any = this.$refs.grid;
        if (grid) {
            grid.load({});
        }
    }


}
</script>

<style lang='less'>
@import './ibizsample0021-wfdyna-exp-grid-view.less';
</style>