CONTROL-BASE.vue.ftl 17.3 KB
Newer Older
1
<template>
2 3 4
<#if ctrl.render??>
    ${ctrl.render.code}
<#else>
5
<div class='items multieditviewpanel<#if ctrl.getPSSysCss?? && ctrl.getPSSysCss()??><#assign singleCss = ctrl.getPSSysCss()> ${singleCss.getCssName()}</#if>'>
6 7 8
    <#if ctrl.getEmbeddedPSAppView()??>
    <div class="item" v-for="item in items" :key="item.id">
        <span class="multieditviewpanel-delete" @click="handleRemove(item)"><i class="el-icon-delete"></i></span>
9
        <${srffilepath2(ctrl.getEmbeddedPSAppView().getCodeName())}      
10 11 12 13 14 15 16 17
            class="viewcontainer2" 
            :viewdata="JSON.stringify(item.viewdata)"
            :viewparam="JSON.stringify(item.viewparam)"
            :viewDefaultUsage="false" 
            :panelState="panelState"  
            @viewdataschange="viewDataChange"
            @viewload="viewload"
            @viewdirty="viewdirty(item,$event)">
18
        </${srffilepath2(ctrl.getEmbeddedPSAppView().getCodeName())}>
19 20 21 22 23 24 25
    </div>
    <divider />
    </#if>
    <div class="multieditviewpanel-button">
        <i-button type="primary" @click="handleAdd">
            {{ $t('app.local.add')}}
        </i-button>
26 27
    </div>
</div>
28
</#if>
29
</template>
30
// 基于 @CONTROL/多编辑视图面板/CONTROL-BASE.vue.ftl 生成
31 32 33 34 35 36 37
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>
    /**
     * 获取多项数据
     *
     * @returns {any[]}
KK's avatar
KK committed
38
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
39 40 41 42 43 44 45 46 47
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
KK's avatar
KK committed
48
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
49 50 51 52 53 54 55 56 57
     */
    public getData(): any {
        return null;
    }

    /**
     * 显示处理提示
     *
     * @type {boolean}
KK's avatar
KK committed
58
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
59
     */
60
    @Prop({ default: true }) public showBusyIndicator?: boolean;
61 62 63 64 65

    /**
     * 部件行为--update
     *
     * @type {string}
KK's avatar
KK committed
66
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
67
     */
68
    @Prop() public updateAction!: string;
69 70 71 72 73
    
    /**
     * 部件行为--fetch
     *
     * @type {string}
KK's avatar
KK committed
74
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
75
     */
76
    @Prop() public fetchAction!: string;
77 78 79 80 81
    
    /**
     * 部件行为--remove
     *
     * @type {string}
KK's avatar
KK committed
82
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
83
     */
84
    @Prop() public removeAction!: string;
85 86 87 88 89
    
    /**
     * 部件行为--load
     *
     * @type {string}
KK's avatar
KK committed
90
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
91
     */
92
    @Prop() public loadAction!: string;
93 94 95 96 97
    
    /**
     * 部件行为--loaddraft
     *
     * @type {string}
KK's avatar
KK committed
98
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
99
     */
100
    @Prop() public loaddraftAction!: string;
101 102 103 104 105
    
    /**
     * 部件行为--create
     *
     * @type {string}
KK's avatar
KK committed
106
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
107
     */
108
    @Prop() public createAction!: string;
109 110 111 112 113

    /**
     * 刷新数据
     *
     * @type {number}
KK's avatar
KK committed
114
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
115
     */
116
    @Prop() public saveRefView?: number;
117 118 119 120 121 122

    /**
     * 刷新数据
     *
     * @param {*} newVal
     * @param {*} oldVal
KK's avatar
KK committed
123
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
124 125 126 127 128 129 130 131 132 133 134 135 136
     */
    @Watch('saveRefView')
    onSaveRefView(newVal: any, oldVal: any) {
        console.log('保存多项数据!');
        if (newVal > 0) {
            this.$emit('drdatasaved', false);
        }

    }

     /**
     * 面板状态订阅对象
     *
137
     * @public
138 139 140
     * @type {Subject<{action: string, data: any}>}
     * @memberof Meditviewpanel
     */
