panel-field.ts 2.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
import { PanelDetailModel } from './panel-detail';

/**
 * 面板属性项模型
 *
 * @export
 * @class PanelFieldModel
 * @extends {PanelDetailModel}
 */
export class PanelFieldModel extends PanelDetailModel {

    /**
     * 是否启用
     *
     * @type {boolean}
     * @memberof PanelFieldModel
     */
    public disabled: boolean = false;

    /**
     * 错误信息
     *
     * @type {string}
     * @memberof PanelFieldModel
     */
    public error: string = '';

    /**
     * 表单项启用条件
     * 
     * 0 不启用
     * 1 新建
     * 2 更新
     * 3 全部启用
     *
     * @type {(number | 0 | 1 | 2 | 3)}
     * @memberof PanelFieldModel
     */
    public enableCond: number | 0 | 1 | 2 | 3 = 3;

    /**
     * Creates an instance of PanelFieldModel.
     * PanelFieldModel 实例
     * 
     * @param {*} [opts={}]
     * @memberof PanelFieldModel
     */
    constructor(opts: any = {}) {
        super(opts);
        this.disabled = opts.disabled ? true : false;
        this.enableCond = opts.enableCond;
    }

    /**
     * 设置是否启用
     *
     * @param {boolean} state
     * @memberof PanelFieldModel
     */
    public setDisabled(state: boolean): void {
        this.disabled = state;
    }

    /**
     * 设置信息内容
     *
     * @param {string} error
     * @memberof PanelFieldModel
     */
    public setError(error: string): void {
        this.error = error;
    }

    /**
     * 设置是否启用
     *
     * @param {string} srfuf
     * @memberof PanelFieldModel
     */
    public setEnableCond(srfuf: string): void {
        // 是否有权限
        const isReadOk: boolean = true;
        const _srfuf: number = parseInt(srfuf, 10);
        let state: boolean = true;

        if (isReadOk) {
            if (_srfuf === 1) {
                if ((this.enableCond & 2) === 2) {
                    state = false;
                }
            } else {
                if ((this.enableCond & 1) === 1) {
                    state = false;
                }
            }
        }
        this.setDisabled(state);
    }

}