main-grid-base.vue 52.4 KB
Newer Older
ibizdev's avatar
ibizdev committed
1
<template>
2
<div class='grid' style="height:100%">
3
  <i-form style="height:100%;display:flex;flex-direction: column;justify-content: space-between">
4
    <el-table v-if="isDisplay === true"
ibizdev's avatar
ibizdev committed
5 6 7 8 9
        :default-sort="{ prop: minorSortPSDEF, order: Object.is(minorSortDir, 'ASC') ? 'ascending' : Object.is(minorSortDir, 'DESC') ? 'descending' : '' }"  
        @sort-change="onSortChange($event)"  
        :border="isDragendCol"
        :highlight-current-row ="isSingleSelect"
        :row-class-name="getRowClassName"
10
        :cell-class-name="getCellClassName"
11
        max-height="items.length > 0 ? 'calc(100%-50px)' : '100%'"
ibizdev's avatar
ibizdev committed
12 13 14 15 16 17
        @row-click="rowClick($event)"  
        @select-all="selectAll($event)"  
        @select="select($event)"  
        @row-class-name="onRowClassName($event)"  
        @row-dblclick="rowDBLClick($event)"  
        ref='multipleTable' :data="items" :show-header="!isHideHeader">
ibizdev's avatar
ibizdev committed
18
            <template slot="empty">
19
                {{$t('app.gridpage.noData')}} 
ibizdev's avatar
ibizdev committed
20
            </template>
ibizdev's avatar
ibizdev committed
21 22 23
            <template v-if="!isSingleSelect">
                <el-table-column align="center" type='selection' :width="checkboxColWidth"></el-table-column>
            </template>
ibizdev's avatar
ibizdev committed
24
            <template v-if="getColumnState('userid')">
25
                <el-table-column show-overflow-tooltip :prop="'userid'" :label="$t('entities.wfuser.main_grid.columns.userid')" :width="250"  :align="'left'" :sortable="'custom'">
26 27 28 29 30 31
                    <template v-slot:header="{column}">
                      <span class="column-header ">
                        {{$t('entities.wfuser.main_grid.columns.userid')}}
                      </span>
                    </template>
                    <template v-slot="{row,column,$index}">