141
    public panelState: Subject<ViewState> = new Subject();
142 143 144 145 146

    /**
     * 视图名称
     *
     * @type {string}
KK's avatar
KK committed
147
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
148
     */
149
    public viewname: string = '<#if ctrl.getEmbeddedPSAppView()??>${srffilepath2(ctrl.getEmbeddedPSAppView().getCodeName())}</#if>';
150 151 152 153 154

    /**
     * 获取数据对象
     *
     * @type {any[]}
KK's avatar
KK committed
155
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
156
     */
157
    public items: any[] = [];
158 159 160 161 162

    /**
     * 计数器
     *
     * @type number
KK's avatar
KK committed
163
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
164
     */
165
    public count: number = 0;
166 167

    <#--  BEGIN:参数处理  -->
tony001's avatar
tony001 committed
168 169
<#if ctrl.getEmbeddedPSAppView()??>
<#assign dataview = ctrl.getEmbeddedPSAppView() />
170 171 172 173 174
<#if !dataview.isPSDEView()>

    /**
     * 关系实体参数对象
     *
175
     * @public
176
     * @type {any[]}
KK's avatar
KK committed
177
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
178
     */
179
    public deResParameters: any[] = [];
180 181 182 183

    /**
     * 当前应用视图参数对象
     *
184
     * @public
185
     * @type {any[]}
KK's avatar
KK committed
186
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
187
     */
188
    public parameters: any[] = [];
189 190 191 192 193 194 195
<#else>
<#--  <#assign dataview = ctrl.getAllRelatedPSAppViews()[0]>  -->
<#assign appDataEntity = dataview.getPSAppDataEntity()/>

    /**
     * 关系实体参数对象
     *
196
     * @public
197
     * @type {any[]}
KK's avatar
KK committed
198
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
199
     */
200
    public deResParameters: any[] = [
201 202 203 204 205 206 207 208 209 210 211 212 213
        <#--  BEGIN:存在父关系路径  -->
        <#if dataview.getPSAppDERSPathCount() gt 0>
        <#list dataview.getPSAppDERSPath(dataview.getPSAppDERSPathCount() - 1) as deRSPath>
        <#assign majorPSAppDataEntity = deRSPath.getMajorPSAppDataEntity()/>
        { pathName: '${srfpluralize(majorPSAppDataEntity.codeName)?lower_case}', parameterName: '${majorPSAppDataEntity.getCodeName()?lower_case}' },
        </#list>
        </#if>
        <#--  END:存在父关系路径  -->
    ];

    /**
     * 当前应用视图参数对象
     *
214
     * @public
215
     * @type {any[]}
KK's avatar
KK committed
216
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
217
     */
218
    public parameters: any[] = [
219 220 221
        { pathName: '${srfpluralize(appDataEntity.codeName)?lower_case}', parameterName: '${appDataEntity.getCodeName()?lower_case}' },
    ];
</#if>
tony001's avatar
tony001 committed
222
</#if>
223 224 225 226 227
<#--  END:参数处理  -->

    /**
     * vue 声明周期
     *
KK's avatar
KK committed
228
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
229
     */
230
    public created() {
231 232 233 234 235 236
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
KK's avatar
KK committed
237
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
238
     */    
239
    public afterCreated(){
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is(action, 'load')) {
                    this.load(data);
                }
                if (Object.is(action, 'save')) {
                    this.saveData(data);
                }
            });
        }
    }   

    /**
     * vue 生命周期
     *
KK's avatar
KK committed
258
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
259
     */
