CONTROL.tsx.ftl 29.4 KB
Newer Older
yanshaowei's avatar
yanshaowei 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 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
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER.tsx.ftl
</#ibizinclude>

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getDatas(): any[] {
        return this.selections;
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getData(): any {
        return this.selections[0];
    }

    /**
     * 传入url值
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    private url: string = '<#ibizinclude>../@MACRO/CONTROL/URL.tsx.ftl</#ibizinclude>';

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop({ default: true }) public showBusyIndicator?: boolean;
    
    /**
     * 部件行为--加载结果集
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public searchAction!: string;

    /**
     * 部件行为--默认数据
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public loaddraftAction?: string;
    
    /**
     * 部件行为--新建
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public createAction?: string;

    /**
     * 部件行为--加载
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public loadAction?: string;

    /**
     * 部件行为--更新
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public updateAction?: string;
    
    /**
     * 部件行为--删除
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public removeAction?: string;

    /**
     * 部件行为--批量添加
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public addBatchAction?: string;

    /**
     * 当前页
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public curPage: number = 1;

    /**
     * 数据
     *
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public items: any[] = [];

    /**
     * 是否支持分页
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public isEnablePagingBar: boolean = ${ctrl.isEnablePagingBar()?c};

    /**
     * 是否禁用排序
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public isNoSort: boolean = ${ctrl.isNoSort()?c};

    /**
     * 排序方向
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public minorSortDir: string = '<#if ctrl.getMinorSortDir()??>${ctrl.getMinorSortDir()}</#if>';

    /**
     * 排序字段
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public minorSortPSDEF: string = '<#if ctrl.getMinorSortPSDEF()??>${ctrl.getMinorSortPSDEF().getCodeName()?lower_case}</#if>';

    /**
     * 分页条数
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public limit: number = ${ctrl.getPagingSize()?c};

    /**
     * 是否显示标题
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public isHideHeader: boolean = ${ctrl.isHideHeader()?c};

    /**
     * 是否单选
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public isSingleSelect?: boolean;

    /**
     * 总条数
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public totalrow: number = 0;

    /**
     * 选中行数据
     *
     * @type {any[]}
     * @memberof Main
     */
    public selections: any[] = [];

    /**
     * 是否开启行编辑
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public isOpenEdit: boolean = false;

    /**
     * 拦截行选中
     *
     * @type {boolean}
     * @memberof Main
     */
    public stopRowClick: boolean = false;

    /**
     * 部件刷新
     *
     * @param {any[]} args
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public refresh(args: any[]): void {
        this.load();
    }

	/**
	 * 选项框列宽
	 *
	 * @type {number}
	 * @memberof AppIndex
	 */
	public checkboxColWidth: number = <#if app.getPSApplicationUI()??>${app.getPSApplicationUI().getPFStyleParam('EL-TABLE.CHECKCOLWIDTH',55)}<#else>55</#if>;

    /**
     * 是否允许拖动列宽
     *
     * @type {boolean}
     * @memberof AppEmbedPicker
     */
    public isDragendCol: boolean = <#if app.getPSApplicationUI()??>${app.getPSApplicationUI().getPFStyleParam('EL-TABLE.ISDRAGENDCOL',false)?c}<#else>false</#if>;

    /**
     * 所有列成员
     *
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public allColumns: any[] = [
        <#if ctrl.getAllPSDEGridColumns()??>
        <#list ctrl.getAllPSDEGridColumns() as column>
        {
            name: '${column.getName()?lower_case}',
            label: '${column.getCaption()}',
            langtag: '<#if langbase??>${langbase}.columns.${column.getName()?lower_case}</#if>',
            show: <#if column.isHideDefault()>false<#else>true</#if>,
            util: '${column.getWidthUnit()}'
        },
        </#list>
        </#if>
    ]

    /**
     * 表格数据加载
     *
     * @param {*} [arg={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public load(opt: any = {}): void {
        const arg: any = {...opt};

        const page: any = {};
        if (this.isEnablePagingBar) {
            Object.assign(page, { current: this.curPage, size: this.limit });
        }
        if (!this.isNoSort && !Object.is(this.minorSortDir, '') && !Object.is(this.minorSortPSDEF, '')) {
            const sort: string[] = [this.minorSortPSDEF];
            if (Object.is(this.minorSortDir, 'ASC')) {
                Object.assign(page, { asc: sort });
            } else {
                Object.assign(page, { desc: sort });
            }
        }
        Object.assign(arg, { page: page });

        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);

        this.serialNumber++;
        const serialnumber = this.serialNumber;
        this.addSerialNumber(this.searchAction, serialnumber);

        const post: Promise<any> = this.$http.post(this.url + this.searchAction, arg, this.showBusyIndicator, serialnumber);
        post.then((response: any) => {
            const { serialnumber: _serialnumber } = response;
            const lastserialnumber = this.getSerialNumber(this.searchAction);
            if (_serialnumber && lastserialnumber && _serialnumber < lastserialnumber) {
                return;
            }

            if (!response.status || response.status !== 200) {
                if (response.errorMessage) {
                    this.$Notice.error({ title: '错误', desc: response.errorMessage });
                }
                return;
            }
            const data: any = response.data;
            if (Object.keys(data).length > 0) {
                this.items = JSON.parse(JSON.stringify(data.records));
                this.totalrow = data.total;
            }
            this.$emit('load', this.items);
        }).catch((response: any) => {
            const { serialnumber: _serialnumber } = response;
            const lastserialnumber = this.getSerialNumber(this.searchAction);
            if (_serialnumber && lastserialnumber && _serialnumber < lastserialnumber) {
                return;
            }

            if (response && response.status === 401) {
                return;
            }
308 309 310 311 312 313 314 315

            if (!response || !response.status || !response.data) {
                this.$Notice.error({ title: '错误', desc: '系统异常' });
                return;
            }

            const { data: _data } = response;
            this.$Notice.error({ title: _data.title, desc: _data.message });
yanshaowei's avatar
yanshaowei committed
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 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
        });
    }

    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public async remove(datas: any[]): Promise<any> {
        if (datas.length === 0) {
            return;
        }
        let dataInfo = '';
        datas.forEach((record: any, index: number) => {
            let srfmajortext = record.srfmajortext;
            if (index < 5) {
                if (!Object.is(dataInfo, '')) {
                    dataInfo += '、';
                }
                dataInfo += srfmajortext;
            } else {
                return false;
            }
        });

        if (datas.length < 5) {
            dataInfo = dataInfo + '共' + datas.length + '条数据';
        } else {
            dataInfo = dataInfo + '...' + '共' + datas.length + '条数据';
        }

        const removeData = () => {
            let keys: any[] = [];
            datas.forEach((data: any) => {
                keys.push(data.srfkey);
            });

            this.serialNumber++;
            const serialnumber = this.serialNumber;
            this.addSerialNumber(this.removeAction, serialnumber);

            const post: Promise<any> = this.$http.post(this.url + this.removeAction, { srfkeys: keys.join(';') }, this.showBusyIndicator, serialnumber);
            return new Promise((resolve: any, reject: any) => {
                post.then((response: any) => {
                    const { serialnumber: _serialnumber } = response;
                    const lastserialnumber = this.getSerialNumber(this.removeAction);
                    if (_serialnumber && lastserialnumber && _serialnumber < lastserialnumber) {
                        return;
                    }

                    if (!response || response.status !== 200) {
                        this.$Notice.error({ title: '', desc: '删除数据失败,' + response.info });
                        return;
                    } else {
                        this.$Notice.success({ title: '', desc: '删除成功!' });
                    }
                    this.load({});
                    this.$emit('remove', null);
                    this.selections = [];
                    resolve(response);
                }).catch((response: any) => {
                    const { serialnumber: _serialnumber } = response;
                    const lastserialnumber = this.getSerialNumber(this.removeAction);
                    if (_serialnumber && lastserialnumber && _serialnumber < lastserialnumber) {
                        return;
                    }

                    if (response && response.status === 401) {
                        return;
                    }
                    if (!response || !response.status || !response.data) {
                        this.$Notice.error({ title: '错误', desc: '系统异常' });
                        reject(response);
                        return;
                    }

                    const { data: _data } = response;
                    this.$Notice.error({ title: _data.title, desc: _data.message });
                    reject(response);
                });
            });
        }

        dataInfo = dataInfo.replace(/[null]/g, '').replace(/[undefined]/g, '').replace(/[ ]/g, '');
        this.$Modal.confirm({
            title: '警告',
            content: '确认要删除 ' + dataInfo + ',删除操作将不可恢复?',
            onOk: () => {
                removeData();
            },
            onCancel: () => { }
        });
        return removeData;
    }


    /**
     * 批量添加
     *
     * @param {*} [arg={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public addBatch(arg: any = {}): void {
        if(!arg) 
            arg = {};
        const post: Promise<any> = this.$http.post(this.url + this.addBatchAction, arg, this.showBusyIndicator);
        post.then((response: any) => {
            if (response.ret !== 200) {
                this.$Notice.error({ title: '', desc: '批量添加失败,' + response.info });
                return;
            }
            this.load({});
            this.$emit('addbatch', null);
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
            this.$Notice.error({ title: '', desc: '批量添加失败' });
        });
    }

    /**
     * 数据导出
     *
     * @param {*} data
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public exportExcel(data: any = {}): void {
        const arg: any = {};

        const page: any = {};
        if (!this.isNoSort && !Object.is(this.minorSortDir, '') && !Object.is(this.minorSortPSDEF, '')) {
            const sort: string[] = [this.minorSortPSDEF];
            if (Object.is(this.minorSortDir, 'ASC')) {
                Object.assign(page, { asc: sort });
            } else {
                Object.assign(page, { desc: sort });
            }
        }

        if (Object.is(data.type, 'maxRowCount')) {
            Object.assign(page, { current: 1, size: data.maxRowCount });
        } else if (Object.is(data.type, 'activatedPage')) {
            Object.assign(page, { current: this.curPage, size: this.limit });
        }
        Object.assign(arg, { page: page });

        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);

        this.serialNumber++;
        const serialnumber = this.serialNumber;
        this.addSerialNumber('exportdata', serialnumber);

        const post: Promise<any> = this.$http.post(this.url + 'exportdata/' + this.searchAction, arg, this.showBusyIndicator, serialnumber);
        post.then((response: any) => {
            const { serialnumber: _serialnumber } = response;
            const lastserialnumber = this.getSerialNumber('exportdata');
            if (_serialnumber && lastserialnumber && _serialnumber < lastserialnumber) {
                return;
            }

            if (!response || response.status !== 200) {
                this.$Notice.error({ title: '', desc: '数据导出失败,' + response.info });
                return;
            }
            const { data: _data } = response;
            const { records: _records } = _data;
            if (!_records || _records.length !== 1) {
                return;
            }

            const { downloadurl: _downloadurl } = _records[0];
            window.open('../' + _downloadurl, '_blank');

        }).catch((response: any) => {
            const { serialnumber: _serialnumber } = response;
            const lastserialnumber = this.getSerialNumber('exportdata');
            if (_serialnumber && lastserialnumber && _serialnumber < lastserialnumber) {
                return;
            }

            if (response && response.status === 401) {
                return;
            }
504 505 506 507 508 509 510
            if (!response || !response.status || !response.data) {
                this.$Notice.error({ title: '错误', desc: '系统异常' });
                return;
            }

            const { data: _data } = response;
            this.$Notice.error({ title: _data.title, desc: _data.message });
yanshaowei's avatar
yanshaowei committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
        });
    }

    /**
     * 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public created(): void {
        this.setColState();
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('load', action)) {
                    this.load(data);
                }
                if (Object.is('remove', action)) {
                    this.load(data);
                }
            });
        }
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public destroyed() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

    /**
     * 获取选中行胡数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getSelection(): any[] {
        return this.selections;
    }

    /**
     * 行双击事件
     *
     * @param {*} $event
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public rowDBLClick($event: any): void {
        if (!$event) {
            return;
        }
        this.selections = [];
        this.selections.push(JSON.parse(JSON.stringify($event)));

        const refs: any = this.$refs;
        if (refs.multipleTable) {
            refs.multipleTable.clearSelection();
            refs.multipleTable.toggleRowSelection($event);
        }

        this.$emit('rowdblclick', this.selections);
        this.$emit('selectionchange', this.selections);
    }

    /**
     * 复选框数据选中
     *
     * @param {*} $event
     * @returns {void}
     * @memberof  ${srfclassname('${ctrl.codeName}')}
     */
    public select($event: any): void {
        if (!$event) {
            return;
        }
        this.selections = [];
        this.selections = [...JSON.parse(JSON.stringify($event))];
        this.$emit('selectionchange', this.selections);
    }

    /**
     * 复选框数据全部选中
     *
     * @param {*} $event
     * @memberof  ${srfclassname('${ctrl.codeName}')}
     */
    public selectAll($event: any): void {
        if (!$event) {
            return;
        }
        this.selections = [];
        this.selections = [...JSON.parse(JSON.stringify($event))];
        this.$emit('selectionchange', this.selections);
    }

    
    /**
     * 行单击选中
     *
     * @param {*} $event
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public rowClick($event: any): void {
        if (!$event) {
            return;
        }
        if(this.stopRowClick) {
            this.stopRowClick = false;
            return;
        }

        this.selections = [];
        this.selections.push(JSON.parse(JSON.stringify($event)));

        const refs: any = this.$refs;
        if (refs.multipleTable) {
            refs.multipleTable.clearSelection();
            refs.multipleTable.toggleRowSelection($event);
        }

        this.$emit('selectionchange', this.selections);
    }


    /**
     * 页面变化
     *
     * @param {*} $event
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public pageOnChange($event: any): void {
        if (!$event) {
            return;
        }
        if ($event === this.curPage) {
            return;
        }
        this.curPage = $event;
        this.load({});
    }

    /**
     * 分页条数变化
     *
     * @param {*} $event
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public onPageSizeChange($event: any): void {
        if (!$event) {
            return;
        }
        if ($event === this.limit) {
            return;
        }
        this.limit = $event;
        if (this.curPage === 1) {
            this.load({});
        }
    }

    /**
     * 分页刷新
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public pageRefresh(): void {
        this.load({});
    }

    /**
     * 排序变化
     *
     * @param {{ column: any, prop: any, order: any }} { column, prop, order }
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public onSortChange({ column, prop, order }: { column: any, prop: any, order: any }): void {
        const dir = Object.is(order, 'ascending') ? 'ASC' : Object.is(order, 'descending') ? 'DESC' : '';
        if (Object.is(dir, this.minorSortDir) && Object.is(this.minorSortPSDEF, prop)) {
            return;
        }
        this.minorSortDir = dir;
        this.minorSortPSDEF = prop ? prop : '';
        this.load({});
    }

    /**
     * 表格行选中样式
     *
     * @param {{ row: any, rowIndex: any }} { row, rowIndex }
     * @returns {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public onRowClassName({ row, rowIndex }: { row: any, rowIndex: any }): string {
        const index = this.selections.findIndex((select: any) => Object.is(select.srfkey, row.srfkey));
        return index !== -1 ? 'grid-row-select' : '';
    }

    /**
     * 界面行为
     *
     * @param {*} row
     * @param {*} tag
     * @param {*} $event
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
	public uiAction(row: any, tag: any, $event: any) {
        this.rowClick(row);
        this.stopRowClick = true;
        <#if ctrl.getPSAppViewLogics()??>
        <#list ctrl.getPSAppViewLogics() as logic>
        <#if logic.getPSAppViewUIAction().getPSUIAction()??>
        <#assign action = logic.getPSAppViewUIAction().getPSUIAction()>
        if(Object.is('${action.getUIActionTag()}', tag)) {
            this.${logic.getName()}(row, tag, $event);
        }
        </#if>
        </#list>
        </#if>
    }

    /**
     * 设置列状态
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public setColState() {
		const _data: any = localStorage.getItem('${ctrl.getPSDataEntity().getName()?lower_case}_${ctrl.getCodeName()?lower_case}_${ctrl.name}');
		if (_data) {
			let columns = JSON.parse(_data);
			columns.forEach((col: any) => {
				let column = this.allColumns.find((item) => Object.is(col.name, item.name));
				if (column) {
					Object.assign(column, col);
				}
			});
		}
    }

    /**
     * 列变化
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public onColChange() {
        localStorage.setItem('${ctrl.getPSDataEntity().getName()?lower_case}_${ctrl.getCodeName()?lower_case}_${ctrl.name}', JSON.stringify(this.allColumns));
    }

<#if render_block??>
${render_block}
<#else>
    /**
     * 内容绘制
     *
     * @param {CreateElement} h
     * @returns
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public render(h: CreateElement) {
        let content = {scopedSlots: {
            default: (props: any) => {
                return this.renderColumn(h, props.row, props.column, props.$index);
            }
        }};
        return (
            <div class='grid'>
                <el-table  
                    <#if !ctrl.isNoSort()> 
                    default-sort={{ prop: this.minorSortPSDEF, order: Object.is(this.minorSortDir, 'ASC') ? 'ascending' : Object.is(this.minorSortDir, 'DESC') ? 'descending' : '' }} 
                    on-sort-change={($event: any) => this.onSortChange($event)} 
                    </#if>
                    border={this.isDragendCol}
                    stripe height={this.isEnablePagingBar && this.items.length > 0 ? 'calc(100% - 50px)' : '100%'} 
                    on-row-click={($event: any) => this.rowClick($event)} 
                    on-select-all={($event: any) => this.selectAll($event)} 
                    on-select={($event: any) => this.select($event)} 
                    row-class-name={($event: any) => this.onRowClassName($event)} 
                    on-row-dblclick={($event: any) => this.rowDBLClick($event)} 
                    ref='multipleTable' data={this.items} show-header={!this.isHideHeader}>
                        { !this.isSingleSelect ? <el-table-column type='selection' width={this.checkboxColWidth}></el-table-column> : '' }
                        <#assign adaptationColu = true/>
                        <#list ctrl.getPSDEGridColumns() as column>
                        { this.render${column.getName()}(content) }
                        </#list>
                        { !this.allColumns.find((column: any) => column.show && Object.is(column.util, 'STAR')) ? <el-table-column></el-table-column> : null}
                </el-table>
                <#if ctrl.isEnablePagingBar()>
                <row class='grid-pagination' v-show={this.items.length > 0}>
                    <page class='pull-right' on-on-change={($event: any) => this.pageOnChange($event)}
                        on-on-page-size-change={($event: any) => this.onPageSizeChange($event)}
                        transfer={true} total={this.totalrow}
                        show-sizer current={this.curPage} page-size={this.limit}
                        page-size-opts={[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]} show-elevator show-total>
                        <span>
                            <span class="page-column">
                                <poptip transfer placement="top-start">
                                    <i-button icon="md-menu">{this.$t('app.gridpage.choicecolumns')}</i-button>
                                    <div slot="content">
                                        {
                                            this.allColumns.map((col: any) => {
                                                return <div><el-checkbox v-model={col.show} on-change={() => this.onColChange()}>{this.$t(col.langtag)}</el-checkbox></div>
                                            })
                                        }
                                    </div>
                                </poptip>
                            </span>
                            <span class="page-button"><i-button icon="md-refresh" title={this.$t('app.gridpage.refresh')} on-click={() => this.pageRefresh()}></i-button></span>&nbsp;
                            <span>
                                {this.$t('app.gridpage.show')}&nbsp;
                                <span>
                                    {
                                        this.items.length === 1 ? 1 :
                                            <span>{(this.curPage - 1) * this.limit + 1}&nbsp;-&nbsp;{this.totalrow > this.curPage * this.limit ? this.curPage * this.limit : this.totalrow}</span>
                                    }
                                </span>&nbsp;
                                {this.$t('app.gridpage.records')},{this.$t('app.gridpage.totle')}&nbsp;{this.totalrow}&nbsp;{this.$t('app.gridpage.records')}
                            </span>
                        </span>
                    </page>
                </row>
                </#if>
            </div>
        );
    }

    <#list ctrl.getPSDEGridColumns() as column>
<@ibizindent blank=4>
${P.getPartCode(column,'COLUMN').code}
</@ibizindent>
    </#list>

    /**
     * 绘制列
     *
     * @param {CreateElement} h
     * @param {*} row
     * @param {*} column
     * @param {*} $index
     * @returns
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public renderColumn(h: CreateElement, row: any, column: any, $index: any) {
        if(row && column) {
            <#list ctrl.getPSDEGridColumns() as column>
            <#if column.getColumnType() == 'DEFGRIDCOLUMN'>
            <#if (column.render??) || (column.getCodeList()?? && column.getCLConvertMode() == 'FRONT') || (ctrl.isEnableRowEdit() && column.isEnableRowEdit())>
            if(Object.is(column.property, '${column.getDataItemName()?lower_case}')) {
                <#if (ctrl.isEnableRowEdit() && column.isEnableRowEdit())>
                if(this.isOpenEdit) {
871
                    return (<span>${P.getEditorCode(column, "GRIDEIDTOR.tsx").code}</span>);
yanshaowei's avatar
yanshaowei committed
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
                }
                </#if>
                <#if (column.render??)>
                return (<span>${column.render.code}</span>);
                <#elseif (column.getCodeList()?? && column.getCLConvertMode() == 'FRONT')> 
                <#assign codelist = column.getPSCodeList()>
                <#if codelist.getCodeListType() == 'STATIC'>
                return (<span>
                <#if codelist.getOrMode() == 'STR'>
                    {this.$codelist.renderStrOr(h, { srfkey: '${sys.codeName}_${column.getCodeList().codeName}', value: row[column.property], emtpytext: '${codelist.getEmptyText()}', textSeparator: '${codelist.textSeparator}', valueSeparator: '${codelist.valueSeparator}' })}
                <#elseif codelist.getOrMode() == 'NUM'>
                    {this.$codelist.renderNumOr(h, { srfkey: '${sys.codeName}_${column.getCodeList().codeName}', value: row[column.property], emtpytext: '${codelist.getEmptyText()}', textSeparator: '${codelist.textSeparator}' })}
                <#else>
                    {this.$codelist.render(h, { srfkey: '${sys.codeName}_${column.getCodeList().codeName}', value: row[column.property], emtpytext: '${codelist.getEmptyText()}' })}
                </#if>
                </span>);
                </#if>
                </#if>
            }
            </#if>
            </#if>
            <#if column.getColumnType() == 'UAGRIDCOLUMN'>
            if(Object.is(column.columnKey, '${column.getName()?lower_case}')) {
                return (
                    <span>
                        <#if column.getPSDEUIActionGroup().getPSDEUIActions()??>
                        <#list column.getPSDEUIActionGroup().getPSDEUIActions() as uiaction>
                        <#if uiaction_index gt 0><divider type='vertical'></divider></#if>
                        <a on-click={($event: any) => this.uiAction(row, '${uiaction.getUIActionTag()}', $event)}>{<#if langbase??>this.$t('${langbase}.uiactions.${uiaction.getUIActionTag()?lower_case}')<#else>'${uiaction.getCaption()}'</#if>}</a>
                        </#list>
                        </#if>
                    </span>
                );
            }
            </#if>
            </#list>
            return row[column.property];
        }
    }
</#if>
}