ibizdev's avatar
ibizdev committed
32 33 34 35 36
                        <span>{{row.userid}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('personname')">
37
                <el-table-column show-overflow-tooltip :prop="'personname'" :label="$t('entities.wfuser.main_grid.columns.personname')" :width="250"  :align="'left'" :sortable="'custom'">
38 39 40 41 42 43
                    <template v-slot:header="{column}">
                      <span class="column-header ">
                        {{$t('entities.wfuser.main_grid.columns.personname')}}
                      </span>
                    </template>
                    <template v-slot="{row,column,$index}">
ibizdev's avatar
ibizdev committed
44 45 46 47 48
                        <span>{{row.personname}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('username')">
49
                <el-table-column show-overflow-tooltip :prop="'username'" :label="$t('entities.wfuser.main_grid.columns.username')" :width="250"  :align="'left'" :sortable="'custom'">
50 51 52 53 54 55
                    <template v-slot:header="{column}">
                      <span class="column-header ">
                        {{$t('entities.wfuser.main_grid.columns.username')}}
                      </span>
                    </template>
                    <template v-slot="{row,column,$index}">
ibizdev's avatar
ibizdev committed
56 57 58 59
                        <span>{{row.username}}</span>
                    </template>
                </el-table-column>
            </template>
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
            <template v-if="getColumnState('orgname')">
                <el-table-column show-overflow-tooltip :prop="'orgname'" :label="$t('entities.wfuser.main_grid.columns.orgname')" :width="250"  :align="'left'" :sortable="'custom'">
                    <template v-slot:header="{column}">
                      <span class="column-header ">
                        {{$t('entities.wfuser.main_grid.columns.orgname')}}
                      </span>
                    </template>
                    <template v-slot="{row,column,$index}">
                        <span>{{row.orgname}}</span>
                    </template>
                </el-table-column>
            </template>
            <template v-if="getColumnState('mdeptname')">
                <el-table-column show-overflow-tooltip :prop="'mdeptname'" :label="$t('entities.wfuser.main_grid.columns.mdeptname')" :width="250"  :align="'left'" :sortable="'custom'">
                    <template v-slot:header="{column}">
                      <span class="column-header ">
                        {{$t('entities.wfuser.main_grid.columns.mdeptname')}}
                      </span>
                    </template>
                    <template v-slot="{row,column,$index}">
                        <span>{{row.mdeptname}}</span>
                    </template>
                </el-table-column>
            </template>
ibizdev's avatar
ibizdev committed
84 85 86 87
            <template v-if="adaptiveState">
                <el-table-column></el-table-column>
            </template>
    </el-table>
88
  
ibizdev's avatar
ibizdev committed
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
    <row class='grid-pagination' v-show="items.length > 0">
        <page class='pull-right' @on-change="pageOnChange($event)" 
            @on-page-size-change="onPageSizeChange($event)"
            :transfer="true" :total="totalrow"
            show-sizer :current="curPage" :page-size="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">{{$t('app.gridpage.choicecolumns')}}</i-button>
                        <div slot="content">
                            <template v-for="col in allColumns">
                                <div :key="col.name"><el-checkbox v-model="col.show" @change="onColChange()">{{$t(col.langtag)}}</el-checkbox></div>
                            </template>
                        </div>
                    </poptip>
                </span>
                <span class="page-button"><i-button icon="md-refresh" :title="$t('app.gridpage.refresh')" @click="pageRefresh()"></i-button></span>&nbsp;
                <span>
                    {{$t('app.gridpage.show')}}&nbsp;
                    <span>
                        <template v-if="items.length === 1">
                        1
                        </template>
                        <template v-else>
                            <span>{{(curPage - 1) * limit + 1}}&nbsp;-&nbsp;{{totalrow > curPage * limit ? curPage * limit : totalrow}}</span>
                        </template>
                    </span>&nbsp;
                    {{$t('app.gridpage.records')}},{{$t('app.gridpage.totle')}}&nbsp;{{totalrow}}&nbsp;{{$t('app.gridpage.records')}}
                </span>
            </span>
        </page>
    </row>
122
  </i-form>
ibizdev's avatar
ibizdev committed
123 124 125
</div>
</template>
<script lang='tsx'>
126
import { Vue, Component, Prop, Provide, Emit, Watch, Model,Inject } from 'vue-property-decorator';
ibizdev's avatar
ibizdev committed
127 128 129
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
130
import { UIActionTool,Util,ViewTool } from '@/utils';
131
import NavDataService from '@/service/app/navdata-service';
132
import AppCenterService from "@service/app/app-center-service";
ibizdev's avatar
ibizdev committed
133 134
import WFUserService from '@/service/wfuser/wfuser-service';
import MainService from './main-grid-service';
135
import WFUserUIService from '@/uiservice/wfuser/wfuser-ui-service';
ibizdev's avatar
ibizdev committed
136
import CodeListService from "@service/app/codelist-service";
137
import { FormItemModel } from '@/model/form-detail';
ibizdev's avatar
ibizdev committed
138 139 140 141 142 143 144 145 146 147 148 149 150


@Component({
    components: {
      
    }
})
export default class MainBase extends Vue implements ControlInterface {

    /**
     * 名称
     *
     * @type {string}
151
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
152
     */
ibizdev's avatar
ibizdev committed
153
    @Prop() public name?: string;
ibizdev's avatar
ibizdev committed
154 155 156 157 158

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
159
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
160
     */
ibizdev's avatar
ibizdev committed
161
    @Prop() public viewState!: Subject<ViewState>;
ibizdev's avatar
ibizdev committed
162 163 164 165 166

    /**
     * 应用上下文
     *
     * @type {*}
167
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
168
     */
ibizdev's avatar
ibizdev committed
169
    @Prop() public context: any;
ibizdev's avatar
ibizdev committed
170 171 172 173 174

    /**
     * 视图参数
     *
     * @type {*}
175
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
176
     */
ibizdev's avatar
ibizdev committed
177
    @Prop() public viewparams: any;
ibizdev's avatar
ibizdev committed
178 179 180 181

    /**
     * 视图状态事件
     *
ibizdev's avatar
ibizdev committed
182
     * @public
ibizdev's avatar
ibizdev committed
183
     * @type {(Subscription | undefined)}
184
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
185
     */
ibizdev's avatar
ibizdev committed
186
    public viewStateEvent: Subscription | undefined;
ibizdev's avatar
ibizdev committed
187 188 189 190 191

    /**
     * 获取部件类型
     *
     * @returns {string}
192
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
193
     */
ibizdev's avatar
ibizdev committed
194
    public getControlType(): string {
ibizdev's avatar
ibizdev committed
195 196 197 198 199 200 201 202 203
        return 'GRID'
    }



    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
204
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
205
     */    
ibizdev's avatar
ibizdev committed
206
    public counterServiceArray:Array<any> = [];
ibizdev's avatar
ibizdev committed
207 208 209 210 211

    /**
     * 建构部件服务对象
     *
     * @type {MainService}
212
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
213
     */
ibizdev's avatar
ibizdev committed
214
    public service: MainService = new MainService({ $store: this.$store });
ibizdev's avatar
ibizdev committed
215 216 217 218 219

    /**
     * 实体服务对象
     *
     * @type {WFUserService}
220
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
221
     */
ibizdev's avatar
ibizdev committed
222
    public appEntityService: WFUserService = new WFUserService({ $store: this.$store });
ibizdev's avatar
ibizdev committed
223 224 225
    


226 227 228 229 230 231 232 233 234 235 236 237 238
    /**
     * 转化数据
     *
     * @param {any} args
     * @memberof  MainBase
     */
    public transformData(args: any) {
        let _this: any = this;
        if(_this.service && _this.service.handleRequestData instanceof Function && _this.service.handleRequestData('transform',_this.context,args)){
            return _this.service.handleRequestData('transform',_this.context,args)['data'];
        }
    }

ibizdev's avatar
ibizdev committed
239 240 241 242
    /**
     * 关闭视图
     *
     * @param {any} args
243
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
244
     */
ibizdev's avatar
ibizdev committed
245
    public closeView(args: any): void {
ibizdev's avatar
ibizdev committed
246 247 248 249 250 251 252
        let _this: any = this;
        _this.$emit('closeview', [args]);
    }

    /**
     *  计数器刷新
     *
253
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
     */
    public counterRefresh(){
        const _this:any =this;
        if(_this.counterServiceArray && _this.counterServiceArray.length >0){
            _this.counterServiceArray.forEach((item:any) =>{
                if(item.refreshData && item.refreshData instanceof Function){
                    item.refreshData();
                }
            })
        }
    }


    /**
     * 代码表服务对象
     *
     * @type {CodeListService}
271
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
272 273 274
     */  
    public codeListService:CodeListService = new CodeListService({ $store: this.$store });

275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    /**
     * 界面UI服务对象
     *
     * @type {WFUserUIService}
     * @memberof MainBase
     */  
    public appUIService:WFUserUIService = new WFUserUIService(this.$store);

    /**
     * 界面行为模型
     *
     * @type {*}
     * @memberof MainBase
     */  
    public ActionModel:any ={
    };

292 293 294 295 296 297 298 299 300
    /**
     * 应用状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     * @memberof MainBase
     */
    public appStateEvent: Subscription | undefined;

ibizdev's avatar
ibizdev committed
301 302 303 304
    /**
     * 获取多项数据
     *
     * @returns {any[]}
305
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
306 307 308 309 310 311 312 313 314
     */
    public getDatas(): any[] {
        return this.selections;
    }

    /**
     * 获取单项树
     *
     * @returns {*}
315
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
316 317 318 319 320 321 322 323 324
     */
    public getData(): any {
        return this.selections[0];
    }

    /**
     * 打开新建数据视图
     *
     * @type {any}
325
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
326
     */
ibizdev's avatar
ibizdev committed
327
    @Prop() public newdata: any;
ibizdev's avatar
ibizdev committed
328 329 330 331
    /**
     * 打开编辑数据视图
     *
     * @type {any}
332
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
333
     */
ibizdev's avatar
ibizdev committed
334
    @Prop() public opendata: any;
ibizdev's avatar
ibizdev committed
335 336 337 338 339

    /**
     * 显示处理提示
     *
     * @type {boolean}
340
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
341
     */
ibizdev's avatar
ibizdev committed
342
    @Prop({ default: true }) public showBusyIndicator?: boolean;
ibizdev's avatar
ibizdev committed
343 344 345 346 347

    /**
     * 部件行为--update
     *
     * @type {string}
348
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
349
     */
ibizdev's avatar
ibizdev committed
350
    @Prop() public updateAction!: string;
ibizdev's avatar
ibizdev committed
351 352 353 354 355
    
    /**
     * 部件行为--fetch
     *
     * @type {string}
356
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
357
     */
ibizdev's avatar
ibizdev committed
358
    @Prop() public fetchAction!: string;
ibizdev's avatar
ibizdev committed
359 360 361 362 363
    
    /**
     * 部件行为--remove
     *
     * @type {string}
364
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
365
     */
ibizdev's avatar
ibizdev committed
366
    @Prop() public removeAction!: string;
ibizdev's avatar
ibizdev committed
367 368 369 370 371
    
    /**
     * 部件行为--load
     *
     * @type {string}
372
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
373
     */
ibizdev's avatar
ibizdev committed
374
    @Prop() public loadAction!: string;
ibizdev's avatar
ibizdev committed
375 376 377 378 379
    
    /**
     * 部件行为--loaddraft
     *
     * @type {string}
380
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
381
     */
ibizdev's avatar
ibizdev committed
382
    @Prop() public loaddraftAction!: string;
ibizdev's avatar
ibizdev committed
383 384 385 386 387
    
    /**
     * 部件行为--create
     *
     * @type {string}
388
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
389
     */
ibizdev's avatar
ibizdev committed
390
    @Prop() public createAction!: string;
ibizdev's avatar
ibizdev committed
391 392 393 394 395

    /**
     * 当前页
     *
     * @type {number}
396
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
397
     */
ibizdev's avatar
ibizdev committed
398
    public curPage: number = 1;
ibizdev's avatar
ibizdev committed
399 400 401 402 403

    /**
     * 数据
     *
     * @type {any[]}
404
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
405
     */
ibizdev's avatar
ibizdev committed
406
    public items: any[] = [];
ibizdev's avatar
ibizdev committed
407 408 409 410 411

    /**
     * 是否支持分页
     *
     * @type {boolean}
412
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
413
     */
ibizdev's avatar
ibizdev committed
414
    public isEnablePagingBar: boolean = true;
ibizdev's avatar
ibizdev committed
415 416 417 418 419

    /**
     * 是否禁用排序
     *
     * @type {boolean}
420
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
421
     */
ibizdev's avatar
ibizdev committed
422
    public isNoSort: boolean = false;
ibizdev's avatar
ibizdev committed
423 424 425 426 427

    /**
     * 排序方向
     *
     * @type {string}
428
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
429
     */
ibizdev's avatar
ibizdev committed
430
    public minorSortDir: string = '';
ibizdev's avatar
ibizdev committed
431 432 433 434 435

    /**
     * 排序字段
     *
     * @type {string}
436
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
437
     */
ibizdev's avatar
ibizdev committed
438
    public minorSortPSDEF: string = '';
ibizdev's avatar
ibizdev committed
439 440 441 442 443

    /**
     * 分页条数
     *
     * @type {number}
444
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
445
     */
ibizdev's avatar
ibizdev committed
446
    public limit: number = 20;
ibizdev's avatar
ibizdev committed
447 448 449 450 451

    /**
     * 是否显示标题
     *
     * @type {boolean}
452
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
453
     */
ibizdev's avatar
ibizdev committed
454
    public isHideHeader: boolean = false;
ibizdev's avatar
ibizdev committed
455 456 457 458 459

    /**
     * 是否默认选中第一条数据
     *
     * @type {boolean}
460
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
461
     */
ibizdev's avatar
ibizdev committed
462
    @Prop({ default: false }) public isSelectFirstDefault!: boolean;
ibizdev's avatar
ibizdev committed
463 464 465 466 467

    /**
     * 是否单选
     *
     * @type {boolean}
468
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
469
     */
ibizdev's avatar
ibizdev committed
470
    @Prop() public isSingleSelect?: boolean;
ibizdev's avatar
ibizdev committed
471 472 473 474 475

    /**
     * 选中数据字符串
     *
     * @type {string}
476
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
477
     */
ibizdev's avatar
ibizdev committed
478
    @Prop() public selectedData?: string;
ibizdev's avatar
ibizdev committed
479 480 481 482 483 484

    /**
     * 选中值变化
     *
     * @param {*} newVal
     * @param {*} oldVal
485
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
     */
    @Watch('selectedData')
    public onValueChange(newVal: any, oldVal: any) {
        this.selections = [];
        if(this.selectedData){
            const refs: any = this.$refs;
            if (refs.multipleTable) {
                refs.multipleTable.clearSelection();
                JSON.parse(this.selectedData).forEach((selection:any)=>{
                    let selectedItem = this.items.find((item:any)=>{
                        return Object.is(item.srfkey, selection.srfkey);
                    });
                    if(selectedItem){
                        this.rowClick(selectedItem);
                    }
                });
            }
        }
    }

    /**
     * 表格行数据默认激活模式
     * 0 不激活
     * 1 单击激活
     * 2 双击激活
     *
     * @type {(number | 0 | 1 | 2)}
513
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
514
     */
ibizdev's avatar
ibizdev committed
515
    @Prop({default: 2}) public gridRowActiveMode!: number;
ibizdev's avatar
ibizdev committed
516 517 518 519 520

    /**
     * 是否开启行编辑
     *
     * @type {boolean}
521
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
522
     */
ibizdev's avatar
ibizdev committed
523
    @Prop({default: false}) public isOpenEdit!: boolean;
ibizdev's avatar
ibizdev committed
524 525 526 527 528

    /**
     * 实际是否开启行编辑
     *
     * @type {boolean}
529
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
530
     */
ibizdev's avatar
ibizdev committed
531
    public actualIsOpenEdit: boolean = this.isOpenEdit;
ibizdev's avatar
ibizdev committed
532 533 534 535 536

    /**
     * 总条数
     *
     * @type {number}
537
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
538
     */
ibizdev's avatar
ibizdev committed
539
    public totalrow: number = 0;
ibizdev's avatar
ibizdev committed
540

541 542 543 544 545
    /**
     * 表格更新默认值项
     * 
     * @memberof MainBase
     */
546
    public defaultUpdateItems:Array<any> =[];
547

ibizdev's avatar
ibizdev committed
548 549 550 551 552 553
    /**
     * 选中行数据
     *
     * @type {any[]}
     * @memberof Main
     */
ibizdev's avatar
ibizdev committed
554
    public selections: any[] = [];
ibizdev's avatar
ibizdev committed
555 556 557 558 559 560 561

    /**
     * 拦截行选中
     *
     * @type {boolean}
     * @memberof Main
     */
ibizdev's avatar
ibizdev committed
562
    public stopRowClick: boolean = false;
ibizdev's avatar
ibizdev committed
563 564


ibizdev's avatar
ibizdev committed
565 566


ibizdev's avatar
ibizdev committed
567 568 569 570
    /**
     * 表格是否显示
     *
     * @type {boolean}
571
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
572
     */
ibizdev's avatar
ibizdev committed
573
    public isDisplay:boolean = true;
ibizdev's avatar
ibizdev committed
574 575 576 577 578

    /**
     * 部件刷新
     *
     * @param {any[]} args
579
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
580
     */
ibizdev's avatar
ibizdev committed
581
    public refresh(args: any[]): void {
ibizdev's avatar
ibizdev committed
582 583 584 585 586 587 588 589 590
        this.load();
    }

    /**
    * 选项框列宽
    *
    * @type {number}
    * @memberof AppIndex
    */
ibizdev's avatar
ibizdev committed
591
    public checkboxColWidth: number = 50;
ibizdev's avatar
ibizdev committed
592 593 594 595 596 597 598

    /**
     * 是否允许拖动列宽
     *
     * @type {boolean}
     * @memberof AppEmbedPicker
     */
599 600
    public isDragendCol: boolean = true;
    
ibizdev's avatar
ibizdev committed
601 602 603 604
    /**
     * 所有列成员
     *
     * @type {any[]}
605
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
606
     */
ibizdev's avatar
ibizdev committed
607
    public allColumns: any[] = [
ibizdev's avatar
ibizdev committed
608 609 610 611 612
        {
            name: 'userid',
            label: '用户标识',
            langtag: 'entities.wfuser.main_grid.columns.userid',
            show: true,
613 614
            util: 'PX',
            isEnableRowEdit: false,
ibizdev's avatar
ibizdev committed
615 616 617 618 619 620
        },
        {
            name: 'personname',
            label: '用户名称',
            langtag: 'entities.wfuser.main_grid.columns.personname',
            show: true,
621 622
            util: 'PX',
            isEnableRowEdit: false,
ibizdev's avatar
ibizdev committed
623 624 625 626 627 628
        },
        {
            name: 'username',
            label: '用户全局名',
            langtag: 'entities.wfuser.main_grid.columns.username',
            show: true,
629 630
            util: 'PX',
            isEnableRowEdit: false,
ibizdev's avatar
ibizdev committed
631
        },
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
        {
            name: 'orgname',
            label: '单位名称',
            langtag: 'entities.wfuser.main_grid.columns.orgname',
            show: true,
            util: 'PX',
            isEnableRowEdit: false,
        },
        {
            name: 'mdeptname',
            label: '主部门名称',
            langtag: 'entities.wfuser.main_grid.columns.mdeptname',
            show: true,
            util: 'PX',
            isEnableRowEdit: false,
        },
ibizdev's avatar
ibizdev committed
648 649
    ]

650 651 652 653
    /**
     * 表格模型集合
     *
     * @type {*}
654
     * @memberof MainBase
655 656 657
     */
    public gridItemsModel: any[] = [];

658 659 660 661 662 663 664 665 666 667 668 669
    /**
     * 获取界面行为权限状态
     *
     * @memberof MainBase
     */
    public getActionState(data:any){
        let targetData:any = this.transformData(data);
        let tempActionModel:any = JSON.parse(JSON.stringify(this.ActionModel));
        ViewTool.calcActionItemAuthState(targetData,tempActionModel,this.appUIService);
        return tempActionModel;
    }

670 671 672 673
    /**
     * 获取表格行模型
     *
     * @type {*}
674
     * @memberof MainBase
675 676 677 678 679 680 681
     */
    public getGridRowModel(){
        return {
          srfkey: new FormItemModel(),
        }
    }

ibizdev's avatar
ibizdev committed
682 683 684 685
    /**
     * 属性值规则
     *
     * @type {*}
686
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
687
     */
ibizdev's avatar
ibizdev committed
688
    public rules: any = {
ibizdev's avatar
ibizdev committed
689 690 691 692 693 694
        srfkey: [
             { required: false, validator: (rule:any, value:any, callback:any) => { return (rule.required && (value === null || value === undefined || value === "")) ? false : true;}, message: '用户标识 值不能为空', trigger: 'change' },
            { required: false, validator: (rule:any, value:any, callback:any) => { return (rule.required && (value === null || value === undefined || value === "")) ? false : true;}, message: '用户标识 值不能为空', trigger: 'blur' },
        ],
    }

695 696 697 698 699 700 701 702
    /**
     * 表格行编辑项校验
     *
     * @param {string} property 属性名
     * @param {*} data 行数据
     * @param {number} rowIndex 行索引
     * @returns Promise<any>
     * 
703
     * @memberof MainBase
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
     */
    public validate(property:string, data:any, rowIndex:number):Promise<any>{
        return new Promise((resolve, reject) => {
            this.$util.validateItem(property,data,this.rules).then(()=>{
                this.gridItemsModel[rowIndex][property].setError(null);
                resolve(true);
            }).catch(({ errors, fields }) => {
                this.gridItemsModel[rowIndex][property].setError(errors[0].message);
                resolve(false);
            });
        });
    }

    /**
     * 校验所有修改过的编辑项
     *
     * @returns Promise<any>
721
     * @memberof MainBase
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
     */
    public async validateAll(){
        let validateState = true;
        let index = -1;
        for(let item of this.items){
          index++;
          if(item.rowDataState === "create" || item.rowDataState === "update"){
            for(let property of Object.keys(this.rules)){
              if(!await this.validate(property,item,index)){
                validateState = false;
              }
            }
          }
        }
        return validateState;
    }

ibizdev's avatar
ibizdev committed
739 740 741 742
    /**
     * 表格数据加载
     *
     * @param {*} [arg={}]
743
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
744
     */
ibizdev's avatar
ibizdev committed
745
    public load(opt: any = {}, pageReset: boolean = false): void {
ibizdev's avatar
ibizdev committed
746
        if(!this.fetchAction){
747
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserGridView'+(this.$t('app.gridpage.notConfig.fetchAction') as string) });
ibizdev's avatar
ibizdev committed
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
            return;
        }
        if(pageReset){
            this.curPage = 1;
        }
        const arg: any = {...opt};
        const page: any = {};
        if (this.isEnablePagingBar) {
            Object.assign(page, { page: this.curPage-1, size: this.limit });
        }
        // 设置排序
        if (!this.isNoSort && !Object.is(this.minorSortDir, '') && !Object.is(this.minorSortPSDEF, '')) {
            const sort: string = this.minorSortPSDEF+","+this.minorSortDir;
            Object.assign(page, { sort: sort });
        }
        Object.assign(arg, page);
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);
ibizdev's avatar
ibizdev committed
767 768 769
        let tempViewParams:any = parentdata.viewparams?parentdata.viewparams:{};
        Object.assign(tempViewParams,JSON.parse(JSON.stringify(this.viewparams)));
        Object.assign(arg,{viewparams:tempViewParams});
ibizdev's avatar
ibizdev committed
770 771 772 773
        const post: Promise<any> = this.service.search(this.fetchAction,JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
        post.then((response: any) => {
            if (!response.status || response.status !== 200) {
                if (response.errorMessage) {
774
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.errorMessage });
ibizdev's avatar
ibizdev committed
775 776 777 778 779 780
                }
                return;
            }
            const data: any = response.data;
            this.totalrow = response.total;
            this.items = JSON.parse(JSON.stringify(data));
781
            // 清空selections,gridItemsModel
ibizdev's avatar
ibizdev committed
782
            this.selections = [];
783 784
            this.gridItemsModel = [];
            this.items.forEach(()=>{this.gridItemsModel.push(this.getGridRowModel())});
785 786 787
            this.items.forEach((item:any)=>{
                Object.assign(item,this.getActionState(item));    
            });
ibizdev's avatar
ibizdev committed
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
            this.$emit('load', this.items);
            // 设置默认选中
            let _this = this;
            setTimeout(() => {
                if(_this.isSelectFirstDefault){
                  _this.rowClick(_this.items[0]);
                }
                if(_this.selectedData){
                    const refs: any = _this.$refs;
                    if (refs.multipleTable) {
                        refs.multipleTable.clearSelection();
                        JSON.parse(_this.selectedData).forEach((selection:any)=>{
                            let selectedItem = _this.items.find((item:any)=>{
                                return Object.is(item.srfkey, selection.srfkey);
                            });
                            if(selectedItem){
                                _this.rowClick(selectedItem);
                            }
                        });
                    }
                }
            }, 300);
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
814
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.errorMessage });
ibizdev's avatar
ibizdev committed
815 816 817 818 819 820 821 822
        });
    }

    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