260
    public destroyed() {
261 262 263 264 265 266
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
KK's avatar
KK committed
267
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
268
     */
269
    public afterDestroy() {
270 271 272 273 274 275 276 277 278 279 280 281 282
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

     /**
      * 保存数据
      *
      * @memberof Meditviewpanel
      */
283
    public saveData(data?: any) {
284 285 286 287 288 289 290 291 292 293 294 295
        this.count = 0;
        if(this.items.length >0){
            Object.assign(data,{showResultInfo:false});
            this.panelState.next({ tag: 'meditviewpanel', action: 'save', data: data });
        }else{
            this.$emit("drdatasaved",{action:'drdatasaved'});
        }
    }

    /**
     * 处理数据
     *
296
     * @public
297
     * @param {any[]} datas
KK's avatar
KK committed
298
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
299
     */
300
    public doItems(datas: any[]): void {
301 302 303
        const [{ pathName, parameterName }] = this.parameters;
        datas.forEach((arg: any) => {
            let id: string = arg[parameterName] ? arg[parameterName] : this.$util.createUUID();
304
            let item: any = { id: id, viewdata: {}, viewparam: {}, data: {} };
305 306
            Object.assign(item.viewdata, this.$viewTool.getIndexViewParam());
            Object.assign(item.viewdata, this.context);
307
            Object.assign(item.data, arg);
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
            // 关系应用实体参数
            this.deResParameters.forEach(({ pathName, parameterName }: { pathName: string, parameterName: string }) => {
                if (this.context[parameterName] && !Object.is(this.context[parameterName], '')) {
                    Object.assign(item.viewdata, { [parameterName]: this.context[parameterName] });
                } else if (arg[parameterName] && !Object.is(arg[parameterName], '')) {
                    Object.assign(item.viewdata, { [parameterName]: arg[parameterName] });
                }
            });

            // 当前视图参数(应用实体视图)
            this.parameters.forEach(({ pathName, parameterName }: { pathName: string, parameterName: string }) => {
                if (arg[parameterName] && !Object.is(arg[parameterName], '')) {
                    Object.assign(item.viewdata, { [parameterName]: arg[parameterName] });
                }
            });

            //合并视图参数
            Object.assign(item.viewparam, this.viewparams);
            this.items.push(item);
        });
    }

    /**
     * 数据加载
     *
333
     * @public
334
     * @param {*} data
KK's avatar
KK committed
335
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
336
     */
Shine-zwj's avatar
Shine-zwj committed
337
    public async load(data: any) {
338
        if(!this.fetchAction){
339
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.multiEditView.notConfig.fetchAction') as string) });
340 341 342 343 344
            return;
        }
        let arg: any = {};
        Object.assign(arg, data,{viewparams:this.viewparams});
        this.items = [];
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
        let viewparamResult:any = Object.assign(arg, this.viewparams);
        const tempContext = Util.deepCopy(this.context);
        if (!(await this.handleCtrlEvents('onbeforeload', { context: tempContext, viewparams: viewparamResult, data: arg }))) {
            return;
        }
        const response: any = await this.service.get(this.fetchAction,JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator);
        try {
            if (response.status && response.status == 200) {
                if (!(await this.handleCtrlEvents('onloadsuccess', { data: response.data }))) {
                    return;
                }
                const data: any = response.data;
                if (data.length > 0) {
                    const items = JSON.parse(JSON.stringify(data));
                    this.doItems(items);
                }
                this.$emit('load', this.items);
            } else {
                if (!(await this.handleCtrlEvents('onloaderror', { data: response.data }))) {
                    return;
                }
366 367
                if (response.data && response.data.message) {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
368 369
                }
            }
370 371 372
        } catch (error) {
             if (!(await this.handleCtrlEvents('onloaderror', { context: tempContext, viewparams: viewparamResult, data: response && response.data ? response.data : arg }))) {
                return;
373 374 375 376
            }
            if (response && response.status === 401) {
                return;
            }
377
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data && response.data.message ? response.data.message : "" });
378
        }
379 380 381 382 383
    }

    /**
     * 增加数据
     * 
KK's avatar
KK committed
384
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
385
     */
