CONTROL-BASE.vue.ftl 40.7 KB
Newer Older
1 2 3
<#ibizinclude>
../@MACRO/CONTROL/LANGBASE.vue.ftl
</#ibizinclude>
4 5
<template>
<#if ctrl.render??><#t>
6
    ${ctrl.render.code}
7
<#else><#t>
8
    <div class="app-data-view<#if ctrl.getPSSysCss?? && ctrl.getPSSysCss()??><#assign singleCss = ctrl.getPSSysCss()> ${singleCss.getCssName()}</#if>">
9 10 11 12 13 14 15 16 17
  <#assign hasSortBar = false />
  <#if ctrl.getPSDEDataViewDataItems?? && ctrl.getPSDEDataViewDataItems()??>
    <#list ctrl.getPSDEDataViewDataItems() as dataItem>
      <#if dataItem.getPSAppDEField?? && dataItem.getPSAppDEField()?? && !dataItem.getPSAppDEField().isKeyField()>
        <#assign hasSortBar = true />
      </#if>
    </#list>
  </#if>
  <#if hasSortBar>
18 19 20 21 22 23 24
    <app-sort-bar
        :sortModel="sortModel"
        :sortField="sortField"
        :sortDir="sortDir"
        entityName="${appde.getCodeName()?lower_case}"
        @clickSort="(val) => {sortClick(val);}">
    </app-sort-bar>
25
  </#if>
26
        <row class="data-view-container" v-show="items.length > 0" :gutter="20" type="flex" justify="start" style="margin:0px;">
Shine-zwj's avatar
Shine-zwj committed
27
        <#if ctrl.isEnableGroup?? && !ctrl.isEnableGroup()>
28 29 30
            <a v-for="(item,index) in items" :key="index" :href = "item.starturl">
                <i-col <#if ctrl.getCardColLG() gt 0> :lg="${ctrl.getCardColLG()?c}"</#if><#if ctrl.getCardColMD() gt 0> :md="${ctrl.getCardColMD()?c}"</#if><#if ctrl.getCardColSM() gt 0> :sm="${ctrl.getCardColSM()?c}"</#if><#if ctrl.getCardColXS() gt 0> :xs="${ctrl.getCardColXS()?c}"</#if> style="<#if ctrl.getCardHeight() gt 0>height: ${ctrl.getCardHeight()?c}<#else>min-height: 170</#if>px;<#if ctrl.getCardWidth() gt 0> width: ${ctrl.getCardWidth()?c}px;</#if>margin-bottom: 10px;">
                    <el-card shadow="always" :class="[ item.isselected === true ? 'isselected' : false, 'single-card-data' ]" @click.native="handleClick(item)" @dblclick.native="handleDblClick(item)">
31 32 33 34 35 36
  <#if ctrl.getItemPSLayoutPanel()??>
    <#assign panel = ctrl.getItemPSLayoutPanel()>
                        <@ibizindent blank=24>
                        ${P.getCtrlCode(panel, 'CONTROL.html').code}
                        </@ibizindent>
  <#elseif ctrl.itemRender??>
37
                        ${ctrl.itemRender.code}
38
  <#else>
39 40 41 42 43 44 45 46 47 48
                        <div class="data-view-item">
                            <img v-if="item.srficonpath" :src="item.srficonpath" class="single-card-img" />
                            <img v-else src="/assets/img/noimage.png" class="single-card-img" />
                            <div class="single-card-default">
                                <Tooltip :content="item.srfmajortext">
                                {{item.srfmajortext}}
                                </Tooltip>
                            </div>
                        </div>
                        <div class="data-view-item-action">
49
                            <template v-for="(action,index) in Object.keys(actionModel)">
50
                                <button type="info" :key="index" v-show="item[action].visabled" :disabled="item[action].disabled" @click="uiAction(item, action, $event)">
51 52
                                    <i :class="actionModel[action].icon" style="margin-right:2px;"></i>
                                    <span>{{actionModel[action].caption}}</span>
53 54
                                </button>
                            </template>
55
                        </div>
56
    </#if>
57 58 59
                    </el-card>
                </i-col>
            </a>
Shine-zwj's avatar
Shine-zwj committed
60 61
        <#elseif ctrl.isEnableGroup?? && ctrl.isEnableGroup()>
            <el-collapse>
62 63 64 65
                <el-collapse-item v-for="(group,index) in groupData" :key="index">
                    <template slot="title">
                    <div style="margin: 0 0 0 12px;"><b>{{group.group}}</b></div>
                    </template>
Shine-zwj's avatar
Shine-zwj committed
66 67
                    <div v-if="group.children.length > 0">
                        <a v-for="(item,i) in group.children" :key="i" :href="item.starturl">
68
                            <i-col  style="min-height: 170px;margin-bottom: 10px;">
Shine-zwj's avatar
Shine-zwj committed
69 70 71 72 73 74 75 76 77
                                <el-card shadow="always" :class="[ item.isselected === true ? 'isselected' : false, 'single-card-data' ]" @click.native="handleClick(item)" @dblclick.native="handleDblClick(item)">
                                <#if ctrl.getItemPSLayoutPanel()??>
                                    <#assign panel = ctrl.getItemPSLayoutPanel()>
                                    <@ibizindent blank=24>
                                    ${P.getCtrlCode(panel, 'CONTROL.html').code}
                                    </@ibizindent>
                                <#elseif ctrl.itemRender??>
                                    ${ctrl.itemRender.code}
                                <#else>