823
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
824
     */
ibizdev's avatar
ibizdev committed
825
    public async remove(datas: any[]): Promise<any> {
ibizdev's avatar
ibizdev committed
826
        if(!this.removeAction){
827
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserGridView'+(this.$t('app.gridpage.notConfig.removeAction') as string) });
ibizdev's avatar
ibizdev committed
828 829 830 831
            return;
        }
        let _datas:any[] = [];
        datas.forEach((record: any, index: number) => {
832
            if (Object.is(record.srfuf,"0")) {
ibizdev's avatar
ibizdev committed
833 834 835
                this.items.some((val: any, num: number) =>{
                    if(JSON.stringify(val) == JSON.stringify(record)){
                        this.items.splice(num,1);
836
                        this.gridItemsModel.splice(num,1);
ibizdev's avatar
ibizdev committed
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
                        return true;
                    }
                }); 
            }else{
               _datas.push(datas[index]);
            }
        });
        if (_datas.length === 0) {
            return;
        }
        let dataInfo = '';
        _datas.forEach((record: any, index: number) => {
            let srfmajortext = record.displayname;
            if (index < 5) {
                if (!Object.is(dataInfo, '')) {
                    dataInfo += '、';
                }
                dataInfo += srfmajortext;
            } else {
                return false;
            }
        });

        if (_datas.length < 5) {
861
            dataInfo = dataInfo + ' '+(this.$t('app.gridpage.totle') as string) + _datas.length + (this.$t('app.gridpage.records') as string)+(this.$t('app.gridpage.data') as string);
ibizdev's avatar
ibizdev committed
862
        } else {
863
            dataInfo = dataInfo + '...' + ' '+(this.$t('app.gridpage.totle') as string) + _datas.length + (this.$t('app.gridpage.desc2') as string);
ibizdev's avatar
ibizdev committed
864 865 866 867 868 869 870
        }

        const removeData = () => {
            let keys: any[] = [];
            _datas.forEach((data: any) => {
                keys.push(data.srfkey);
            });
ibizdev's avatar
ibizdev committed
871
            let _removeAction = keys.length > 1 ? 'removeBatch' : this.removeAction ;
872
            let _keys = keys.length > 1 ? keys : keys[0] ;
ibizdev's avatar
ibizdev committed
873
            const context:any = JSON.parse(JSON.stringify(this.context));
874
            const post: Promise<any> = this.service.delete(_removeAction,Object.assign(context,{ wfuser: _keys }),Object.assign({ wfuser: _keys },{viewparams:this.viewparams}), this.showBusyIndicator);
ibizdev's avatar
ibizdev committed
875 876 877
            return new Promise((resolve: any, reject: any) => {
                post.then((response: any) => {
                    if (!response || response.status !== 200) {
878
                        this.$Notice.error({ title: '', desc: (this.$t('app.gridpage.delDataFail') as string)+',' + response.info });
ibizdev's avatar
ibizdev committed
879 880
                        return;
                    } else {
881
                        this.$Notice.success({ title: '', desc: (this.$t('app.gridpage.delSuccess') as string) });
ibizdev's avatar
ibizdev committed
882 883 884 885
                    }
                    //删除items中已删除的项
                    console.log(this.items);
                    _datas.forEach((data: any) => {
886 887 888 889
                        this.items.some((item:any,index:number)=>{
                            if(Object.is(item.srfkey,data.srfkey)){
                                this.items.splice(index,1);
                                this.gridItemsModel.splice(index,1);
ibizdev's avatar
ibizdev committed
890 891 892 893 894 895 896 897 898 899 900 901 902
                                return true;
                            }
                        });
                    });
                    this.totalrow -= _datas.length;
                    this.$emit('remove', null);
                    this.selections = [];
                    resolve(response);
                }).catch((response: any) => {
                    if (response && response.status === 401) {
                        return;
                    }
                    if (!response || !response.status || !response.data) {
903
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
904 905 906 907 908 909 910 911 912 913
                        reject(response);
                        return;
                    }
                    reject(response);
                });
            });
        }

        dataInfo = dataInfo.replace(/[null]/g, '').replace(/[undefined]/g, '');
        this.$Modal.confirm({
914 915
            title: (this.$t('app.commonWords.warning') as string),
            content: (this.$t('app.gridpage.confirmDel') as string)+' ' + dataInfo + ','+(this.$t('app.gridpage.notRecoverable') as string),
ibizdev's avatar
ibizdev committed
916 917 918 919 920 921 922 923 924 925 926 927 928
            onOk: () => {
                removeData();
            },
            onCancel: () => { }
        });
        return removeData;
    }


    /**
     * 批量添加
     *
     * @param {*} [arg={}]
929
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
930
     */
