mob-edit-view3-engine.ts 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
import { MobEditViewEngine } from './mob-edit-view-engine';

/**
 * 实体移动端编辑视图(分页关系)界面引擎
 *
 * @export
 * @class MobEditView3Engine
 * @extends {MobEditViewEngine}
 */
export class MobEditView3Engine extends MobEditViewEngine {

    /**
     * 数据关系栏
     *
     * @protected
     * @type {*}
     * @memberof MobEditView3Engine
     */
    protected drTab: any;

    /**
     * Creates an instance of MobEditView3Engine.
     * 
     * @memberof MobEditView3Engine
     */
    constructor() {
        super();
    }

    /**
     * 初始化引擎
     *
     * @param {*} [options={}]
     * @memberof MobEditView3Engine
     */
    public init(options: any = {}): void {
        this.drTab = options.drtab;
        super.init(options);
    }

    /**
     * 部件事件机制
     *
     * @param {string} ctrlName
     * @param {string} eventName
     * @param {*} args
     * @memberof MobEditView3Engine
     */
    public onCtrlEvent(ctrlName: string, eventName: string, args: any): void {
        super.onCtrlEvent(ctrlName, eventName, args);
        if (Object.is(ctrlName, 'drtab')) {
            this.drTabEvent(eventName, args);
        }
    }

    /**
     * 数据关系栏事件
     *
     * @param {string} eventName
     * @param {any[]} args
     * @memberof MobEditView3Engine
     */
    public drTabEvent(eventName: string, args: any[]): void {
        if (Object.is(eventName, 'selectionchange')) {
            this.drTabSelectionChange(args);
        }
    }

    /**
     * 数据关系栏选中
     *
     * @param {any[]} args
     * @memberof MobEditView3Engine
     */
    public drTabSelectionChange(data: any): void {
        if (data) {
            if(this.view.drItemCache?.indexOf(data.name) == -1){
                this.view.drItemCache.push(data.name);
            }
            this.view.drItem = data;
            if (this.getDrTab()) {
                this.setViewState2({ tag: this.getDrTab().name, action: 'change', viewdata: data });
            }
            this.view.$forceUpdate();
        }
        this.emitViewEvent('selectionchange', data);
    }

    /**
     * 表单加载完成
     *
     * @param {*} [arg={}]
     * @memberof MobEditView3Engine
     */
    public onFormLoad(arg: any = {}): void {
        super.onFormLoad(arg);
        if (this.getDrTab()) {
            const tag = this.getDrTab().name;
            Object.assign(arg, {
              srfparentdename: this.getForm().appDeCodeName,
              srfparentkey: arg.srfkey,
            });
            this.setViewState2({ tag: tag, action: 'state', viewdata: arg });
        }
    }

    /**
     * 表单保存完成
     *
     * @param {*} [arg={}]
     * @memberof MobEditView3Engine
     */
    public onFormSave(arg: any = {}): void {
        super.onFormSave(arg);
        if (this.getDrTab()) {
            let viewparams = {};
            Object.assign(viewparams, this.view.viewparams)
            const tag = this.getDrTab().name;
            Object.assign(viewparams, arg);
            this.setViewState2({ tag: tag, action: 'save', viewdata: viewparams });
        }
    }

    /**
     * 获取关系
     *
     * @returns {*}
     * @memberof MobEditView3Engine
     */
    public getDrTab(): any {
        return this.drTab;
    }
}