78 79 80 81 82 83 84 85 86 87
                                    <div class="data-view-item">
                                        <img v-if="item.srficonpath" :src="item.srficonpath" class="single-card-img" />
                                        <img v-else src="/assets/img/noimage.png" class="single-card-img" />
                                        <div class="single-card-default">
                                            <Tooltip :content="item.srfmajortext">
                                            {{item.srfmajortext}}
                                            </Tooltip>
                                        </div>
                                    </div>
                                    <div class="data-view-item-action">
88
                                        <template v-for="(action,index) in Object.keys(actionModel)">
89
                                            <button type="info" :key="index" v-show="item[action].visabled" :disabled="item[action].disabled" @click="uiAction(item, action, $event)">
90 91
                                                <i :class="actionModel[action].icon" style="margin-right:2px;"></i>
                                                <span>{{actionModel[action].caption}}</span>
92 93
                                            </button>
                                        </template>
Shine-zwj's avatar
Shine-zwj committed
94 95 96 97 98 99
                                    </div>
                                </#if>
                                </el-card>
                            </i-col>
                        </a>
                    </div>
100
                    <div v-else class="item-nodata">
101
                        {{ $t('<#if langbase??>${langbase}.nodata</#if>') }}
Shine-zwj's avatar
Shine-zwj committed
102 103 104 105
                    </div>
                </el-collapse-item>
            </el-collapse>
        </#if>
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
        <#if ctrl.getBatchPSDEToolbar?? && ctrl.getBatchPSDEToolbar()??>
            <div class="drag-filed" @mousedown="down">
                <row class='dataview-pagination'>
                    <div v-show="flag" class="batch-toolbar">
                    <#assign batchToolbar = ctrl.getBatchPSDEToolbar()/>
                    <@ibizindent blank=12>
                    ${P.getCtrlCode(batchToolbar, 'CONTROL.html').code}
                    </@ibizindent>
                    </div>
                    <div class="dataview-pagination-icon">
                        <Icon type="md-code-working" @click="onClick"/>
                    </div>
                </row>
            </div>
        </#if>
121
        </row>
122
        <div v-show="items.length == 0" class="app-data-empty">
123 124 125 126 127 128 129 130 131 132
        {{ $t('<#if langbase??>${langbase}.nodata</#if>') }}
        <#if ctrl.getQuickPSDEToolbar?? && ctrl.getQuickPSDEToolbar()??>
            <span class="quick-toolbar">
                <#assign quickToolbar = ctrl.getQuickPSDEToolbar()/>
                <@ibizindent blank=12>
                ${P.getCtrlCode(quickToolbar, 'CONTROL.html').code}
                </@ibizindent>
            </span>
        </#if>
        </div>
133
        <el-backtop target=".content-container .app-data-view"></el-backtop> 
134
  </div>
135
</#if>
136
</template>
137
// 基于 @CONTROL/数据视图/CONTROL-BASE.vue.ftl 生成
Shine-zwj's avatar
Shine-zwj committed
138
<#assign import_block>
139
import CodeListService from "@/codelist/codelist-service";
Shine-zwj's avatar
Shine-zwj committed
140
</#assign>
141 142 143
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>
144 145 146 147 148 149 150

    /**
     * 代码表服务对象
     *
     * @type {CodeListService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
RedPig97's avatar
RedPig97 committed
151
    public codeListService:CodeListService = new CodeListService();
152

153 154 155 156 157 158
    /**
     * 界面UI服务对象
     *
     * @type {${srfclassname('${appde.getCodeName()}')}UIService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
RedPig97's avatar
RedPig97 committed
159
    public appUIService:${srfclassname('${appde.getCodeName()}')}UIService = new ${srfclassname('${appde.getCodeName()}')}UIService();
160

161 162 163 164
    /**
     * 获取多项数据
     *
     * @returns {any[]}
KK's avatar
KK committed
165
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
166 167 168 169 170 171 172 173 174
     */
    public getDatas(): any[] {
        return this.selections;
    }

    /**
     * 获取单项树
     *
     * @returns {*}
KK's avatar
KK committed
175
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
176 177 178 179 180 181 182 183 184
     */
    public getData(): any {
        return null;
    }

    /**
     * 是否默认选中第一条数据
     *
     * @type {boolean}
KK's avatar
KK committed
185
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
186
     */
187
    @Prop({ default: false }) public isSelectFirstDefault!: boolean;
188 189 190 191 192

    /**
     * 显示处理提示
     *
     * @type {boolean}
KK's avatar
KK committed
193
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
194
     */
195
    @Prop({ default: true }) public showBusyIndicator?: boolean;
196 197 198 199 200

    /**
     * 部件行为--create
     *
     * @type {string}
KK's avatar
KK committed
201
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
202
     */
203
    @Prop() public createAction!: string;
204 205 206 207 208

    /**
     * 部件行为--remove
     *
     * @type {string}
KK's avatar
KK committed
209
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
210
     */
211
    @Prop() public removeAction!: string;