386
    public handleAdd(){
387
        if(!this.loaddraftAction){
388
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.multiEditView.notConfig.loaddraftAction') as string) });
389 390 391 392 393
            return;
        }
        const promice: Promise<any> = this.service.loadDraft(this.loaddraftAction,JSON.parse(JSON.stringify(this.context)),{viewparams:this.viewparams}, this.showBusyIndicator);
        promice.then((response: any) => {
            if (!response.status || response.status !== 200) {
394 395
                if (response.data && response.data.message) {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
396 397 398 399 400 401 402 403 404
                }
                return;
            }
            const data: any = response.data;
            this.doItems([data]);
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
405
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data && response.data.message ? response.data.message : "" });
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
    /**
     * 删除数据
     *
     * @param {*} item
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public handleRemove(item:any){
        if (item.data.srfuf == "0") {
                //删除items中已删除的项
                let index = this.items.findIndex((value: any, index: any, arr: any) => {
                    return value === item;
                });
                this.items.splice(index, 1);
            } else {
                // 原有的走接口删除
                let tempContext: any = JSON.parse(JSON.stringify(this.context));
                Object.assign(tempContext, { '${ctrl.getPSAppDataEntity().getCodeName()?lower_case}': item.data.${ctrl.getPSAppDataEntity().getCodeName()?lower_case} });
                let arg: any = JSON.parse(JSON.stringify(this.viewparams));
                Object.assign(arg, { '${ctrl.getPSAppDataEntity().getKeyPSAppDEField().getCodeName()?lower_case}': item.data.${ctrl.getPSAppDataEntity().getCodeName()?lower_case} });
                const promice: Promise<any> = this.service.delete(this.removeAction, tempContext, arg, this.showBusyIndicator);
                promice.then((response: any) => {
                    if (!response.status || response.status !== 200) {
                        if (response.data && response.data.message) {
                            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
                        }
                        return;
                    }
                    //删除items中已删除的项
                    let index = this.items.findIndex((value: any, index: any, arr: any) => {
                        return value.data.${ctrl.getPSAppDataEntity().getCodeName()?lower_case} === item.data.${ctrl.getPSAppDataEntity().getCodeName()?lower_case};
                    });
                    this.items.splice(index, 1);
                }).catch((response: any) => {
                    if (response.data && response.data.message) {
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
                    }
                });
            }
    }

449 450 451 452 453
    /**
     * 设置视图脏值变化
     *
     * @param {*} item
     * @param {boolean} $event
KK's avatar
KK committed
454
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
455
     */
456
    public setViewDirty(item: any, $event: boolean) {
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
        let index: number = this.items.findIndex((_item: any) => Object.is(_item.id, item.id));
        if (index === -1) {
            return;
        }
        Object.assign(this.items[index], { viewdirty: $event });
        let state: boolean = this.items.some((item: any) => {
            if (item.viewdirty) {
                return true;
            }
            return false;
        });
        this.$emit('viewdatadirty', state);
    }

     /**
     * 部件抛出事件
KK's avatar
KK committed
473
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
474
     */
475
    public viewDataChange($event:any){
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
        if($event){
            try{
                $event = JSON.parse($event);
            }catch(error){
                return;
            }
            if(Object.is($event.action,'load')){
                console.log('加载----');
            }
            if(Object.is($event.action,'save')){
                this.count++;
                if (this.items.length === this.count) {
                    this.$emit('drdatasaved',{action:'save'});
                }
            }
            if(Object.is($event.action,'remove')){
                if ($event.data) {
                    let resultIndex = this.items.findIndex((value:any, index:any, arr:any) => {
494
                        return value['viewdata']['${ctrl.getPSAppDataEntity().getKeyPSAppDEField().getCodeName()?lower_case}'] === $event.data['${ctrl.getPSAppDataEntity().getKeyPSAppDEField().getCodeName()?lower_case}'];
495 496 497 498 499 500 501 502 503 504 505 506 507
                    });
                    if (resultIndex !== -1) {
                        this.items.splice(resultIndex, 1);
                    }
                }
            }            
        }
    }

    /**
     * 视图加载完成
     *
     * @returns
KK's avatar
KK committed
508
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
509
     */
510
    public viewload($event:any){
511 512 513 514 515 516 517
        console.log('视图加载完成');
    }

    /**
     * editview9 视图数据变化
     *
     * @returns
KK's avatar
KK committed
518
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
519
     */
520
    public viewdirty(item:any,$event:any){
521 522 523 524 525 526 527 528 529 530 531
        // editview9 视图数据变化;
        this.setViewDirty(item, $event);
    }

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

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