mpickupview-base.tsx 10.5 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
import { IPSAppDEPickupView, IPSDEPickupViewPanel } from '@ibiz/dynamic-model-api';
import { MPickupViewEngine, ModelTool, throttle, MPickUpViewInterface, Util } from 'ibiz-core';
import { MainViewBase } from './mainview-base';

/**
 * 数据多项选择视图基类
 *
 * @export
 * @class MPickUpViewBase
 * @extends {MainViewBase}
 * @implements {MPickUpViewInterface}
 */
export class MPickUpViewBase extends MainViewBase implements MPickUpViewInterface {

    /**
     * 视图实例
     * 
     * @memberof MPickUpViewBase
     */
    public declare viewInstance: IPSAppDEPickupView;

    /**
     * 引擎对象
     *
     * @type {MPickupViewEngine}
     * @memberof MPickUpViewBase
     */
    public declare engine: MPickupViewEngine;

    /**
     * 选择视图面板实例
     * 
     * @memberof MPickUpViewBase
     */
    public pickUpViewPanelInstance!: IPSDEPickupViewPanel;

    /**
     * 是否显示按钮
     *
     * @type {boolean}
     * @memberof MPickUpViewBase
     */
    public isShowButton: boolean = true;

    /**
     * 选中数据的字符串
     *
     * @type {string}
     * @memberof MPickUpViewBase
     */
    public selectedData: string = "";

    /**
     * 视图选中数据
     *
     * @type {any[]}
     * @memberof MPickUpViewBase
     */
    public viewSelections: any[] = [];

    /**
     * 部件模型
     *
     * @type {*}
     * @memberof MPickUpViewBase
     */
    public ctrlModel: any = {};

    /**
     * 监听部件动态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof MPickUpViewBase
     */
    public onDynamicPropsChange(newVal: any, oldVal: any) {
        super.onDynamicPropsChange(newVal, oldVal);
        if (this.viewparams?.selectedData) {
            this.selectedData = JSON.stringify(this.viewparams.selectedData);
            this.viewSelections = this.viewparams.selectedData;
        }
    }

    /**
     * 监听部件静态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof MPickUpViewBase
     */
    public onStaticPropsChange(newVal: any, oldVal: any) {
        this.isShowButton = newVal?.isShowButton !== false;
        super.onStaticPropsChange(newVal, oldVal);
    }

    /**
     * 引擎初始化
     *
     * @public
     * @memberof MPickUpViewBase
     */
    public engineInit(): void {
        if (this.Environment && this.Environment.isPreviewMode) {
            return;
        }
        let engineOpts = ({
            view: this,
            p2k: '0',
            pickupViewPanel: (this.$refs[this.pickUpViewPanelInstance?.name] as any).ctrl,
            keyPSDEField: this.appDeCodeName.toLowerCase(),
            majorPSDEField: this.appDeMajorFieldName.toLowerCase(),
        });
        this.engine.init(engineOpts);
    }

    /**
     * 初始化分页导航视图实例
     * 
     * @memberof MPickUpViewBase
     */
    public async viewModelInit() {
        this.viewInstance = (this.staticProps?.modeldata) as IPSAppDEPickupView;
        await super.viewModelInit();
        this.pickUpViewPanelInstance = ModelTool.findPSControlByType("PICKUPVIEWPANEL", this.viewInstance.getPSControls());
    }

    /**
     * 初始化容器模型
     *
     * @param {*} opts
     * @memberof MPickUpViewBase
     */
    public initContainerModel(opts: any) {
        super.initContainerModel(opts);
        const { modeldata } = opts;
        modeldata?.getPSControls().forEach((ctrl: any) => {
            this.ctrlModel[ctrl.name] = { name: `${ctrl.name}`, type: `${ctrl.controlType}` };
        });
    }

    /**
     * 删除右侧全部选中数据
     *
     * @memberof MPickUpViewBase
     */
    public onCLickLeft(): void {
        if (this.engine) {
            this.engine.toLeft();
        }
    }

    /**
     * 添加左侧选中数据
     *
     * @memberof MPickUpViewBase
     */
    public onCLickRight(): void {
        if (this.engine) {
            this.engine.toRight();
        }
    }

    /**
     * 选中数据全部删除
     *
     * @memberof MPickUpViewBase
     */
    public onCLickAllLeft(): void {
        if (this.Environment && this.Environment.isPreviewMode) {
            return;
        }
        if (this.engine) {
            this.engine.toAllLeft();
        }
    }

    /**
     * 添加左侧面板所有数据到右侧
     *
     * @memberof MPickUpViewBase
     */
    public onCLickAllRight(): void {
        if (this.Environment && this.Environment.isPreviewMode) {
            return;
        }
        if (this.engine) {
            this.engine.toAllRight();
        }
    }

    /**
     * 确定
     *
     * @memberof MPickUpViewBase
     */
    public onClickOk(): void {
        if (this.engine) {
            this.engine.ok(this.viewSelections);
        }
    }

    /**
     * 取消
     *
     * @memberof MPickUpViewBase
     */
    public onClickCancel(): void {
        if (this.engine) {
            this.engine.cancel();
        }
    }