212 213 214 215 216

    /**
     * 部件行为--update
     *
     * @type {string}
KK's avatar
KK committed
217
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
218
     */
219
    @Prop() public updateAction!: string;
220 221 222 223 224

    /**
     * 部件行为--fetch
     *
     * @type {string}
KK's avatar
KK committed
225
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
226
     */
227
    @Prop() public fetchAction!: string;
228

229 230 231 232 233 234 235
<#if view.getPSAppViewLogics?? && view.getPSAppViewLogics()??>
  <#list view.getPSAppViewLogics() as logic>
    <#if logic.getPFLogicCodeType() == 'APP_NEWDATA'>
    /**
     * 打开新建数据视图
     *
     * @type {any}
KK's avatar
KK committed
236
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
237 238 239 240 241 242 243 244
     */
    @Prop() public newdata: any;
    </#if>
    <#if logic.getPFLogicCodeType() == 'APP_OPENDATA'>
    /**
     * 打开编辑数据视图
     *
     * @type {any}
KK's avatar
KK committed
245
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
246 247 248 249 250 251 252 253 254 255
     */
    @Prop() public opendata: any;
    </#if>
  </#list>
</#if>

    /**
     * this引用
     *
     * @type {number}
KK's avatar
KK committed
256
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
257 258 259
     */
    public thisRef: any = this;

Shine-zwj's avatar
Shine-zwj committed
260 261 262 263 264 265 266
<#if ctrl.isEnableGroup?? && ctrl.isEnableGroup()>
    /**
     * 分组属性
     * 
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
267
    public groupField: string = "<#if ctrl.getGroupPSDEField?? && ctrl.getGroupPSDEField()??>${ctrl.getGroupPSDEField().getCodeName()?lower_case}</#if>";
268 269

    /**
270
     * 分组属性是否配置代码表
271 272 273 274
     * 
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
275
    public groupFieldCodelist: boolean = <#if ctrl.getGroupPSDEField()?? && ctrl.getGroupPSDEField().getPSCodeList?? && ctrl.getGroupPSDEField().getPSCodeList()??>true<#else>false</#if>;
276

277 278 279 280 281 282 283
    /**
     * 分组数据
     * 
     * @type {Array<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public groupData: Array<any> = [];
284
    
285 286 287 288 289 290
    /**
     * 分组模式
     * 
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
291
    public groupMode: string = "<#if ctrl.getGroupMode?? && ctrl.getGroupMode()??>${ctrl.getGroupMode()}</#if>";
292

293 294 295 296 297 298
    /**
     * 分组方法
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public group(){
299 300 301 302 303 304
        let _this:any = this;
        if(_this.drawGroup && _this.drawGroup instanceof Function && Object.is(_this.groupMode,"AUTO")){
            _this.drawGroup();
        }else if(_this.drawCodelistGroup && _this.drawCodelistGroup instanceof Function && Object.is(_this.groupMode,"CODELIST")){
            _this.drawCodelistGroup();
        }
305
    }
Shine-zwj's avatar
Shine-zwj committed
306
</#if>
307 308 309 310 311 312 313 314
    /**
     * 拖拽元素对象
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public dragEle:any;

315 316

    /**
317
     * 拖拽后位置left
318
     *
319
     * @type {boolean}
320
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
321 322
     */
    public leftP:any;
323 324

    /**
325 326 327 328 329 330 331 332 333
     * 拖拽后位置top
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public topP:any;

    /**
     * 拖拽标识
334
     * 
335
     * @type {boolean}
336 337
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
338
    public dragflag:boolean=false;
Shine-zwj's avatar
Shine-zwj committed
339

340
    /**
341
     * 为拖拽不是点击
342
     * 
343
     * @type {boolean}
Shine-zwj's avatar
Shine-zwj committed
344
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
345
     */
346 347 348 349 350 351 352 353 354 355
    public moveflag:boolean = false;