ibizdev's avatar
ibizdev committed
931
    public addBatch(arg: any = {}): void {
ibizdev's avatar
ibizdev committed
932
        if(!this.fetchAction){
933
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserGridView'+(this.$t('app.gridpage.notConfig.fetchAction') as string) });
ibizdev's avatar
ibizdev committed
934 935 936 937 938
            return;
        }
        if(!arg){
            arg = {};
        }
939
        console.error((this.$t('app.gridpage.notBatch') as string));
ibizdev's avatar
ibizdev committed
940 941 942 943 944 945
    }

    /**
     * 数据导入
     *
     * @param {*} data
946
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
     */
     public importExcel(data:any ={}):void{
        //导入excel
        const importDataModel:any ={
        }
        if(Object.keys(importDataModel).length == 0){
            this.$Notice.warning({ 'title': (this.$t("app.utilview.warning") as string), 'desc': (this.$t("app.utilview.info") as string) });
            return;
        }
        const view:any ={
            viewname: 'app-data-upload',
            title: this.$t("app.utilview.importview"),
            width: 900,
            height: 700
        }
        let container: Subject<any> = this.$appmodal.openModal(view, JSON.parse(JSON.stringify(this.context)), importDataModel);
        container.subscribe((result: any) => {
          if(Object.is(result.ret,'OK')){
            this.refresh(result.datas);
          }
      });
    }


    /**
     * 数据导出
     *
     * @param {*} data
975
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
976
     */
