CONTROL-BASE.vue.ftl 17.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
<template>
    <div class="app-data-view">
<#if ctrl.render??><#t>
        ${ctrl.render.code}
<#else><#t>
  <#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>
        <div class="bar-container">
          <row class="page-sort-bar" :gutter="10" type="flex" justify="start" style="margin:0px;" >
    <#if ctrl.getPSDEDataViewDataItems?? && ctrl.getPSDEDataViewDataItems()??>
      <#list ctrl.getPSDEDataViewDataItems() as dataItem>
        <#if dataItem.getPSAppDEField?? && dataItem.getPSAppDEField()?? && !dataItem.getPSAppDEField().isKeyField()>
            <i-col :class="getsortClass('${dataItem.getPSDEField().getCodeName()?lower_case}')" @click.native="sortClick('${dataItem.getPSDEField().getCodeName()?lower_case}')">
              <span class="sort-field-text">{{$t('entities.${appde.getCodeName()?lower_case}.fields.${dataItem.getPSDEField().getCodeName()?lower_case}')}}</span>
              <span class="caret-wrapper">
                <Icon type="md-arrow-dropup" />
                <Icon type="md-arrow-dropdown" />
              </span>
            </i-col>
        </#if>
      </#list>
    </#if>
          </row>
        </div>
  </#if>
        <row class="data-view-container" v-if="items.length > 0" :gutter="20" type="flex" justify="start" style="margin:0px;">
            <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)">
                        <#if ctrl.getItemPSLayoutPanel()??>
                        <#assign panel = ctrl.getItemPSLayoutPanel()>
                        <layout_${panel.getName()} name='${panel.name}' :data="item"></layout_${panel.getName()}>
                        <#elseif ctrl.itemRender??>
                        ${ctrl.itemRender.code}
                        <#else>
                        <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>
                        </#if>
                    </el-card>
                </i-col>
            </a>
        </row>
        <div v-else class="app-data-empty">暂无数据</div>
</#if>
  </div>
</template>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>
    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getDatas(): any[] {
        return this.selections;
    }

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

    /**
     * 是否默认选中第一条数据
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
89
    @Prop({ default: false }) public isSelectFirstDefault!: boolean;
90 91 92 93 94 95 96

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
97
    @Prop({ default: true }) public showBusyIndicator?: boolean;
98 99 100 101 102 103 104

    /**
     * 部件行为--create
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
105
    @Prop() public createAction!: string;
106 107 108 109 110 111 112

    /**
     * 部件行为--remove
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
113
    @Prop() public removeAction!: string;
114 115 116 117 118 119 120

    /**
     * 部件行为--update
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
121
    @Prop() public updateAction!: string;
122 123 124 125 126 127 128

    /**
     * 部件行为--fetch
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
129
    @Prop() public fetchAction!: string;
130 131 132 133 134 135 136

    /**
     * 是否单选
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
137
    @Prop() public isSingleSelect?: boolean;
138 139 140 141 142 143 144

    /**
     * 数据
     *
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
145
    public items: any[] = [];
146 147 148 149 150 151 152

    /**
     * 是否支持分页
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
153
    public isEnablePagingBar: boolean = ${ctrl.isEnablePagingBar()?c};;
154 155 156 157 158 159 160

    /**
     * 总条数
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
161
    public totalRecord: number = 0;
162 163 164 165 166 167

    /**
     * 选中数组
     * @type {Array<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
168
    public selections: Array<any> = [];
169 170 171 172 173 174 175

    /**
     * 当前页
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
176
    public curPage: number = 1;
177 178 179 180 181 182 183

    /**
     * 分页条数
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
184
    public limit: number = ${ctrl.getPagingSize()?c};
185 186 187 188 189 190 191

    /**
     * 排序方向
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */    
192
    public sortDir:string = '<#if ctrl.getMinorSortDir()??>${ctrl.getMinorSortDir()?lower_case}</#if>';
193 194 195 196 197 198 199

    /**
     * 排序字段
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */    
200
    public sortField: string = '<#if ctrl.getMinorSortPSDEF()??>${ctrl.getMinorSortPSDEF().getCodeName()?lower_case}</#if>';
201 202 203 204 205 206 207

    /**
     * 排序点击事件
     * @param {string} field 属性名
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
208
    public sortClick(field:string) {
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
        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 属性名
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
228
    public getsortClass(field:string) {
229 230 231 232 233 234 235 236 237 238 239 240 241 242
        if(this.sortField !== field || this.sortDir === ''){
            return '';
        }else if(this.sortDir === 'asc'){
            return 'sort-ascending'
        }else if(this.sortDir === 'desc'){
            return 'sort-descending'
        }
    }

    /**
     * Vue声明周期,组件挂载完毕
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
243
    public mounted () {
244 245 246 247 248 249 250 251
        this.afterMounted();
    }

    /**
     * 执行mounted后的逻辑
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */    
252
    public afterMounted(){
253 254 255 256 257 258 259 260 261 262 263 264 265 266
        <#if !ctrl.isEnablePagingBar()>
        this.$el.addEventListener('scroll', ()=> {
            if( this.$el.scrollTop +  this.$el.clientHeight  >=  this.$el.scrollHeight) {
                this.loadMore();
            }
        })
        </#if>
    }

    /**
     * Vue声明周期,组件创建完毕
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
267
    public created() {
268 269 270 271 272 273 274 275
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */    
276
    public afterCreated(){
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
        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)
                }
            });
        }
    }

    /**
	 * 加载更多
	 *
	 * @memberof ${srfclassname('${ctrl.codeName}')}
	 */