<#if ctrl.getGroupMode?? && ctrl.getGroupMode() == 'CODELIST'>

    /**
     * 分组代码表
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */ 
    public groupCodelist: any = {<#if ctrl.getGroupPSCodeList?? && ctrl.getGroupPSCodeList()??>type:'${ctrl.getGroupPSCodeList().getCodeListType()}',tag:'${ctrl.getGroupPSCodeList().getCodeName()}'</#if>};
Shine-zwj's avatar
Shine-zwj committed
356 357 358 359 360 361 362 363

    /**
     * 根据分组代码表绘制分组列表
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public async drawCodelistGroup(){
        let groups: Array<any> = [];
364
        let fields: Array<any> = [];
Shine-zwj's avatar
Shine-zwj committed
365 366
        let groupTree:Array<any> = [];
        let data:Array<any> = [...this.items];
367 368 369 370 371 372
        if(Object.keys(this.groupCodelist).length > 0){
            let groupCodelist: any = await this.codeListService.getDataItems(this.groupCodelist);
            groups = Util.deepCopy(groupCodelist);
        }
        if(groups.length == 0){
            console.warn("分组数据无效");
Shine-zwj's avatar
Shine-zwj committed
373 374 375 376
        }
        groups.forEach((group: any,i: number)=>{
            let children:Array<any> = [];
            data.forEach((item: any,j: number)=>{
377 378
                if(this.groupFieldCodelist){
                    if(Object.is(group.label,item[this.groupField])) {
379 380
                        children.push(item);
                    }
381
                }else if(Object.is(group.value,item[this.groupField])){
Shine-zwj's avatar
Shine-zwj committed
382 383 384 385 386 387 388 389 390 391 392
                    children.push(item);
                }
            });
            const tree: any ={
                group: group.label,
                children: children
            }
            groupTree.push(tree);
        });
        let child:Array<any> = [];
        data.forEach((item: any)=>{
393
            let i: number = 0;
394
            if(this.groupFieldCodelist){
395
                i = groups.findIndex((group: any)=>Object.is(group.label,item[this.groupField]));
396 397
            }else{
                i = groups.findIndex((group: any)=>Object.is(group.value,item[this.groupField]));
398
            }
Shine-zwj's avatar
Shine-zwj committed
399 400 401 402 403 404 405 406
            if(i < 0){
                child.push(item);
            }
        })
        const Tree: any = {
            group: this.$t('app.commonWords.other'),
            children: child
        }
407 408 409
        if(child && child.length > 0){
            groupTree.push(Tree);
        }
410
        this.groupData = [...groupTree];
Shine-zwj's avatar
Shine-zwj committed
411 412 413 414 415 416 417 418 419
    }
</#if>

<#if ctrl.getGroupMode?? && ctrl.getGroupMode() == 'AUTO'>
    /**
     * 绘制分组列表
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
420
    public async drawGroup(){
Shine-zwj's avatar
Shine-zwj committed
421 422
        let data:Array<any> = [...this.items];
        let groups:Array<any> = [];
423
        let fields: Array<any> = [];
Shine-zwj's avatar
Shine-zwj committed
424
        data.forEach((item: any)=>{
425
            if(item.hasOwnProperty(this.groupField)){
426
                groups.push(item[this.groupField]);
Shine-zwj's avatar
Shine-zwj committed
427 428 429
            }
        });
        groups = [...new Set(groups)];
430 431 432
        if(groups.length == 0){
            console.warn("分组数据无效");
        }
Shine-zwj's avatar
Shine-zwj committed
433 434 435 436
        let groupTree:Array<any> = [];
        groups.forEach((group: any,i: number)=>{
            let children:Array<any> = [];
            data.forEach((item: any,j: number)=>{
437
                if(Object.is(group,item[this.groupField])){
Shine-zwj's avatar
Shine-zwj committed
438 439 440
                    children.push(item);
                }
            });
441
            group = group ? group : this.$t('app.commonWords.other');
Shine-zwj's avatar
Shine-zwj committed
442 443 444 445 446 447
            const tree: any ={
                group: group,
                children: children
            }
            groupTree.push(tree);
        });
448
        this.groupData = [...groupTree];
Shine-zwj's avatar
Shine-zwj committed
449 450
    }
</#if>
451 452 453 454
    /**
     * 是否单选
     *
     * @type {boolean}
KK's avatar
KK committed
455
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
456
     */
457
    @Prop() public isSingleSelect?: boolean;
458 459 460 461 462 463 464 465 466 467
    
    <#if ctrl.getQuickPSDEToolbar?? && ctrl.getQuickPSDEToolbar()??>
      <#assign quickToolbar = ctrl.getQuickPSDEToolbar()/>
      ${P.getCtrlCode(quickToolbar, 'CONTROL.vue').code}
    </#if>

    <#if ctrl.getBatchPSDEToolbar?? && ctrl.getBatchPSDEToolbar()??>
      <#assign batchToolbar = ctrl.getBatchPSDEToolbar()/>
      ${P.getCtrlCode(batchToolbar, 'CONTROL.vue').code}
    </#if>
468 469 470 471 472

    /**
     * 数据
     *
     * @type {any[]}
KK's avatar
KK committed
473
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
474
     */
475
    public items: any[] = [];
476

477 478 479 480 481 482
    /**
     * 操作栏模型数据
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */ 
483
    public actionModel:any ={
484 485 486 487 488 489 490 491 492
    <#if ctrl.getPSDEDataViewItems?? && ctrl.getPSDEDataViewItems()??>
    <#list ctrl.getPSDEDataViewItems() as dataViewItem>
        <#if dataViewItem.getPSDEUIActionGroup?? && dataViewItem.getPSDEUIActionGroup()??>
         <#assign UIActionGrop = dataViewItem.getPSDEUIActionGroup() />
            <#if UIActionGrop.getPSUIActions?? && UIActionGrop.getPSUIActions()??>
            <#list UIActionGrop.getPSUIActions() as UIAction >
             "${UIAction.getUIActionTag()}":{name:"${UIAction.getUIActionTag()}",icon:"<#if UIAction.getPSSysImage()??><#assign img=UIAction.getPSSysImage() /><#if img.getCssClass()?? && (img.getCssClass()?length gt 0)>${img.getCssClass()}</#if></#if>",caption:"${UIAction.getCaption()}",disabled: false, visabled: true,noprivdisplaymode:<#if UIAction.getNoPrivDisplayMode(view)??>${UIAction.getNoPrivDisplayMode(view)}</#if>,dataaccaction: "<#if UIAction.getDataAccessAction()??>${UIAction.getDataAccessAction()}</#if>", actiontarget: "${UIAction.getActionTarget()}"},
            </#list>
            </#if>
493 494 495 496 497
        </#if>
    </#list>
    </#if>
    };

498 499 500 501
    /**
     * 是否支持分页
     *
     * @type {boolean}
KK's avatar
KK committed
502
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
503
     */
504
    public isEnablePagingBar: boolean = ${ctrl.isEnablePagingBar()?c};;
505 506 507 508 509

    /**
     * 总条数
     *
     * @type {number}
KK's avatar
KK committed
510
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
511
     */
512
    public totalRecord: number = 0;
513

tony001's avatar
tony001 committed
514 515 516 517
    /**
     * 加载的数据是否附加在items之后
     *
     * @type {boolean}
KK's avatar
KK committed
518
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
519 520 521
     */
    public isAddBehind:boolean = false;

522 523 524
    /**
     * 选中数组
     * @type {Array<any>}
KK's avatar
KK committed
525
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
526
     */
527
    public selections: Array<any> = [];
528 529 530 531 532

    /**
     * 当前页
     *
     * @type {number}
KK's avatar
KK committed
533
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
534
     */
535
    public curPage: number = 1;
536 537 538 539 540

    /**
     * 分页条数
     *
     * @type {number}
KK's avatar
KK committed
541
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
542
     */
543
    public limit: number = ${ctrl.getPagingSize()?c};
544 545 546 547 548

    /**
     * 排序方向
     *
     * @type {string}
KK's avatar
KK committed
549
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
550
     */    
551
    public sortDir:string = '<#if ctrl.getMinorSortDir()??>${ctrl.getMinorSortDir()?lower_case}</#if>';
552 553 554 555 556

    /**
     * 排序字段
     *
     * @type {string}
KK's avatar
KK committed
557
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
558
     */    
559
    public sortField: string = '<#if ctrl.getMinorSortPSDEF()??>${ctrl.getMinorSortPSDEF().getCodeName()?lower_case}</#if>';
560

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
<#if hasSortBar>
    <#if ctrl.getPSDEDataViewDataItems?? && ctrl.getPSDEDataViewDataItems()??>
    /**
     * 排序模型数据集
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
    public sortModel: any[] = [
        <#list ctrl.getPSDEDataViewDataItems() as dataItem>
            <#if dataItem.getPSAppDEField?? && dataItem.getPSAppDEField()?? && !dataItem.getPSAppDEField().isKeyField()>
                <#if !P.exists("sort", dataItem.getPSDEField().getCodeName(), "") >
        '${dataItem.getPSDEField().getCodeName()?lower_case}'<#if dataItem_has_next>,</#if>
                </#if>
            </#if>
        </#list>
    ]
    </#if>
</#if>

581 582 583 584 585 586 587 588 589
    /**
     * 应用状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public appStateEvent: Subscription | undefined;

590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
    /**
     * 默认隐藏批量操作工具栏
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public flag: boolean = false;

    /**
     * 更改批量操作工具栏显示状态
     *
     * @param $event
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public onClick($event: any){
        if(!this.moveflag){
            this.flag = !this.flag;
        } 
        this.moveflag = false;
    }

611 612 613 614
    /**
     * 排序点击事件
     * @param {string} field 属性名
     *
KK's avatar
KK committed
615
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
616
     */
617
    public sortClick(field:string) {
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
        if(this.sortField !== field){
            this.sortField = field;
            this.sortDir = 'asc';
        }else if(this.sortDir === 'asc'){
            this.sortDir = 'desc';
        }else if(this.sortDir === 'desc'){
            this.sortDir = '';
        }else{
            this.sortDir = 'asc';
        }
        this.refresh();
    }

    /**
     * 排序class变更
     * @param {string} field 属性名
     *
KK's avatar
KK committed
635
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
636
     */
637
    public getsortClass(field:string) {
638 639 640 641 642 643 644 645 646 647 648 649
        if(this.sortField !== field || this.sortDir === ''){
            return '';
        }else if(this.sortDir === 'asc'){
            return 'sort-ascending'
        }else if(this.sortDir === 'desc'){
            return 'sort-descending'
        }
    }

    /**
     * Vue声明周期,组件挂载完毕
     *
KK's avatar
KK committed
650
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
651
     */
652
    public mounted () {
653 654 655 656 657 658
        this.afterMounted();
    }

    /**
     * 执行mounted后的逻辑
     *
KK's avatar
KK committed
659
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
660
     */    
661
    public afterMounted(){
662
        this.$el.addEventListener('scroll', ()=> {
663
            <#if ctrl.getBatchPSDEToolbar?? && ctrl.getBatchPSDEToolbar()??>
664 665
            let el: any = this.$el.getElementsByClassName('dataview-pagination')[0];
            el.style.top = 40 + this.$el.scrollTop + 'px';
666 667
            </#if>
            <#if ctrl.isEnablePagingBar()>
668 669 670
            if( this.$el.scrollTop +  this.$el.clientHeight  >=  this.$el.scrollHeight) {
                this.loadMore();
            }
671
            </#if>
672
        })
673 674
    }

675 676


677 678 679
    /**
     * Vue声明周期,组件创建完毕
     *
KK's avatar
KK committed
680
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
681
     */
682
    public created() {
683
        this.afterCreated();
684 685 686
        this.$nextTick(()=>{
            this.mouseEvent();
        })
687 688 689 690 691
    }

    /**
     * 执行created后的逻辑
     *
KK's avatar
KK committed
692
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
693
     */    
694
    public afterCreated(){
695 696 697 698 699 700 701 702 703 704 705 706 707
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(this.name, tag)) {
                    return;
                }
                if (Object.is(action,'load')) {
                    this.refresh(data)
                }
                if (Object.is(action,'filter')) {
                    this.refresh(data)
                }
            });
        }