ibizdev's avatar
ibizdev committed
977
    public exportExcel(data: any = {}): void {
ibizdev's avatar
ibizdev committed
978 979 980 981 982 983 984 985 986 987 988 989 990
        // 导出Excel
        const doExport = async (_data:any) => {
            const tHeader: Array<any> = [];
            const filterVal: Array<any> = [];
            this.allColumns.forEach((item: any) => {
              item.show && item.label ? tHeader.push(this.$t(item.langtag)) : "";
              item.show && item.name ? filterVal.push(item.name) : "";
            });
            const data = await this.formatExcelData(filterVal, _data);
            this.$export.exportExcel().then((excel:any)=>{
                excel.export_json_to_excel({
                  header: tHeader, //表头 必填
                  data, //具体数据 必填
991
                  filename: "用户"+(this.$t('app.gridpage.grid') as string), //非必填
ibizdev's avatar
ibizdev committed
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
                  autoWidth: true, //非必填
                  bookType: "xlsx" //非必填
                });
            }); 
        };
        const page: any = {};
        // 设置page,size
        if (Object.is(data.type, 'maxRowCount')) {
            Object.assign(page, { page: 0, size: data.maxRowCount });
        } else if (Object.is(data.type, 'activatedPage')) {
            try {
                doExport(JSON.parse(JSON.stringify(this.items)));
            } catch (error) {
                console.error(error);
            }
            return;
        }
        // 设置排序
        if (!this.isNoSort && !Object.is(this.minorSortDir, '') && !Object.is(this.minorSortPSDEF, '')) {
          const sort: string = this.minorSortPSDEF+","+this.minorSortDir;
            Object.assign(page, { sort: sort });
        }
        const arg: any = {};
        Object.assign(arg, page);
        // 获取query,搜索表单,viewparams等父数据
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);
        const post: Promise<any> = this.service.search(this.fetchAction,JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
        post.then((response: any) => {
            if (!response || response.status !== 200) {
1023
                this.$Notice.error({ title: '', desc: (this.$t('app.gridpage.exportFail') as string)+',' + response.info });
ibizdev's avatar
ibizdev committed
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
                return;
            }
            try {
                doExport(JSON.parse(JSON.stringify(response.data)));
            } catch (error) {
                console.error(error);
            }
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
1035
            this.$Notice.error({ title: '', desc: (this.$t('app.gridpage.exportFail') as string) });
ibizdev's avatar
ibizdev committed
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
        });
    }


    /**
     * 导出数据格式化
     * 
     * @param {*} filterVal
     * @param {*} jsonData
     * @returns {[]}
1046
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
     */
    public async formatExcelData(filterVal:any, jsonData:any) {
        let codelistColumns:Array<any> = [
        ];
        let _this = this;
        for (const codelist of codelistColumns) {
          // 动态代码表处理
          if (Object.is(codelist.codelistType, "DYNAMIC")) {
              let items = await _this.codeListService.getItems(codelist.srfkey);
              jsonData.forEach((row:any)=>{
                  row[codelist.name] = _this.getCodelistValue(items, row[codelist.name], codelist);
              });
          // 静态处理
          } else if(Object.is(codelist.codelistType, "STATIC")){
              let items = await _this.$store.getters.getCodeListItems(codelist.srfkey);
              jsonData.forEach((row:any)=>{
                  row[codelist.name] = _this.getCodelistValue(items, row[codelist.name], codelist);
              });
          }
        }
        return jsonData.map((v:any) => filterVal.map((j:any) => v[j]))
    }   


    /**
     * 解析代码表和vlaue,设置items
     *
ibizdev's avatar
ibizdev committed
1074
     * @public
ibizdev's avatar
ibizdev committed
1075 1076 1077
     * @param {any[]} items 代码表数据
     * @param {*} value
     * @returns {*}
1078
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1079
     */
