CONTROL-BASE.vue.ftl 18.9 KB
Newer Older
ibizdev's avatar
ibizdev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
<#ibizinclude>
./CONTROL-BASE.template.ftl
</#ibizinclude>

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

    /**
     * 视图类型
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() protected viewType?: string | 'DEMOBMDVIEW' | 'DEMOBMDVIEW9' | 'DEMOBWFMDVIEW';

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop({ default: true }) protected showBusyIndicator?: boolean;

    /**
     * 部件行为--update
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() protected updateAction!: string;
    
    /**
     * 部件行为--fetch
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() protected fetchAction!: string;
    
    /**
     * 部件行为--remove
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() protected removeAction!: string;
    
    /**
     * 部件行为--load
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() protected loadAction!: string;
    
    /**
     * 部件行为--loaddraft
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() protected loaddraftAction!: string;
    
    /**
     * 部件行为--create
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() protected createAction!: string;

    /**
     * 部件样式
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop({default: '<#if ctrl.getMobListStyle?? && ctrl.getMobListStyle()??>${ctrl.getMobListStyle()}</#if>'}) protected controlStyle!: string | 'ICONVIEW'  | 'LISTVIEW' | 'SWIPERVIEW' | 'LISTVIEW2' | 'LISTVIEW3' | 'LISTVIEW4';

    /**
    *上级传递的选中项
    *@type {Array}
    *@memberof ${srfclassname('${ctrl.codeName}')}
    */
     @Prop() public selectedData?:Array<any>;


    /**
    * 新建打开视图
    *
    * @type {Function}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    @Prop() public newdata?: Function; 


    /**
    * 打开视图
    *
    * @type {Function}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    @Prop() public opendata?: Function; 


    /**
    * 当前选中数组
    *
    * @type {array}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public  selectdata :any = [];

    /**
    * 关闭行为
    *
    * @type {Function}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    @Prop() public close?:Function;


    /**
     * 布局大小
     * 
     * @memberof ${srfclassname('${ctrl.name}')}
     */    
    @Prop() public size?:string;


    /**
    * 是否为临时模式
    *
    * @type {boolean}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    @Prop({ default: false}) public isTempMode?:boolean;

    <#if view.getViewType()?? && view.getViewType()=='DEMOBPICKUPMDVIEW'>
    /**
    * 存放多数据选择数组(多选)
    *
    * @type {array}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public checkboxList:Array<string> = [];

    /**
    * 存放数据选择数组(单选)
    *
    * @type {object}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public radio:any = '';


    /**
    * 点击多选按钮触发
    *
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public change(){
        if(this.isMutli){
             let checkboxLists= this.items.filter((item,index)=>{
                  if(this.checkboxList.indexOf(item.srfkey)!=-1){
                    return true;
                  }else{
                    return false;
                  }
                })
          this.$emit('selectchange',checkboxLists);
        }else{
           let radioItem = this.items.filter((item,index)=>{return item.srfkey==this.radio});
           this.$emit('selectchange',radioItem);
        }
    }
    </#if>

    /**
    * 列表键值对
    *
    * @type {Map}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public listMap: any = new Map();

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

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

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

    /**
    * 判断底部数据是否全部加载完成,若为真,则 bottomMethod 不会被再次触发
    *
    * @type {number}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    get allLoaded() {
        return ((this.pageNumber + 1) * this.pageSize) >= this.pageTotal ? true : false;
    }

    /**
    * 底部状态
    *
    * @type {String}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    // public bottomStatus: String = "";

    /**
    * 顶部状态
    *
    * @type {String}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    // public topStatus: String = "";

    /**
    * 
    *
    * @type {Number}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    // public moveTranslate: Number = 0;

    /**
    * searchKey 搜索关键字
    *
    * @type {string}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
     public searchKey:string = '';

    /**
    * 列表数组
    *
    * @param {Array<any>}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public items:Array<any> =[];

    /**
    * 选中数组
    *
    * @param {Array<any>}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public selectedArray:Array<any> = [];

    /**
    * 多选计数
    *
    * @param {number}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public selectednumber:number =0;

    /**
    * 搜索行为
    *
    * @param {string}
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    @Prop() public searchAction?:string;

    /**
    * 是否为选择视图
    *
    * @param {boolean} 
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    @Prop() public isSelected?:boolean;

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

    /**
    * 单选选择值
    *
    * @param {string} 
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public selectedValue:string = ""; 
    
    /**
    * 底部改变状态
    * 
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public handleBottomChange(status: String) {
    //   this.bottomStatus = status;
    }

    /**
    * 顶部改变状态
    * 
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public handleTopChange(status: String) {
    //   this.moveTranslate = 1;
    //   this.topStatus = status;
    }

    /**
     * 上拉加载更多数据
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public async loadBottom(): Promise<any> {
        this.pageNumber++;
        let params = {};
        if (this.viewparams) {
            Object.assign(params, this.viewparams);
        }
        Object.assign(params, { query: this.searchKey, page: this.pageNumber, size: this.pageSize });
        let response: any = await this.load(params, 'bottom');
        let loadmoreBottom: any = this.$refs.loadmoreBottom;
        if (loadmoreBottom) {
            loadmoreBottom.complete();
        }
    }

    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public async remove(datas: any[]): Promise<any> {
        let arg: any = {};
        let keys: Array<string> = [];
        let infoStr: string = '';
        datas.forEach((data: any, index: number) => {
            keys.push(data.${appde.getKeyPSAppDEField().getCodeName()?lower_case});
            if (index < 5) {
                if (!Object.is(infoStr, '')) {
                    infoStr += '、';
                }
                <#if appde.getMajorPSAppDEField()??>
                infoStr += data.${appde.getMajorPSAppDEField().getCodeName()?lower_case};
                <#else>
                infoStr += data.srfmajortext;
                </#if>
            }
        });

        if (datas.length < 5) {
KK's avatar
KK committed
375
            infoStr = infoStr + this.$t('app.message.totle') + datas.length + this.$t('app.message.data');
ibizdev's avatar
ibizdev committed
376
        } else {
KK's avatar
KK committed
377
            infoStr = infoStr + '...' + this.$t('app.message.totle') + datas.length + this.$t('app.message.data');
ibizdev's avatar
ibizdev committed
378 379 380 381 382 383
        }
        return new Promise((resolve, reject) => {
            const _remove = async () => {
                let _context: any = { ${appde.getCodeName()?lower_case}: keys.join(';') }
                const response: any = await this.service.delete(this.removeAction, Object.assign({}, this.context, _context), arg, this.showBusyIndicator);
                if (response && response.status === 200) {
KK's avatar
KK committed
384
                    this.$notice.success((this.$t('app.message.deleteSccess') as string));
ibizdev's avatar
ibizdev committed
385 386 387 388 389 390 391 392 393
                    this.load();
                    resolve(response);
                } else {
                    this.$notice.error(response.message);
                    reject(response);
                }
            }

            this.$dialog.confirm({
KK's avatar
KK committed
394
                title: (this.$t('app.message.warning') as string),
KK's avatar
KK committed
395
                message: this.$t('app.message.confirmToDelete') + infoStr +','+ this.$t('app.message.unrecoverable') + '?',
ibizdev's avatar
ibizdev committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
            }).then(() => {
                _remove();
            }).catch(() => {
            });
        });
    }

    /**
     * 刷新数据
     *
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public refresh(): Promise<any> {
        return new Promise((resolve: any, reject: any) => {
            this.load().then((res) => {
                resolve(res);
            }).catch((error: any) => {
                reject(error);
            })
        })
    }

    /**
     * 快速搜索
     *
     * @param {string} query
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public async quickSearch(query: string): Promise<any> {
        this.searchKey = query;
        this.pageNumber = 0;
        const response = await this.load(Object.assign({ query: query }, { page: this.pageNumber, size: this.pageSize }), "init");
        return response;
    }

    /**
     * 数据加载
     *
     * @private
     * @param {*} [data={}]
     * @param {string} [type=""]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    private async load(data: any = {}, type: string = ""): Promise<any> {
        if (!data.page) {
            Object.assign(data, { page: this.pageNumber });
        }
        if (!data.size) {
            Object.assign(data, { size: this.pageSize });
        }
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(data, parentdata);
        const response: any = await this.service.search(this.fetchAction, this.context, data, this.showBusyIndicator);
        if (!response || response.status !== 200) {
            this.$notify({ type: 'danger', message: response.error.message });
            return response;
        }
        
        this.$emit('load', (response.data) ? response.data : []);
        this.items = [];
        this.items = response.data;
        console.log(this.items)
        return response;
    }

    /**
    * 全选
    *
    * @private
    * @param {*} [arg={}]
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    private handleClick() {
        this.items.forEach((item: any) => {
            item.value = true;
        });
        this.selectednumber = this.items.length;
    }

    /**
     * checkbox 选中回调
     *
     * @param {*} data
     * @returns
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public checkboxChange(data: any) {
        let { detail } = data;
        if (!detail) {
            return;
        }
        let { value } = detail;
        this.selectednumber = 0;
        this.items.forEach((item: any, index: number) => {
            if (item.value) {
                this.selectednumber++;
            }
            if (Object.is(item.${appde.getCodeName()?lower_case}id, value)) {
                if (detail.checked) {
                    this.selectdata.push(this.items[index]);
                } else {
                    this.selectdata.splice(this.selectdata.findIndex((i: any) => i.value === item.value), 1)
                }
            }
        });
        this.$emit('selectionchange', this.selectdata);
    }

    /**
     * 下拉刷新
     *
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public async pullDownToRefresh(): Promise<any> {
        this.pageNumber = 0;
        let params = {};
        if (this.viewparams) {
            Object.assign(params, this.viewparams);
        }
        Object.assign(params, { query: this.searchKey, pageNumber: this.pageNumber, pageSize: this.pageSize });
        let response: any = await this.load(params, 'top');
        return response;
    }

    /**
    * 点击列表数据跳转
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public goPage(item: String) {
      this.selectedArray.push(item);
      this.$emit('rowclick',item);
    }

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

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

    /**
    * vue生命周期created
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
    public created() {
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */    
    protected afterCreated(){
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(this.name, tag)) {
                    return;
                }
                if (Object.is(action, "load")) {
                    this.pageNumber = 0;
                    this.load(Object.assign(data, { page: this.pageNumber, size: this.pageSize }), "init");
                }
                if (Object.is(action, "search")) {
                    this.pageNumber = 0;
                    this.load(Object.assign(data, { page: this.pageNumber, size: this.pageSize }), "init");
                }
                if (Object.is(action, "quicksearch")) {
                    this.searchKey = data;
                    this.pageNumber = 0;
                    this.load(Object.assign({ query: data }, { page: this.pageNumber, size: this.pageSize }), "init");
                }
                if (Object.is(action, "refresh")) {
                    this.refresh();
                }
            });
        }
        <#if view.getViewType()?? && view.getViewType()=='DEMOBPICKUPMDVIEW'>
        if (!this.isMutli) {
            if (this.selectedData && this.selectedData.length > 0) {
                this.radio = this.selectedData[0].srfkey;
            }
        } else {
            if (this.selectedData && this.selectedData.length > 0) {
                this.checkboxList = [];
                this.selectedData.forEach((item: any) => {
                    this.checkboxList.push(item.srfkey);
                })
            }
        }
        </#if>
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public destroyed() {
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    protected afterDestroy() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }



    /**
     * 单选选中变化
     * 
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public onSimpleSelChange(item: any = {}) {
        this.$emit('selectionchange', [item]);
        this.selectedValue = item.srfkey;
        this.selectedArray = [];
        this.goPage(item);
    }


KK's avatar
KK committed
645 646 647 648 649
   /**
     * 是否展示多选
     *
     * @memberof ${srfclassname('${ctrl.name}')}
     */
