form-tab-panel.ts 2.0 KB
Newer Older
ibizdev's avatar
ibizdev committed
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
import { FormDetailModel } from './form-detail';

/**
 * 分页部件模型
 *
 * @export
 * @class FormTabPanelModel
 * @extends {FormDetailModel}
 */
export class FormTabPanelModel extends FormDetailModel {

    /**
     * 被激活分页
     *
     * @type {string}
     * @memberof FormTabPanelModel
     */
    public activiedPage: string = '';

    /**
     * 选中激活状态
     *
     * @type {string}
     * @memberof FormTabPanelModel
     */
    public clickActiviePage: string = '';

    /**
     * 分页子成员
     *
     * @type {any[]}
     * @memberof FormTabPanelModel
     */
    public tabPages: any[] = [];

    /**
     * Creates an instance of FormTabPanelModel.
     * FormTabPanelModel 实例
     * 
     * @param {*} [opts={}]
     * @memberof FormTabPanelModel
     */
    constructor(opts: any = {}) {
        super(opts);
        this.tabPages = [...opts.tabPages];
        if (this.tabPages.length > 0) {
            this.activiedPage = this.tabPages[0].name;
        }
    }

    /**
     * 设置激活分页
     *
     * @memberof FormTabPanelModel
     */
    public setActiviePage(): void {
        if (!this.form) {
            return;
        }
        const detailsModel: any = this.form.detailsModel;

        const index = this.tabPages.findIndex((tabpage: any) => Object.is(tabpage.name, this.clickActiviePage) && Object.is(tabpage.name, this.activiedPage) && detailsModel[tabpage.name].visible);
        if (index !== - 1) {
            return;
        }

        this.tabPages.some((tabpage: any) => {
            if (detailsModel[tabpage.name].visible) {
                this.activiedPage = tabpage.name;
                return true;
            }
            return false;
        });
    }

    /**
     * 选中页面
     *
     * @param {*} $event
     * @returns {void}
     * @memberof FormTabPanelModel
     */
    public clickPage($event: any): void {
        if (!$event) {
            return;
        }

        this.clickActiviePage = $event;
        this.activiedPage = $event;
    }
}