708 709 710 711 712 713 714 715 716 717
        if(AppCenterService && AppCenterService.getMessageCenter()){
            this.appStateEvent = AppCenterService.getMessageCenter().subscribe(({ name, action, data }) =>{
                if(!Object.is(name,"${ctrl.getPSAppDataEntity().getCodeName()}")){
                    return;
                }
                if(Object.is(action,'appRefresh')){
                    this.refresh([data]);
                }
            })
        }
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
    /**
     * 鼠标移动+放下
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public mouseEvent(){
        this.dragEle = document.getElementsByClassName('drag-filed')[0];
        document.onmousemove=(e:any)=>{
            if(this.dragflag){
                this.dragEle.style.left = (e.clientX - this.leftP) + 'px';
                this.dragEle.style.top = (e.clientY - this.topP) + 'px';
                this.moveflag = true;
            }
        }
        document.onmouseup=(e:any)=>{
            this.dragflag = false;
        }
    }

    /**
     * mousedown事件
     * 
     * @param $event
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public down(e:any){
        this.leftP = e.clientX - this.dragEle.offsetLeft;
        this.topP = e.clientY - this.dragEle.offsetTop;
        this.dragflag = true;
    }

751 752 753
    /**
	 * 加载更多
	 *
KK's avatar
KK committed
754
	 * @memberof ${srfclassname('${ctrl.codeName}')}Base
755
	 */