ibizdev's avatar
ibizdev committed
1080
    public getCodelistValue(items: any[], value: any, codelist: any,){
ibizdev's avatar
ibizdev committed
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
        if(!value){
            return this.$t('codelist.'+codelist.srfkey+'.empty');
        }
        if (items) {
            let result:any = [];
            if(Object.is(codelist.renderMode,"number")){
                items.map((_item: any, index: number)=>{
                    const nValue = parseInt((value as any), 10);
                    const codevalue = _item.value;
                    if((parseInt(codevalue, 10) & nValue) > 0){
                        result.push(_item);
                    } 
                });
            } else if(Object.is(codelist.renderMode,"string")){
                const arrayValue: Array<any> = (value as any).split(codelist.valueSeparator);
                arrayValue.map((value: any, index: number) => {
                    result.push([]);
                    let values: any[] = Object.is(this.$util.typeOf(value), 'number') ? [value] : [...(value as any).split(codelist.valueSeparator)];
                    values.map((val:any ,num: number)=>{
                        const item = this.getItem(items, val, codelist); 
                        if(item){
                          result[index].push(item);
                        } 
                    });
                });
            } else {
                let values: any[] = Object.is(this.$util.typeOf(value), 'number') ? [value] : [...(value as any).split(codelist.valueSeparator)];
                values.map((value:any ,index: number)=>{
                    const item = this.getItem(items, value, codelist); 
                    if(item){
                      result.push(item);
                    } 
                });
            }
            // 设置items
            if(result.length != 0){
              return result.join(codelist.valueSeparator);
            }else{
              return value;
            }
        }
    }

    /**
     * 获取代码项
     *
ibizdev's avatar
ibizdev committed
1127
     * @public
ibizdev's avatar
ibizdev committed
1128 1129 1130
     * @param {any[]} items
     * @param {*} value
     * @returns {*}
1131
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1132
     */
ibizdev's avatar
ibizdev committed
1133
    public getItem(items: any[], value: any, codelist: any): any {
ibizdev's avatar
ibizdev committed
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
        const arr: Array<any> = items.filter(item => {return item.value == value});
        if (arr.length !== 1) {
            return undefined;
        }
        if(Object.is(codelist.codelistType,'STATIC')){
            return this.$t('codelist.'+codelist.srfkey+'.'+arr[0].value);
        }else{
            return arr[0].text;
        }
    }

    /**
     * 生命周期
     *
1148
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1149
     */
ibizdev's avatar
ibizdev committed
1150
    public created(): void {
ibizdev's avatar
ibizdev committed
1151 1152 1153 1154 1155 1156
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
1157
     *  @memberof MainBase
ibizdev's avatar
ibizdev committed
1158
     */    
ibizdev's avatar
ibizdev committed
1159
    public afterCreated(){
ibizdev's avatar
ibizdev committed
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
        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.remove(data);
                }
                if (Object.is('save', action)) {
                    this.save(data);
                }
            });
        }
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
        if(AppCenterService && AppCenterService.getMessageCenter()){
            this.appStateEvent = AppCenterService.getMessageCenter().subscribe(({ name, action, data }) =>{
                if(!Object.is(name,"WFUser")){
                    return;
                }
                if(Object.is(action,'appRefresh')){
                    this.refresh([data]);
                }
            })
        }
ibizdev's avatar
ibizdev committed
1187 1188 1189 1190 1191
    }

    /**
     * vue 生命周期
     *
1192
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1193
     */
