ibiz-mpickup-view-controller.ts 4.7 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 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 168 169 170 171
/**
 * 多项数据选择视图控制器
 *
 * @class IBizMPickupViewController
 * @extends {IBizMainViewController}
 */
class IBizMPickupViewController extends IBizMainViewController {

    /**
     * 按钮文本--确定
     *
     * @type {string}
     * @memberof IBizMPickupViewController
     */
    public okBtnText: string = '确定';

    /**
     * 按钮文本--取消
     *
     * @type {string}
     * @memberof IBizMPickupViewController
     */
    public cancelBtnText: string = '取消';

    /**
     * 是否是iframe嵌入视图
     *
     * @type {boolean}
     * @memberof IBizMPickupViewController
     */
    public srfembed: boolean = false;

    /**
     * 父视图id
     *
     * @type {string}
     * @memberof IBizMPickupViewController
     */
    public parentOpenerid: string = '';

    /**
     * 多项选择数据集服务对象
     * 
     * @type {IBizMPickupResult}
     * @memberof IBizMPickupViewController
     */
    public MPickupResult: IBizMPickupResult = null;

    /**
     * Creates an instance of IBizMPickupViewController.
     * 创建 IBizMPickupViewController 实例
     * 
     * @param {*} [opts={}] 
     * @memberof IBizMPickupViewController
     */
    constructor(opts: any = {}) {
        super(opts);

        this.MPickupResult = new IBizMPickupResult({
            name: 'mpickupresult',
            viewController: this,
            url: opts.url,
        });
        this.regControl('mpickupresult', this.MPickupResult);
    }

    /**
     * 视图部件初始化
     *
     * @memberof IBizMPickupViewController
     */
    public onInitComponents(): void {
        super.onInitComponents();
        const pickupViewPanel = this.getPickupViewPanel();
        if (pickupViewPanel && this.MPickupResult) {
            // 选择视图面板数据选中
            pickupViewPanel.on(IBizPickupViewPanel.SELECTIONCHANGE).subscribe((args) => {
                this.MPickupResult.setCurSelections(args);
            });
            // 选择视图面板数据激活
            pickupViewPanel.on(IBizPickupViewPanel.DATAACTIVATED).subscribe((args) => {
                this.MPickupResult.appendDatas(args);
            });
            // 选择视图面板所有数据
            pickupViewPanel.on(IBizPickupViewPanel.ALLDATA).subscribe((args) => {
                this.MPickupResult.setAllData(args);
            });
        }
    }

    /**
     * 准备视图参数
     *
     * @memberof IBizMPickupViewController
     */
    public parseViewParams(): void {
        super.parseViewParams();

        let viewparams: any = this.getViewParam();
        if (viewparams.hasOwnProperty('srfembed')) {
            this.srfembed = Object.is(viewparams.srfembed, 'true') ? true : false;
        }
        if (viewparams.hasOwnProperty('openerid')) {
            this.parentOpenerid = viewparams.openerid;
        }
    }

    /**
     * 处理视图参数
     * 
     * @memberof IBizMPickupViewController
     */
    public onInit(): void {
        super.onInit();
        if (this.getViewParam() && Array.isArray(this.getViewParam().selectedData)) {
            if (this.MPickupResult) {
                this.MPickupResult.appendDatas(this.getViewParam().selectedData);
            }
        }
    }

    /**
     * 数据选择,确定功能
     *
     * @returns {void}
     * @memberof IBizMPickupViewController
     */
    public onClickOkButton(): void {

        if (this.MPickupResult.selections.length === 0) {
            return;
        }
        // this.nzModalSubject.next({ ret: 'OK', selection: this.MPickupResult.selections });
        // this.nzModalSubject.next('DATACHANGE');
        // this.closeWindow();
        if (this.srfembed && window && window.parent && !Object.is(this.parentOpenerid, '')) {
            let win = window;
            win.parent.postMessage({ ret: 'OK', type: 'SETSELECTIONS', selections: this.MPickupResult.selections, openerid: this.parentOpenerid }, '*');
            return;
        }
        this.closeModal({ ret: 'OK', selections: this.MPickupResult.selections });
    }


    /**
     * 关闭显示选择视图
     * 
     * @param {*} type 
     * @memberof IBizMPickupViewController
     */
    public onClickCancelButton(type: any): void {
        // this.nzModalSubject.destroy(type);
        if (this.srfembed && window && window.parent && !Object.is(this.parentOpenerid, '')) {
            let win = window;
            win.parent.postMessage({ ret: 'OK', type: 'SETSELECTIONS', selections: null, openerid: this.parentOpenerid }, '*');
            return;
        }
        this.closeModal();
    }

    /**
     * 获取选中视图面板
     *
     * @returns {*}
     * @memberof IBizMPickupViewController
     */
    public getPickupViewPanel(): any {
        return this.getControl('pickupviewpanel');
    }
}