756
    public loadMore(){
757 758 759
        if(this.totalRecord>this.items.length)
        {
            this.curPage = ++this.curPage;
tony001's avatar
tony001 committed
760
            this.isAddBehind = true;
761 762 763 764 765 766 767
            this.load({});
        }
    }

    /**
     * 刷新
     *
768
     * @param {*} [args={}]
KK's avatar
KK committed
769
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
770
     */
771
    public refresh(args?: any) {
772
        this.curPage = 1;
773
        this.load(args, true);
774 775 776 777 778
    }

    /**
     * vue 生命周期
     *
KK's avatar
KK committed
779
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
780
     */
781
    public destroyed() {
782 783 784 785 786 787
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
KK's avatar
KK committed
788
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
789
     */
790
    public afterDestroy() {
791 792 793
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
794 795 796
        if(this.appStateEvent){
            this.appStateEvent.unsubscribe();
        }
797 798 799 800 801 802 803 804
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

    /**
     * 表格数据加载
     *
805
     * @public
806 807
     * @param {*} [arg={}]
     * @param {boolean} [isReset=false] 是否重置items
KK's avatar
KK committed
808
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
809
     */
Mosher's avatar
Mosher committed
810
    public async load(opt: any = {}, isReset: boolean = false): Promise<any> {
811
        if(!this.fetchAction){
812
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.list.notConfig.fetchAction') as string) });
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
            return;
        }      
        const arg: any = {...opt};
        const page: any = {};
        if (this.isEnablePagingBar) {
            Object.assign(page, { page: this.curPage-1, size: this.limit });
        }
        // 设置排序
        if (!Object.is(this.sortDir, '') && !Object.is(this.sortField, '')) {
          const sort: string = this.sortField+","+this.sortDir;
            Object.assign(page, { sort: sort });
        }
        Object.assign(arg, page);
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);
tony001's avatar
tony001 committed
829 830 831
        let tempViewParams:any = parentdata.viewparams?parentdata.viewparams:{};
        Object.assign(tempViewParams,JSON.parse(JSON.stringify(this.viewparams)));
        Object.assign(arg,{viewparams:tempViewParams});
Mosher's avatar
Mosher committed
832 833 834 835 836
        if (!(await this.handleCtrlEvents('onbeforeload', { data: arg }))) {
            return;
        }
        try {
            const response = await this.service.search(this.fetchAction,JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
837
            if (!response || response.status !== 200) {
Mosher's avatar
Mosher committed
838 839 840 841
                //  加载失败
                if (!(await this.handleCtrlEvents('onloaderror', { data: response.data ? response.data : [] }))) {
                    return;
                }
842 843
                if (response.data && response.data.message) {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
844 845 846
                }
                return;
            }
Mosher's avatar
Mosher committed
847 848 849 850
            //  加载成功
            if (!(await this.handleCtrlEvents('onloadsuccess', { data: response.data }))) {
                return;
            }
851
            const data: any = response.data;
tony001's avatar
tony001 committed
852 853 854
            if(!this.isAddBehind){
                this.items = [];
            }
855 856 857 858 859 860 861 862 863 864 865 866
            if (Object.keys(data).length > 0) {
                let datas = JSON.parse(JSON.stringify(data));
                datas.map((item: any) => {
                    Object.assign(item, { isselected: false });
                });
                this.totalRecord = response.total;
                if(isReset){
                    this.items = datas;
                }else{
                    this.items.push(...datas);
                }
            }
tony001's avatar
tony001 committed
867
            this.isAddBehind = false;
868 869 870
            this.items.forEach((item: any) => {
                Object.assign(item,this.getActionState(item));    
            })
871
            this.$emit('load', this.items);
872
            //在导航视图中,如已有选中数据,则右侧展开已选中数据的视图,如无选中数据则默认选中第一条
873
            if(this.isSelectFirstDefault){
874 875 876 877 878 879 880 881 882 883
                if(this.selections && this.selections.length > 0){
                    this.selections.forEach((select: any)=>{
                        const index = this.items.findIndex((item:any) => Object.is(item.srfkey,select.srfkey));
                        if(index != -1){
                            this.handleClick(this.items[index]);
                        }
                    })
                }else{
                    this.handleClick(this.items[0]);
                } 
884
            }
885 886
            <#if ctrl.isEnableGroup?? && ctrl.isEnableGroup()>
            this.group();
Shine-zwj's avatar
Shine-zwj committed
887
            </#if>
Mosher's avatar
Mosher committed
888 889 890 891 892 893 894 895 896 897
        } catch (response: any) {
            //  加载失败
            if (!(await this.handleCtrlEvents('onloaderror', { data: response && response.data ? response.data : [] }))) {
                return;
            }
            if (response && response.status === 401) {
                return;
            }
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data && response.data.message ? response.data.message : "" });
        }
898 899 900 901 902 903 904
    }

    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
