
import { Subject } from 'rxjs';
import { GridView9Base } from '@/studio-core';
import HRDutySkillService from '@/service/hrduty-skill/hrduty-skill-service';
import HRDutySkillAuthService from '@/authservice/hrduty-skill/hrduty-skill-auth-service';
import GridView9Engine from '@engine/view/grid-view9-engine';
import HRDutySkillUIService from '@/uiservice/hrduty-skill/hrduty-skill-ui-service';
import CodeListService from "@service/app/codelist-service";


/**
 * 职务技能嵌入职务视图基类
 *
 * @export
 * @class HRDutySkillV_002Base
 * @extends {GridView9Base}
 */
export class HRDutySkillV_002Base extends GridView9Base {
    /**
     * 视图对应应用实体名称
     *
     * @protected
     * @type {string}
     * @memberof HRDutySkillV_002Base
     */
    protected appDeName: string = 'hrdutyskill';

    /**
     * 应用实体主键
     *
     * @protected
     * @type {string}
     * @memberof HRDutySkillV_002Base
     */
    protected appDeKey: string = 'hrdutyskillid';

    /**
     * 应用实体主信息
     *
     * @protected
     * @type {string}
     * @memberof HRDutySkillV_002Base
     */
    protected appDeMajor: string = 'hrdutyskillname';

    /**
     * 实体服务对象
     *
     * @type {HRDutySkillService}
     * @memberof HRDutySkillV_002Base
     */
    protected appEntityService: HRDutySkillService = new HRDutySkillService;

    /**
     * 实体权限服务对象
     *
     * @type HRDutySkillUIService
     * @memberof HRDutySkillV_002Base
     */
    public appUIService: HRDutySkillUIService = new HRDutySkillUIService(this.$store);


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

    /**
     * 视图模型数据
     *
     * @protected
     * @type {*}
     * @memberof HRDutySkillV_002Base
     */
    protected model: any = {
        srfCaption: 'entities.hrdutyskill.views.v_002.caption',
        srfTitle: 'entities.hrdutyskill.views.v_002.title',
        srfSubTitle: 'entities.hrdutyskill.views.v_002.subtitle',
        dataInfo: ''
    }

    /**
     * 容器模型
     *
     * @protected
     * @type {*}
     * @memberof HRDutySkillV_002Base
     */
    protected containerModel: any = {
        view_grid: { name: 'grid', type: 'GRID' },
    };


	/**
     * 视图唯一标识
     *
     * @protected
     * @type {string}
     * @memberof ViewBase
     */
	protected viewtag: string = '6d4cab857af2830b37515c2015a40e5f';


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

    /**
     * 引擎初始化
     *
     * @public
     * @memberof HRDutySkillV_002Base
     */
    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);
            },
            newdata: (args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any) => {
                this.newdata(args,fullargs, params, $event, xData);
            },
            grid: this.$refs.grid,
            keyPSDEField: 'hrdutyskill',
            majorPSDEField: 'hrdutyskillname',
            isLoadDefault: true,
        });
    }

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

    /**
     * grid 部件 beforeload 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof HRDutySkillV_002Base
     */
    public grid_beforeload($event: any, $event2?: any): void {
        this.engine.onCtrlEvent('grid', 'beforeload', $event);
    }

    /**
     * grid 部件 rowdblclick 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof HRDutySkillV_002Base
     */
    public grid_rowdblclick($event: any, $event2?: any): void {
        this.engine.onCtrlEvent('grid', 'rowdblclick', $event);
    }

    /**
     * grid 部件 remove 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof HRDutySkillV_002Base
     */
    public grid_remove($event: any, $event2?: any): void {
        this.engine.onCtrlEvent('grid', 'remove', $event);
    }

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

    /**
     * 打开新建数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof HRDutySkillV_002
     */
    public newdata(args: any[],fullargs?:any[], params?: any, $event?: any, xData?: any) {
        let localContext:any = null;
        let localViewParam:any =null;
        const data: any = {};
        if(args[0].srfsourcekey){
            data.srfsourcekey = args[0].srfsourcekey;
        }
        let tempContext = JSON.parse(JSON.stringify(this.context));
        delete tempContext.hrdutyskill;
        if(args.length >0){
            Object.assign(tempContext,args[0]);
        }
        let deResParameters: any[] = [];
        if(tempContext.hrduty && true){
            deResParameters = [
            { pathName: 'hrduties', parameterName: 'hrduty' },
            ]
        }
        const parameters: any[] = [
            { pathName: 'hrdutyskills', parameterName: 'hrdutyskill' },
        ];
        const _this: any = this;
        const openDrawer = (view: any, data: any) => {
            let container: Subject<any> = this.$appdrawer.openDrawer(view, tempContext, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: 'hrduty-skill-v-001', 
            height: 0, 
            width: 600,  
            title: this.$t('entities.hrdutyskill.views.v_001.title'),
            placement: 'DRAWER_RIGHT',
        };
        openDrawer(view, data);
    }


    /**
     * 打开编辑数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof HRDutySkillV_002
     */
    public opendata(args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any) {
        const localContext: any = null;
        const localViewParam: any =null;
        const data: any = {};
        let tempContext = JSON.parse(JSON.stringify(this.context));
        if(args.length >0){
            Object.assign(tempContext,args[0]);
        }
        let deResParameters: any[] = [];
        if(tempContext.hrduty && true){
            deResParameters = [
            { pathName: 'hrduties', parameterName: 'hrduty' },
            ]
        }
        const parameters: any[] = [
            { pathName: 'hrdutyskills', parameterName: 'hrdutyskill' },
        ];
        const _this: any = this;
        const openDrawer = (view: any, data: any) => {
            let container: Subject<any> = this.$appdrawer.openDrawer(view, tempContext, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: 'hrduty-skill-v-001', 
            height: 0, 
            width: 600,  
            title: this.$t('entities.hrdutyskill.views.v_001.title'),
            placement: 'DRAWER_RIGHT',
        };
        openDrawer(view, data);
    }



    /**
     * 表格行数据默认激活模式
     * 0 不激活
     * 1 单击激活
     * 2 双击激活
     *
     * @protected
     * @type {(0 | 1 | 2)}
     * @memberof HRDutySkillV_002Base
     */
    protected gridRowActiveMode: 0 | 1 | 2 = 0;
}