CONTROL-BASE.vue.ftl 12.1 KB
Newer Older
1 2
<template>  
    <div :class="['app-list', this.items.length > 0 ? '' : 'app-list-empty' ]">
3
            <div v-if="items.length > 0" style="height:100%;">
4 5 6 7 8 9
                <#if ctrl.render??>
                ${ctrl.render.code}
                <#else>                 
                        <div v-for = "item in items" :key="item.srfmajortext"  :class="['app-list-item', {'isSelect': item.isselected === true ? true : false}]" @click="handleClick(item)"  @dblclick="handleDblClick(item)">
                    <#if ctrl.getItemPSLayoutPanel()??>
                        <#assign panel = ctrl.getItemPSLayoutPanel()>
10
                            <layout_${panel.getName()} name='${panel.name}' :inputData="item"></layout_${panel.getName()}>
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
                    <#elseif ctrl.itemRender??>
                            ${ctrl.itemRender.code}
                    <#else>
                            {{item.srfmajortext}}
                    </#if>
                        </div>
                </#if>
            </div>
            <div v-else>
                暂无数据
            </div>
    </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}')}
     */
54
    @Prop({ default: false }) public isSelectFirstDefault!: boolean;
55 56 57 58 59 60 61

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
62
    @Prop({ default: true }) public showBusyIndicator?: boolean;
63 64 65 66 67 68 69

    /**
     * 部件行为--create
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
70
    @Prop() public createAction!: string;
71 72 73 74 75 76 77

    /**
     * 部件行为--remove
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
78
    @Prop() public removeAction!: string;
79 80 81 82 83 84 85

    /**
     * 部件行为--update
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
86
    @Prop() public updateAction!: string;
87 88 89 90 91 92 93

    /**
     * 部件行为--fetch
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
94
    @Prop() public fetchAction!: string;
95 96 97 98 99 100 101

    /**
     * 当前页
     *
     * @type {number}
     * @memberof Main
     */
102
    public curPage: number = 1;
103 104 105 106 107 108 109

    /**
     * 数据
     *
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
110
    public items: any[] = [];
111 112 113 114 115 116 117

    /**
     * 是否支持分页
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
118
    public isEnablePagingBar: boolean = true;
119 120 121 122 123 124 125

    /**
     * 分页条数
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
126
    public limit: number = 20;
127 128 129 130 131 132 133

    /**
     * 总条数
     *
     * @type {number}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
134
    public totalRecord: number = 0;
135 136 137 138 139 140

    /**
     * 选中数组
     * @type {Array<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
141
    public selections: Array<any> = [];
142 143 144 145 146 147

     /**
     * Vue声明周期,组件挂载完毕
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
148
    public mounted () {
149 150 151 152 153 154 155 156
        this.afterMounted();
    }

    /**
     * 执行mounted后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
157
    public afterMounted () {
158 159 160 161 162 163 164 165 166 167 168 169
        this.$el.addEventListener('scroll', ()=> {
            if( this.$el.scrollTop +  this.$el.clientHeight  >=  this.$el.scrollHeight) {
                this.loadMore();
            }
        })
    }

    /**
     * Vue声明周期,组件创建完毕
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
170
    public created() {
171 172 173 174 175 176 177 178
        this.afterCreated()
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */    
179
    public afterCreated(){
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
        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)
                }
            });
        }
    }    

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
197
    public destroyed() {
198 199 200 201 202 203 204 205
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
206
    public afterDestroy() {
207 208 209 210 211 212 213 214 215 216 217 218 219
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }    

    /**
    * 加载更多
    *
    * @memberof Mob
    */
220
    public loadMore(){
221 222 223 224 225 226 227 228 229 230 231 232 233
        if(this.totalRecord>this.items.length)
        {
            this.curPage = ++this.curPage;
            this.load({});
        }
    }

    /**
     * 刷新
     *
     * @param {*} [opt={}]
     * @memberof Main
     */
234
    public refresh(opt: any = {}) {
235 236 237 238 239 240 241 242
        this.curPage = 1;
        this.items = [];
        this.load(opt);
    }

    /**
     * 列表数据加载
     *
243
     * @public
244 245 246
     * @param {*} [arg={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
247
    public load(opt: any = {}): void {
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
        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 });
        }
        Object.assign(arg, page);
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(arg, parentdata);
        Object.assign(arg,{viewparams:this.viewparams});
        const post: Promise<any> = this.service.search(this.fetchAction, this.context?JSON.parse(JSON.stringify(this.context)):{}, arg, 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;
                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}')}
     */
299
    public async remove(datas: any[]): Promise<any> {
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
        if(!this.removeAction){
            this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表格removeAction参数未配置' });
            return;
        }
        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
331
            let _removeAction = keys.length > 1 ? 'removeBatch' : this.removeAction ;
332
            const context:any = JSON.parse(JSON.stringify(this.context));
333
            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);
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
            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}')}
     *
     */
385
    public handleClick(args: any) {
386 387 388 389 390 391 392 393 394 395
        this.clearSelection();
        args.isselected = !args.isselected;
        this.selectchange();
    }

    /**
     * 双击数据
     * @memberof ${srfclassname('${ctrl.codeName}')}
     *
     */
396
    public handleDblClick(args: any) {
397 398 399 400 401 402 403 404
        this.$emit('rowdblclick', args);
    }

    /**
     * 触发事件
     * @memberof ${srfclassname('${ctrl.codeName}')}
     *
     */
405
    public selectchange() {
406 407 408 409 410 411 412 413 414 415 416 417 418 419
        this.selections = [];
        this.items.map((item: any) => {
            if (item.isselected) {
                this.selections.push(item);
            }
        });
        this.$emit('selectionchange', this.selections);
    }

    /**
     * 清除当前所有选中状态
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
420
    public clearSelection(){
421 422 423 424 425 426 427 428 429 430 431 432
        this.items.map((item: any) => {
            Object.assign(item, { isselected: false });
        }); 
    }

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

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