KK's avatar
KK committed
905
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
906
     */
907
    public async remove(datas: any[]): Promise<any> {
908
        if(!this.removeAction){
909
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.gridpage.notConfig.removeAction') as string) });
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
            return;
        }
        let _datas:any[] = [];
        datas.forEach((record: any, index: number) => {
            if (Object.is(record.srfuf, '0')) {
                this.items.some((val: any, num: number) =>{
                    if(JSON.stringify(val) == JSON.stringify(record)){
                        this.items.splice(num,1);
                        return true;
                    }
                }); 
            }else{
               _datas.push(datas[index]);
            }
        });
        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) {
942
            dataInfo = dataInfo + ' ' + (this.$t('app.dataView.sum') as string) + _datas.length + (this.$t('app.dataView.data') as string);
943
        } else {
944
            dataInfo = dataInfo + '...' + ' ' + (this.$t('app.dataView.sum') as string) + _datas.length + (this.$t('app.dataView.data') as string);
945 946
        }

Mosher's avatar
Mosher committed
947
        const removeData = async () => {
948 949 950 951
            let keys: any[] = [];
            _datas.forEach((data: any) => {
                keys.push(data.srfkey);
            });
WodahsOrez's avatar
WodahsOrez committed
952
            let _removeAction = keys.length > 1 ? 'removeBatch' : this.removeAction ;
953
            const context:any = JSON.parse(JSON.stringify(this.context));
Mosher's avatar
Mosher committed
954
            try {
Mosher's avatar
Mosher committed
955
                if (!(await this.handleCtrlEvents('onbeforeremove', { data: keys }))) {
Mosher's avatar
Mosher committed
956 957 958 959
                    return;
                }
                const response: any = this.service.delete(_removeAction,Object.assign(context,{ ${ctrl.getPSAppDataEntity().codeName?lower_case}: keys.join(';') }),Object.assign({ ${ctrl.getPSAppDataEntity().codeName?lower_case}: keys.join(';') },{viewparams:this.viewparams}), this.showBusyIndicator);
                if (!response || response.status !== 200) {
Mosher's avatar
Mosher committed
960
                    if (!(await this.handleCtrlEvents('onremoveerror', { data: keys }))) {
961 962
                        return;
                    }
Mosher's avatar
Mosher committed
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
                    this.$Notice.error({ title: '', desc: (this.$t('app.commonWords.delDataFail') as string) + ',' + response.info });
                    return;
                }
                if (!(await this.handleCtrlEvents('onremovesuccess', { data: response.data }))) {
                    return;
                }
                this.$Notice.success({ title: '', desc: (this.$t('app.commonWords.deleteSuccess') as string) });
                //删除items中已删除的项
                _datas.forEach((data: any) => {
                    this.items.some((item:any,index:number)=>{
                        if(Object.is(item.srfkey,data.srfkey)){
                            this.items.splice(index,1);
                            <#if ctrl.isEnableGroup?? && ctrl.isEnableGroup()>
                            this.group();
                            </#if>
                            return true;
                        }
980 981
                    });
                });
Mosher's avatar
Mosher committed
982 983 984 985 986 987 988 989 990 991 992 993
                this.$emit('remove', null);
                this.selections = [];
                return response;
            } catch (response: any) {
                if (response && response.status === 401) {
                    return;
                }
                if (!response || !response.status || !response.data) {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
                }
                return response;
            }
994 995 996 997
        }

        dataInfo = dataInfo.replace(/[null]/g, '').replace(/[undefined]/g, '').replace(/[ ]/g, '');
        this.$Modal.confirm({
998 999
            title: (this.$t('app.commonWords.warning') as string),
            content: (this.$t('app.gridpage.confirmDel') as string) + ' ' + dataInfo + ',' + (this.$t('app.gridpage.notRecoverable') as string),
1000 1001 1002 1003 1004 1005 1006 1007
            onOk: () => {
                removeData();
            },
            onCancel: () => { }
        });
        return removeData;
    }