ibizdev's avatar
ibizdev committed
1194
    public destroyed() {
ibizdev's avatar
ibizdev committed
1195 1196 1197 1198 1199 1200
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
1201
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1202
     */
ibizdev's avatar
ibizdev committed
1203
    public afterDestroy() {
ibizdev's avatar
ibizdev committed
1204 1205 1206
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
1207 1208 1209
        if(this.appStateEvent){
            this.appStateEvent.unsubscribe();
        }
ibizdev's avatar
ibizdev committed
1210 1211 1212 1213 1214 1215
    }

    /**
     * 获取选中行胡数据
     *
     * @returns {any[]}
1216
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1217
     */
ibizdev's avatar
ibizdev committed
1218
    public getSelection(): any[] {
ibizdev's avatar
ibizdev committed
1219 1220 1221 1222 1223 1224 1225 1226
        return this.selections;
    }

    /**
     * 行双击事件
     *
     * @param {*} $event
     * @returns {void}
1227
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1228
     */
ibizdev's avatar
ibizdev committed
1229
    public rowDBLClick($event: any): void {
ibizdev's avatar
ibizdev committed
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
        if (!$event || this.actualIsOpenEdit || Object.is(this.gridRowActiveMode,0)) {
            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}
1251
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1252
     */
ibizdev's avatar
ibizdev committed
1253
    public select($event: any): void {
ibizdev's avatar
ibizdev committed
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
        if (!$event) {
            return;
        }
        this.selections = [];
        this.selections = [...JSON.parse(JSON.stringify($event))];
        this.$emit('selectionchange', this.selections);
    }

    /**
     * 复选框数据全部选中
     *
     * @param {*} $event
1266
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1267
     */
ibizdev's avatar
ibizdev committed
1268
    public selectAll($event: any): void {
ibizdev's avatar
ibizdev committed
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
        if (!$event) {
            return;
        }
        this.selections = [];
        this.selections = [...JSON.parse(JSON.stringify($event))];
        this.$emit('selectionchange', this.selections);
    }

    
    /**
     * 行单击选中
     *
     * @param {*} $event
     * @returns {void}
1283
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1284
     */
ibizdev's avatar
ibizdev committed
1285
    public rowClick($event: any, ifAlways: boolean = false): void {
ibizdev's avatar
ibizdev committed
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
        if (!ifAlways && (!$event || this.actualIsOpenEdit)) {
            return;
        }
        if(this.stopRowClick) {
            this.stopRowClick = false;
            return;
        }
        if(this.isSingleSelect){
            this.selections = [];
        }
        // 已选中则删除,没选中则添加
        let selectIndex = this.selections.findIndex((item:any)=>{
1298
            return Object.is(item.wfuser,$event.wfuser);
ibizdev's avatar
ibizdev committed
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
        });
        if (Object.is(selectIndex,-1)){
          this.selections.push(JSON.parse(JSON.stringify($event)));
        } else {
          this.selections.splice(selectIndex,1);
        }

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

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


    /**
     * 页面变化
     *
     * @param {*} $event
     * @returns {void}
1325
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1326
     */
ibizdev's avatar
ibizdev committed
1327
    public pageOnChange($event: any): void {
ibizdev's avatar
ibizdev committed
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
        if (!$event) {
            return;
        }
        if ($event === this.curPage) {
            return;
        }
        this.curPage = $event;
        this.load({});
    }

    /**
     * 分页条数变化
     *
     * @param {*} $event
     * @returns {void}
1343
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1344
     */
ibizdev's avatar
ibizdev committed
1345
    public onPageSizeChange($event: any): void {
ibizdev's avatar
ibizdev committed
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
        if (!$event) {
            return;
        }
        if ($event === this.limit) {
            return;
        }
        this.limit = $event;
        if (this.curPage === 1) {
            this.load({});
        }
    }

    /**
     * 分页刷新
     *
1361
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1362
     */
ibizdev's avatar
ibizdev committed
1363
    public pageRefresh(): void {
ibizdev's avatar
ibizdev committed
1364 1365 1366 1367 1368 1369 1370
        this.load({});
    }

    /**
     * 排序变化
     *
     * @param {{ column: any, prop: any, order: any }} { column, prop, order }
1371
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1372
     */
ibizdev's avatar
ibizdev committed
1373
    public onSortChange({ column, prop, order }: { column: any, prop: any, order: any }): void {
ibizdev's avatar
ibizdev committed
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
        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}
1388
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1389
     */
ibizdev's avatar
ibizdev committed
1390
    public onRowClassName({ row, rowIndex }: { row: any, rowIndex: any }): string {
ibizdev's avatar
ibizdev committed
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
        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
1403
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1404
     */
ibizdev's avatar
ibizdev committed
1405
	public uiAction(row: any, tag: any, $event: any) {
1406
        // this.rowClick(row, true);
1407
        $event.stopPropagation();
ibizdev's avatar
ibizdev committed
1408 1409 1410 1411 1412
    }

    /**
     * 设置列状态
     *
1413
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1414
     */
ibizdev's avatar
ibizdev committed
1415
    public setColState() {
ibizdev's avatar
ibizdev committed
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
		const _data: any = localStorage.getItem('wf_user_main_grid');
		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);
				}
			});
		}
    }

    /**
     * 列变化
     *
1431
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1432
     */
ibizdev's avatar
ibizdev committed
1433
    public onColChange() {
ibizdev's avatar
ibizdev committed
1434 1435 1436 1437 1438 1439 1440 1441
        localStorage.setItem('wf_user_main_grid', JSON.stringify(this.allColumns));
    }

    /**
     * 获取列状态
     *
     * @param {string} name
     * @returns {boolean}
1442
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1443
     */
ibizdev's avatar
ibizdev committed
1444
    public getColumnState(name: string): boolean {
ibizdev's avatar
ibizdev committed
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
        let column = this.allColumns.find((col: any) =>
            Object.is(name, col.name)
        );
        return column.show ? true : false;
    }

    /**
     * 表格列是否自适应布局
     *
     * @readonly
     * @type {boolean}
1456
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1457 1458 1459 1460 1461 1462 1463 1464 1465
     */
    get adaptiveState(): boolean {
        return !this.allColumns.find((column: any) => column.show && Object.is(column.util, 'STAR'));
    }

    /**
     * 保存
     *
     * @param {*} $event
1466
     * @returns {Promise<any>}
1467
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1468
     */
1469
    public async save(args: any[], params?: any, $event?: any, xData?: any){
ibizdev's avatar
ibizdev committed
1470
        let _this = this;
1471 1472 1473 1474 1475 1476
        // 拷贝模式
        if(_this.viewparams && _this.viewparams.copymode && Object.is(_this.viewparams.copymode,'true') && _this.items && _this.items.length >0){
            for (const item of _this.items) {
                item.rowDataState = 'create';
            }
        }
1477 1478 1479 1480 1481 1482 1483
        if(_this.items && _this.items.length >0){
            for (const item of _this.items) {
                if(Object.is(item.rowDataState, 'update')){
                    _this.updateDefault(item);
                }
            }
        }
1484
        if(!await this.validateAll()){
1485
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.rulesException') as string) });
1486 1487 1488 1489 1490 1491 1492 1493 1494
            return [];
        }
        let successItems:any = [];
        let errorItems:any = [];
        let errorMessage:any = [];
        for (const item of _this.items) {
            try {
                if(Object.is(item.rowDataState, 'create')){
                    if(!this.createAction){
1495
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserGridView'+(this.$t('app.gridpage.notConfig.createAction') as string) });
1496 1497 1498 1499 1500 1501 1502
                    }else{
                      Object.assign(item,{viewparams:this.viewparams});
                      let response = await this.service.add(this.createAction, JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator);
                      successItems.push(JSON.parse(JSON.stringify(response.data)));
                    }
                }else if(Object.is(item.rowDataState, 'update')){
                    if(!this.updateAction){
1503
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserGridView'+(this.$t('app.gridpage.notConfig.updateAction') as string) });
1504 1505 1506 1507 1508
                    }else{
                        Object.assign(item,{viewparams:this.viewparams});
                        if(item.wfuser){
                            Object.assign(this.context,{wfuser:item.wfuser});
                        }
1509
                        let response = await this.service.update(this.updateAction,JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator);
1510 1511
                        successItems.push(JSON.parse(JSON.stringify(response.data)));
                    }
ibizdev's avatar
ibizdev committed
1512
                }
1513 1514 1515
            } catch (error) {
                errorItems.push(JSON.parse(JSON.stringify(item)));
                errorMessage.push(error);
ibizdev's avatar
ibizdev committed
1516
            }
1517 1518 1519 1520
        }
        this.$emit('save', successItems);
        this.refresh([]);
        if(errorItems.length === 0){
1521
            this.$Notice.success({ title: '', desc: (this.$t('app.commonWords.saveSuccess') as string) });
1522 1523
        }else{
          errorItems.forEach((item:any,index:number)=>{
1524
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: errorMessage[index].data.message });
1525 1526 1527 1528
            console.error(errorMessage[index]);
          });
        }
        return successItems;