KK's avatar
KK committed
650 651
    @Prop({default:false}) showCheack?: boolean;

KK's avatar
KK committed
652 653 654 655 656 657 658 659

    /**
     * 选中或取消事件
     *
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public checkboxSelect(item:any){
        let count = this.selectedArray.findIndex((i) => {
KK's avatar
KK committed
660
            return i.${appde.getKeyPSAppDEField().getCodeName()?lower_case} == item.${appde.getKeyPSAppDEField().getCodeName()?lower_case};
KK's avatar
KK committed
661
        });
KK's avatar
KK committed
662
        let re = false;
KK's avatar
KK committed
663
        if(count == -1){
KK's avatar
KK committed
664
            re = true;
KK's avatar
KK committed
665 666 667 668
            this.selectedArray.push(item);
        }else{
            this.selectedArray.splice(count,1);
        }
KK's avatar
KK committed
669
        this.items.forEach((_item: any, index: number) => {
KK's avatar
KK committed
670
            if (_item.${appde.getKeyPSAppDEField().getCodeName()?lower_case} == item.${appde.getKeyPSAppDEField().getCodeName()?lower_case}) {
KK's avatar
KK committed
671 672 673
                this.items[index].checked = re;
            }
        });
KK's avatar
KK committed
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
    }

    /**
     * 长按定时器
     *
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public loop :any;
    
    /**
     * 开始长按
     *
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public start () {
      clearTimeout(this.loop); //再次清空定时器,防止重复注册定时器
      this.loop = setTimeout(() => {
KK's avatar
KK committed
691
        this.$emit("showCheackChange", !this.showCheack);
KK's avatar
KK committed
692 693 694 695 696 697 698 699 700 701 702 703
      }, 1000);
    }

    /**
     * 结束长按
     *
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public end () {
      clearTimeout(this.loop); //清空定时器,防止重复注册定时器
    }

KK's avatar
KK committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
   /**
     * 全选事件
     *
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public checkboxAll(item:any) {
        this.selectAllIschecked = item.detail.checked;
        if(this.selectAllIschecked){
            this.selectedArray = JSON.parse(JSON.stringify(this.items));
        }else{
            this.selectedArray = [];
        }
        this.items.forEach((item:any,index:number)=>{
            this.items[index].checked = this.selectAllIschecked
        });
        this.$forceUpdate();
    }


    /**
     * 全选按钮选中状态
     *
     * @memberof ${srfclassname('${ctrl.name}')}
     */
    public selectAllIschecked = false;

ibizdev's avatar
ibizdev committed
730 731 732 733 734 735 736
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

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