1008 1009 1010 1011 1012 1013

    /**
     * 保存
     *
     * @param {*} $event
     * @returns {Promise<any>}
KK's avatar
KK committed
1014
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1015 1016 1017 1018 1019 1020
     */
    public async save(args: any[], params?: any, $event?: any, xData?: any){
        let _this = this;
        let successItems:any = [];
        let errorItems:any = [];
        let errorMessage:any = [];
Mosher's avatar
Mosher committed
1021 1022 1023
        if (!(await this.handleCtrlEvents('onbeforesave', { data: _this.items }))) {
            return;
        }
1024 1025 1026 1027
        for (const item of _this.items) {
            try {
                if(Object.is(item.rowDataState, 'create')){
                    if(!this.createAction){
1028
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.list.notConfig.createAction') as string) });
1029 1030 1031 1032 1033 1034 1035
                    }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){
1036
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.list.notConfig.updateAction') as string) });
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
                    }else{
                        Object.assign(item,{viewparams:this.viewparams});
<#if de??>
                        if(item.${appde.getCodeName()?lower_case}){
                            Object.assign(this.context,{${appde.getCodeName()?lower_case}:item.${appde.getCodeName()?lower_case}});
                        }
</#if>
                        let response = await this.service.add(this.updateAction,JSON.parse(JSON.stringify(this.context)),item, this.showBusyIndicator);
                        successItems.push(JSON.parse(JSON.stringify(response.data)));
                    }
                }
            } catch (error) {
                errorItems.push(JSON.parse(JSON.stringify(item)));
                errorMessage.push(error);
            }
        }
        this.$emit('save', successItems);
        this.refresh();
        if(errorItems.length === 0){
Mosher's avatar
Mosher committed
1056 1057 1058
            if (!(await this.handleCtrlEvents('onsavesuccess', { data: successItems }))) {
                return;
            }
1059
            this.$Notice.success({ title: '', desc: (this.$t('app.commonWords.saveSuccess') as string) });
Mosher's avatar
Mosher committed
1060 1061 1062 1063 1064 1065 1066 1067
        } else {
            if (!(await this.handleCtrlEvents('onsaveerror', { data: errorItems }))) {
                return;
            }
            errorItems.forEach((item:any,index:number)=>{
                this.$Notice.error({ title: (this.$t('app.commonWords.saveFailed') as string), desc: item.majorentityname + (this.$t('app.commonWords.saveFailed') as string) + '!' });
                console.error(errorMessage[index]);
            });
1068 1069 1070 1071
        }
        return successItems;
    }

1072 1073 1074 1075 1076
    /**
     * 面板数据变化处理事件
     * @param {any} item 当前卡片数据
     * @param {any} $event 面板事件数据
     *
KK's avatar
KK committed
1077
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1078 1079 1080 1081 1082
     */
    public onPanelDataChange(item:any,$event:any) {
        Object.assign(item, $event, {rowDataState:'update'});
    }

1083 1084
    /**
     * 选择数据
KK's avatar
KK committed
1085
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1086 1087
     *
     */
1088
    public handleClick(args: any) {
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
        args.isselected = !args.isselected;
        if(this.isSingleSelect) {
            this.items.forEach((item:any) =>{
                if(item.srfkey !== args.srfkey){
                    item.isselected =false;
                }
            })
        }
        this.selectchange();
    }

    /**
     * 双击数据
KK's avatar
KK committed
1102
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1103 1104
     *
     */
1105
    public handleDblClick(args: any) {
1106 1107 1108 1109 1110
        this.$emit('rowdblclick', args);
    }

    /**
     * 触发事件
KK's avatar
KK committed
1111
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1112 1113
     *
     */
1114
    public selectchange() {
Mosher's avatar
Mosher committed
1115 1116 1117
        this.handleCtrlEvents('onselectionchange').then((res: boolean) => {
            if (!res) {
                return;
1118
            }
Mosher's avatar
Mosher committed
1119 1120 1121 1122 1123 1124 1125 1126
            this.selections = [];
            this.items.map((item: any) => {
                if (item.isselected) {
                    this.selections.push(item);
                }
            });
            this.$emit('selectionchange', this.selections);
        })
1127
    }
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150

    /**
     * 操作列界面行为
     *
     * @param {*} data
     * @param {*} tag
     * @param {*} $event
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
	public uiAction(data: any, tag: any, $event: any) {
        $event.stopPropagation();
        <#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()}(data, tag, $event);
        }
        </#if>
        </#list>
        </#if>
    }

1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
    /**
     * 获取界面行为权限状态
     *
     * @param {*} data 当前列表行数据
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public getActionState(data:any){
        let tempActionModel:any = JSON.parse(JSON.stringify(this.actionModel));
        let targetData:any = this.transformData(data);
        ViewTool.calcActionItemAuthState(targetData,tempActionModel,this.appUIService);
        return tempActionModel;
    }

1164 1165 1166 1167 1168 1169 1170
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL-BASE.style.ftl
</#ibizinclude>