297
    public loadMore(){
298 299 300 301 302 303 304 305 306 307 308 309 310
        if(this.totalRecord>this.items.length)
        {
            this.curPage = ++this.curPage;
            this.load({});
        }
    }

    /**
     * 刷新
     *
     * @param {*} [opt={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
311
    public refresh(opt: any = {}) {
312 313 314 315 316 317 318 319 320
        this.curPage = 1;
        this.load(opt, true);
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
321
    public destroyed() {
322 323 324 325 326 327 328 329
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
330
    public afterDestroy() {
331 332 333 334 335 336 337 338 339 340 341
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

    /**
     * 表格数据加载
     *
342
     * @public
343 344 345 346
     * @param {*} [arg={}]
     * @param {boolean} [isReset=false] 是否重置items
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
347
    public load(opt: any = {}, isReset: boolean = false): void {
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
        if(!this.fetchAction){
            this.$Notice.error({ title: '错误', desc: '${view.getName()}视图列表fetchAction参数未配置' });
            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);
        let viewparamResult:any = Object.assign(arg,this.viewparams);
        const post: Promise<any> = this.service.search(this.fetchAction,JSON.parse(JSON.stringify(this.context)), {viewparams:viewparamResult}, this.showBusyIndicator);
        post.then((response: any) => {
            if (!response || response.status !== 200) {
                if (response.errorMessage) {
                    this.$Notice.error({ title: '错误', desc: response.errorMessage });
                }
                return;
            }
            const data: any = response.data;
            this.items = [];
            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);
                }
            }
            this.$emit('load', this.items);
            if(this.isSelectFirstDefault){
                this.handleClick(this.items[0]);
            }
        }, (response: any) => {
            if (response && response.status === 401) {
                return;
            }
            this.$Notice.error({ title: '错误', desc: response.errorMessage });
        });
    }

    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
408
    public async remove(datas: any[]): Promise<any> {
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
        if(!this.removeAction){
            this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表格removeAction参数未配置' });
            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) {
            dataInfo = dataInfo + ' 共' + _datas.length + '条数据';
        } else {
            dataInfo = dataInfo + '...' + ' 共' + _datas.length + '条数据';
        }

        const removeData = () => {
            let keys: any[] = [];
            _datas.forEach((data: any) => {
                keys.push(data.srfkey);
            });
WodahsOrez's avatar
WodahsOrez committed
453
            let _removeAction = keys.length > 1 ? 'removeBatch' : this.removeAction ;
454
            const context:any = JSON.parse(JSON.stringify(this.context));
455
            const post: Promise<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);
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
            return new Promise((resolve: any, reject: any) => {
                post.then((response: any) => {
                    if (!response || response.status !== 200) {
                        this.$Notice.error({ title: '', desc: '删除数据失败,' + response.info });
                        return;
                    } else {
                        this.$Notice.success({ title: '', desc: '删除成功!' });
                    }
                    //删除items中已删除的项
                    _datas.forEach((data: any) => {
                      this.items.some((item:any,index:number)=>{
                        if(Object.is(item.srfkey,data.srfkey)){
                          this.items.splice(index,1);
                                return true;
                            }
                        });
                    });
                    this.$emit('remove', null);
                    this.selections = [];
                    resolve(response);
                }).catch((response: any) => {
                    if (response && response.status === 401) {
                        return;
                    }
                    if (!response || !response.status || !response.data) {
                        this.$Notice.error({ title: '错误', desc: '系统异常' });
                        reject(response);
                        return;
                    }
                    reject(response);
                });
            });
        }

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

    /**
     * 选择数据
     * @memberof ${srfclassname('${ctrl.codeName}')}
     *
     */
507
    public handleClick(args: any) {
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
        args.isselected = !args.isselected;
        if(this.isSingleSelect) {
            this.items.forEach((item:any) =>{
                if(item.srfkey !== args.srfkey){
                    item.isselected =false;
                }
            })
        }
        this.selectchange();
    }

    /**
     * 双击数据
     * @memberof ${srfclassname('${ctrl.codeName}')}
     *
     */
524
    public handleDblClick(args: any) {
525 526 527 528 529 530 531 532
        this.$emit('rowdblclick', args);
    }

    /**
     * 触发事件
     * @memberof ${srfclassname('${ctrl.codeName}')}
     *
     */
533
    public selectchange() {
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
        this.selections = [];
        this.items.map((item: any) => {
            if (item.isselected) {
                this.selections.push(item);
            }
        });
        this.$emit('selectionchange', this.selections);
    }
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

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