    /**
     * 渲染视图主体内容区
     * 
     * @memberof MPickUpViewBase
     */
    public renderMainContent() {
        return (
            <div class="view-content__body__transfer">
                <div class="view-content__body__transfer__left" style={{ width: !this.isShowButton ? '100%' : '' }}>
                    {this.renderControlContent()}
                </div>
                {this.isShowButton && <div class="view-content__body__transfer__center">
                    {this.renderButtons()}
                </div>}
                {this.isShowButton && <div class="view-content__body__transfer__right">
                    {this.renderMpickerSelect()}
                </div>}
            </div>
        )
    }

    /**
     *  渲染视图底部按钮
     * @memberof MPickUpViewBase
     */
    public renderFooter() {
        return (
            this.isShowButton ? <div slot="footer" class="view-footer__buttons">
                <app-button
                    type="primary"
                    disabled={this.viewSelections.length > 0 ? false : true}
                    caption={this.viewButtonModel?.view_okbtn?.text}
                    on-onClick={(e: any) => throttle(this.onClickOk, e, this)}>
                </app-button>
                &nbsp;&nbsp;
                <app-button
                    caption={this.viewButtonModel?.view_cancelbtn?.text}
                    on-onClick={(e: any) => throttle(this.onClickCancel,e,this)}>
                </app-button>
            </div> : null
        )
    }

    /**
     * 渲染按钮
     * 
     * @memberof MPickUpViewBase
     */
    public renderButtons() {
        return [
            <app-button
                type="primary"
                tooltip={this.viewButtonModel?.view_rightbtn.text}
                disabled={this.viewButtonModel?.view_rightbtn.disabled}
                iconcls="el-icon-arrow-right"
                on-onClick={(e: any) => throttle(this.onCLickRight, e, this)}>
            </app-button>,
            <app-button
                type="primary"
                tooltip={this.viewButtonModel?.view_leftbtn.text}
                disabled={this.viewButtonModel?.view_leftbtn.disabled}
                iconcls="el-icon-arrow-left"
                on-onClick={(e: any) => throttle(this.onCLickLeft, e, this)}>
            </app-button>,
            <app-button
                type="primary"
                tooltip={this.viewButtonModel?.view_allrightbtn.text}
                disabled={this.viewButtonModel?.view_allrightbtn.disabled}
                iconcls="el-icon-d-arrow-right"
                on-onClick={(e: any) => throttle(this.onCLickAllRight, e, this)}>
            </app-button>,
            <app-button
                type="primary"
                tooltip={this.viewButtonModel?.view_allleftbtn.text}
                disabled={this.viewButtonModel?.view_allleftbtn.disabled}
                iconcls="el-icon-d-arrow-left"
                on-onClick={(e: any) => throttle(this.onCLickAllLeft, e, this)}>
            </app-button>
        ]
    }

    /**
     * 渲染多数据选择
     * 
     * @memberof MPickUpViewBase
     */
    public renderMpickerSelect() {
        return <div class="view-content__body__transfer__right__select">
            {this.viewSelections.map((item: any, index: number) => {
                return <div key={index} class={{ 'is-active': item._select, 'picker-item': true }} on-click={() => throttle(this.selectionsClick, [item], this)} on-dblclick={() => throttle(this.selectionsDBLClick, [item], this)}>
                    <span>{item.srfmajortext}</span>
                </div>
            })}
        </div>
    }

    /**
     * 渲染选择视图面板
     * 
     * @memberof MPickUpViewBase
     */
    public renderControlContent() {
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.pickUpViewPanelInstance);
        return this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: this.pickUpViewPanelInstance?.name, on: targetCtrlEvent });
    }

    /**
     * 计算目标部件所需参数
     *
     * @param {string} [controlType]
     * @returns
     * @memberof MPickUpViewBase
     */
    public computeTargetCtrlData(controlInstance: any, args?: any) {
        const { targetCtrlName, targetCtrlParam, targetCtrlEvent } = super.computeTargetCtrlData(controlInstance, args);
        Object.assign(targetCtrlParam.dynamicProps, {
            selectedData: this.selectedData,
        })
        Object.assign(targetCtrlParam.staticProps, {
            isSingleSelect: false,
            isShowButton: this.isShowButton,
        })
        return { targetCtrlName, targetCtrlParam, targetCtrlEvent }
    }

    /**
     * 选中数据单击
     *
     * @param {*} item
     * @memberof MPickUpViewBase
     */
    public selectionsClick(item: any): void {
        item._select = !item._select;
        const removeSelect: boolean = this.viewSelections.some((selection: any) => selection._select);
        this.viewButtonModel.view_leftbtn.disabled = !removeSelect;
    }

    /**
     * 选中树双击
     *
     * @param {*} item
     * @memberof MPickUpViewBase
     */
    public selectionsDBLClick(item: any): void {
        const index: number = this.viewSelections.findIndex((selection: any) => Object.is(selection.srfkey, item.srfkey));
        if (index !== -1) {
            this.viewSelections.splice(index, 1);
        }
        const removeSelect: boolean = this.viewSelections.some((selection: any) => selection._select);
        this.viewButtonModel.view_leftbtn.disabled = !removeSelect;
        this.selectedData = JSON.stringify(this.viewSelections);
    }

}