pickup-view2-engine.ts 4.1 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
import { ViewEngine } from './view-engine';

/**
 * 实体选择视图(左右关系)
 *
 * @export
 * @class PickupView2Engine
 * @extends {ViewEngine}
 */
export class PickupView2Engine extends ViewEngine {

    /**
     * 树导航
     *
     * @type {*}
     * @memberof PickupView2Engine
     */
    private treeExpBar: any = null;

    /**
     * 选择视图面板
     *
     * @private
     * @type {*}
     * @memberof PickupView2Engine
     */
    private pickupViewPanel: any = null;

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

    /**
     * 初始化引擎
     *
     * @param {*} options
     * @memberof PickupView2Engine
     */
    public init(options: any): void {
        this.treeExpBar = options.treeExpBar;
        this.pickupViewPanel = options.pickupviewpanel;
        super.init(options);
    }


    /**
     * 引擎加载
     *
     * @memberof PickupView2Engine
     */
    public load(): void {
        this.view.viewSelections = [];
        super.load();
        if (this.getTreeExpBar()) {
            const tag = this.getTreeExpBar().name;
            this.setViewState2({ tag: tag, action: 'load', viewdata: this.view.viewparams });
        }
    }

    /**
     * 处理部件事件
     *
     * @param {string} ctrlName
     * @param {string} eventName
     * @param {*} args
     * @memberof PickupView2Engine
     */
    public onCtrlEvent(ctrlName: string, eventName: string, args: any): void {
        super.onCtrlEvent(ctrlName, eventName, args);
        const treeExpBar = this.getTreeExpBar();
        if (ctrlName === treeExpBar?.name) {
            this.handleTreeExpBarEvents(eventName, args);
        }
        const panel = this.getPickupViewPanel();
        if (ctrlName === panel?.name) {
            this.handlePickupViewPanelEvents(eventName, args);
        }
    }

    /**
     * 处理树导航栏事件
     *
     * @protected
     * @param {string} eventName 事件名称
     * @param {*} args 参数
     * @memberof PickupView2Engine
     */
    protected handleTreeExpBarEvents(eventName: string, args: any) {
        if (eventName === 'selectionchange') {
            this.view.navItem = args;
            this.view.$forceUpdate();
            this.view.$nextTick(() => {
                if (this.getPickupViewPanel()) {
                    this.setViewState2({ tag: this.getPickupViewPanel().name, action: 'load', viewdata: args?.srfnavdata?.viewparams });
                }
            })
        }
        if (Object.is(eventName, 'activated')) {
            this.emitViewEvent('viewdatasactivated', args);
        }
    }

    /**
     * 处理选择视图面板事件
     *
     * @protected
     * @param {string} eventName 事件名称
     * @param {*} args 参数
     * @memberof PickupView2Engine
     */
    protected handlePickupViewPanelEvents(eventName: string, args: any) {
        if (eventName === 'selectionchange') {
            this.onSelectionChange(args);
        }
    }

    /**
     * 值选中变化
     *
     * @param {any[]} args
     * @memberof PickupView2Engine
     */
    public onSelectionChange(args: any[]): void {
        this.view.viewSelections = [];
        this.view.viewSelections = [...args]
        const _disabled: boolean = this.view.viewSelections.length > 0 ? false : true;
        this.view.viewButtonModel.view_okbtn.disabled = _disabled;
        if(!this.view.isShowButton){
            this.emitViewEvent('viewdataschange', [...args]);
        }
    }

    /**
     * 获取树导航
     *
     * @returns {*}
     * @memberof PickupView2Engine
     */
    public getTreeExpBar(): any {
        return this.treeExpBar;
    }

    /**
     * 获取选择视图面板
     *
     * @return {*}  {*}
     * @memberof PickupView2Engine
     */
    public getPickupViewPanel(): any {
        return this.pickupViewPanel;
    }

    /**
     * @description 视图销毁
     * @memberof PickupView2Engine
     */
    public destroyed() {
        super.destroyed();
        this.pickupViewPanel = null;
        this.treeExpBar = null;
    }
}