ibizdev's avatar
ibizdev committed
1529 1530
    }

1531 1532 1533 1534 1535
    /**
     * 新建行
     *
     * @param {*} $event
     * @returns {void}
1536
     * @memberof MainBase
1537 1538 1539
     */
    public newRow(args: any[], params?: any, $event?: any, xData?: any): void {
        if(!this.loaddraftAction){
1540
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserGridView'+(this.$t('app.gridpage.notConfig.loaddraftAction') as string) });
1541 1542 1543 1544 1545 1546 1547 1548
            return;
        }
        let _this = this;
        Object.assign(args[0],{viewparams:this.viewparams});
        let post: Promise<any> = this.service.loadDraft(this.loaddraftAction, JSON.parse(JSON.stringify(this.context)), args[0], this.showBusyIndicator);
        post.then((response: any) => {
            if (!response.status || response.status !== 200) {
                if (response.errorMessage) {
1549
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.errorMessage });
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
                }
                return;
            }
            const data = response.data;
            this.createDefault(data);
            data.rowDataState = "create";
            _this.items.push(data);
            _this.gridItemsModel.push(_this.getGridRowModel());
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
            if (!response || !response.status || !response.data) {
1563
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574
                return;
            }
        });
    }

    /**
     * 表格编辑项值变更
     *  
     * @param row 行数据
     * @param {{ name: string, value: any }} $event
     * @returns {void}
1575
     * @memberof MainBase
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595
     */
    public onGridItemValueChange(row: any,$event: { name: string, value: any },rowIndex: number): void {
        if (!$event) {
            return;
        }
        if (!$event.name || Object.is($event.name, '') || !row.hasOwnProperty($event.name)) {
            return;
        }
        row[$event.name] = $event.value;
        this.gridEditItemChange(row, $event.name, $event.value, rowIndex);
    }

    /**
     * 表格编辑项值变化
     *
     * @public
     * @param row 行数据
     * @param property 列编辑项名
     * @param row 列编辑项值
     * @returns {void}
1596
     * @memberof MainBase
1597 1598 1599
     */
    public gridEditItemChange(row: any, property: string, value: any, rowIndex: number){
        row.rowDataState = row.rowDataState ? row.rowDataState : "update" ;
1600 1601 1602 1603 1604
        if(Object.is(row.rowDataState,"update")){
            if(!value && this.defaultUpdateItems.includes(property)){
                row.hasUpdated = true;
            }
        }
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
        this.validate(property,row,rowIndex);
    }

    /**
     * 表格编辑项更新
     *
     * @param {string} mode 界面行为名称
     * @param {*} [data={}] 请求数据
     * @param {string[]} updateDetails 更新项
     * @param {boolean} [showloading] 是否显示加载状态
     * @returns {void}
1616
     * @memberof MainBase
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626
     */
    public updateGridEditItem(mode: string, data: any = {}, updateDetails: string[], showloading?: boolean): void {
        if (!mode || (mode && Object.is(mode, ''))) {
            return;
        }
        const arg: any = JSON.parse(JSON.stringify(data));
        Object.assign(arg,{viewparams:this.viewparams});
        const post: Promise<any> = this.service.frontLogic(mode,JSON.parse(JSON.stringify(this.context)),arg, showloading);
        post.then((response: any) => {
            if (!response || response.status !== 200) {
1627
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.gridpage.formitemFailed') as string) });
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644
                return;
            }
            const _data: any = response.data;
            if(!_data){
                return;
            }
            updateDetails.forEach((name: string) => {
                if (!_data.hasOwnProperty(name)) {
                    return;
                }
                data[name] = _data[name];
            });
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
            if (!response || !response.status || !response.data) {
1645
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1646 1647 1648 1649
                return;
            }
        });
    }
ibizdev's avatar
ibizdev committed
1650 1651 1652 1653 1654 1655

    /**
     * 获取对应行class
     *
     * @param {*} $args row 行数据,rowIndex 行索引
     * @returns {void}
1656
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1657
     */
ibizdev's avatar
ibizdev committed
1658
    public getRowClassName(args:{row: any,rowIndex: number}){
ibizdev's avatar
ibizdev committed
1659 1660 1661 1662 1663
        let isSelected = this.selections.some((item:any)=>{
            return Object.is(item.wfuser,args.row.wfuser);
        });
        return isSelected ? "grid-selected-row" : "";
    }
1664

1665 1666 1667 1668 1669 1670 1671 1672
    /**
     * 获取对应列class
     *
     * @param {*} $args row 行数据,column 列数据,rowIndex 行索引,列索引
     * @returns {void}
     * @memberof MainBase
     */
    public getCellClassName(args:{row: any, column: any, rowIndex: number, columnIndex:number}){
1673 1674 1675 1676 1677 1678 1679 1680 1681
        if(args.column.property){
          let col = this.allColumns.find((item:any)=>{
              return Object.is(args.column.property,item.name);
          })
          if(col !== undefined){
              if(col.isEnableRowEdit && this.actualIsOpenEdit ){
                  return 'edit-cell';
              }
          }
1682
        }
1683
        return 'info-cell';
1684 1685
    }

1686 1687 1688
    /**
     * 新建默认值
     * @param {*}  row 行数据
1689
     * @memberof MainBase
1690 1691 1692
     */
    public createDefault(row: any){                    
    }
1693 1694 1695 1696 1697 1698 1699 1700

    /**
     * 更新默认值
     * @param {*}  row 行数据
     * @memberof MainBase
     */
    public updateDefault(row: any){                    
    }
ibizdev's avatar
ibizdev committed
1701 1702 1703 1704 1705 1706
}
</script>

<style lang='less'>
@import './main-grid.less';
</style>