main-form-base.vue 65.9 KB
Newer Older
ibizdev's avatar
ibizdev committed
1
<template>
2
    <i-form :model="this.data" class='app-form' ref='form'  id='wfuser_main' style="" @on-validate="formItemValidate">
ibizdev's avatar
ibizdev committed
3 4
    <input style="display:none;" />
    <row >
5
            <i-col v-show="detailsModel.group1.visible" :style="{}"  :lg="{ span: 24, offset: 0 }">
6
    <app-form-group :uiService="appUIService" :data="transformData(data)" :manageContainerStatus="detailsModel.group1.manageContainerStatus"  :isManageContainer="detailsModel.group1.isManageContainer" @managecontainerclick="manageContainerClick('group1')" layoutType="TABLE_24COL" titleStyle="" class='' :uiActionGroup="detailsModel.group1.uiActionGroup" @groupuiactionclick="groupUIActionClick($event)" :caption="$t('entities.wfuser.main_form.details.group1')" :isShowCaption="true" uiStyle="DEFAULT" :titleBarCloseMode="0" :isInfoGroupMode="false" >    
ibizdev's avatar
ibizdev committed
7
    <row>
ibizdev's avatar
ibizdev committed
8
        <i-col v-show="detailsModel.personname.visible" :style="{}"  :lg="{ span: 24, offset: 0 }">
9
    <app-form-item name='personname' :itemRules="this.rules().personname" class='' :caption="$t('entities.wfuser.main_form.details.personname')" uiStyle="DEFAULT" :labelWidth="130" :isShowCaption="true" :error="detailsModel.personname.error" :isEmptyCaption="false" labelPos="LEFT">
10 11 12 13 14 15 16 17
    <input-box 
    v-model="data.personname"  
    @enter="onEnter($event)"  
     unit=""  
    :disabled="detailsModel.personname.disabled" 
    type='text' 
    style="">
</input-box>
18

ibizdev's avatar
ibizdev committed
19
</app-form-item>
ibizdev's avatar
ibizdev committed
20 21

</i-col>
ibizdev's avatar
ibizdev committed
22
<i-col v-show="detailsModel.username.visible" :style="{}"  :lg="{ span: 24, offset: 0 }">
23
    <app-form-item name='username' :itemRules="this.rules().username" class='' :caption="$t('entities.wfuser.main_form.details.username')" uiStyle="DEFAULT" :labelWidth="130" :isShowCaption="true" :error="detailsModel.username.error" :isEmptyCaption="false" labelPos="LEFT">
24 25 26 27 28 29 30 31
    <input-box 
    v-model="data.username"  
    @enter="onEnter($event)"  
     unit=""  
    :disabled="detailsModel.username.disabled" 
    type='text' 
    style="">
</input-box>
32

ibizdev's avatar
ibizdev committed
33
</app-form-item>
ibizdev's avatar
ibizdev committed
34

ibizdev's avatar
ibizdev committed
35 36
</i-col>
    
ibizdev's avatar
ibizdev committed
37 38 39 40 41 42 43 44 45 46 47
    </row>
</app-form-group>

</i-col>


    </row>
</i-form>
</template>

<script lang='tsx'>
48
import { Vue, Component, Prop, Provide, Emit, Watch, Model,Inject } from 'vue-property-decorator';
ibizdev's avatar
ibizdev committed
49 50 51
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
52
import { UIActionTool,Util,ViewTool } from '@/utils';
53
import NavDataService from '@/service/app/navdata-service';
54
import AppCenterService from "@service/app/app-center-service";
55
import WFUserEntityService from '@/service/wfuser/wfuser-service';
ibizdev's avatar
ibizdev committed
56
import MainService from './main-form-service';
57
import WFUserUIService from '@/uiservice/wfuser/wfuser-ui-service';
ibizdev's avatar
ibizdev committed
58 59
import { FormButtonModel, FormPageModel, FormItemModel, FormDRUIPartModel, FormPartModel, FormGroupPanelModel, FormIFrameModel, FormRowItemModel, FormTabPageModel, FormTabPanelModel, FormUserControlModel } from '@/model/form-detail';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
60
import schema from 'async-validator';
61
import { Environment } from '@/environments/environment';
ibizdev's avatar
ibizdev committed
62 63 64 65 66 67 68 69 70 71 72 73 74


@Component({
    components: {
      
    }
})
export default class MainBase extends Vue implements ControlInterface {

    /**
     * 名称
     *
     * @type {string}
75
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
76
     */
ibizdev's avatar
ibizdev committed
77
    @Prop() public name?: string;
ibizdev's avatar
ibizdev committed
78 79 80 81 82

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
83
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
84
     */
ibizdev's avatar
ibizdev committed
85
    @Prop() public viewState!: Subject<ViewState>;
ibizdev's avatar
ibizdev committed
86 87 88 89 90

    /**
     * 应用上下文
     *
     * @type {*}
91
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
92
     */
93
    @Prop() public context!: any;
ibizdev's avatar
ibizdev committed
94 95 96 97 98

    /**
     * 视图参数
     *
     * @type {*}
99
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
100
     */
101
    @Prop() public viewparams!: any;
ibizdev's avatar
ibizdev committed
102 103 104 105

    /**
     * 视图状态事件
     *
ibizdev's avatar
ibizdev committed
106
     * @public
ibizdev's avatar
ibizdev committed
107
     * @type {(Subscription | undefined)}
108
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
109
     */
ibizdev's avatar
ibizdev committed
110
    public viewStateEvent: Subscription | undefined;
ibizdev's avatar
ibizdev committed
111 112 113 114 115

    /**
     * 获取部件类型
     *
     * @returns {string}
116
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
117
     */
ibizdev's avatar
ibizdev committed
118
    public getControlType(): string {
ibizdev's avatar
ibizdev committed
119 120 121 122 123 124 125 126 127
        return 'FORM'
    }



    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
128
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
129
     */    
ibizdev's avatar
ibizdev committed
130
    public counterServiceArray:Array<any> = [];
ibizdev's avatar
ibizdev committed
131 132 133 134 135

    /**
     * 建构部件服务对象
     *
     * @type {MainService}
136
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
137
     */
ibizdev's avatar
ibizdev committed
138
    public service: MainService = new MainService({ $store: this.$store });
ibizdev's avatar
ibizdev committed
139 140 141 142 143

    /**
     * 实体服务对象
     *
     * @type {WFUserService}
144
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
145
     */
146
    public appEntityService: WFUserEntityService = new WFUserEntityService({ $store: this.$store });
ibizdev's avatar
ibizdev committed
147 148 149
    


150 151 152 153 154 155 156 157 158 159 160 161 162
    /**
     * 转化数据
     *
     * @param {any} args
     * @memberof  MainBase
     */
    public transformData(args: any) {
        let _this: any = this;
        if(_this.service && _this.service.handleRequestData instanceof Function && _this.service.handleRequestData('transform',_this.context,args)){
            return _this.service.handleRequestData('transform',_this.context,args)['data'];
        }
    }

ibizdev's avatar
ibizdev committed
163 164 165 166
    /**
     * 关闭视图
     *
     * @param {any} args
167
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
168
     */
ibizdev's avatar
ibizdev committed
169
    public closeView(args: any): void {
ibizdev's avatar
ibizdev committed
170 171 172 173 174 175 176
        let _this: any = this;
        _this.$emit('closeview', [args]);
    }

    /**
     *  计数器刷新
     *
177
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
178 179 180 181 182 183 184 185 186 187 188 189 190
     */
    public counterRefresh(){
        const _this:any =this;
        if(_this.counterServiceArray && _this.counterServiceArray.length >0){
            _this.counterServiceArray.forEach((item:any) =>{
                if(item.refreshData && item.refreshData instanceof Function){
                    item.refreshData();
                }
            })
        }
    }


191

192 193 194 195 196 197
    /**
     * 视图默认使用
     *
     * @type {string}
     * @memberof MainBase
     */
198
    @Inject({from:'navModel',default: 'tab'})
199 200
    public navModel!:string;

201 202 203 204 205 206 207 208 209
    /**
     * 主键表单项名称
     *
     * @protected
     * @type {string}
     * @memberof MainBase
     */
    public formKeyItemName: string = '';

210 211 212 213 214 215 216 217
    /**
     * 是否自动加载
     *
     * @type {boolean}
     * @memberof MainBase
     */
    @Prop({default:false}) public isautoload?:boolean;

218 219 220 221 222 223 224 225
    /**
     * 界面UI服务对象
     *
     * @type {WFUserUIService}
     * @memberof MainBase
     */  
    public appUIService:WFUserUIService = new WFUserUIService(this.$store);

226 227 228
    /**
     * 工作流审批意见控件绑定值
     *
229
     * @memberof MainBase
230 231
     */
    public srfwfmemo:string = "";
ibizdev's avatar
ibizdev committed
232 233 234 235 236
    
    /**
     * 获取多项数据
     *
     * @returns {any[]}
237
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
238 239 240 241 242 243 244 245 246
     */
    public getDatas(): any[] {
        return [this.data];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
247
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
248 249 250 251 252 253 254 255 256
     */
    public getData(): any {
        return this.data;
    }

    /**
     * 是否默认保存
     *
     * @type {boolean}
257
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
258
     */
ibizdev's avatar
ibizdev committed
259
    @Prop({ default: false }) public autosave?: boolean;
ibizdev's avatar
ibizdev committed
260 261 262 263 264

    /**
     * 显示处理提示
     *
     * @type {boolean}
265
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
266
     */
ibizdev's avatar
ibizdev committed
267
    @Prop({ default: true }) public showBusyIndicator?: boolean;
ibizdev's avatar
ibizdev committed
268 269 270 271 272

    /**
     * 部件行为--submit
     *
     * @type {string}
273
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
274
     */
ibizdev's avatar
ibizdev committed
275
    @Prop() public WFSubmitAction!: string;
ibizdev's avatar
ibizdev committed
276 277 278 279 280
    
    /**
     * 部件行为--start
     *
     * @type {string}
281
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
282
     */
ibizdev's avatar
ibizdev committed
283
    @Prop() public WFStartAction!: string;
ibizdev's avatar
ibizdev committed
284 285 286 287 288
    
    /**
     * 部件行为--update
     *
     * @type {string}
289
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
290
     */
ibizdev's avatar
ibizdev committed
291
    @Prop() public updateAction!: string;
ibizdev's avatar
ibizdev committed
292 293 294 295 296
    
    /**
     * 部件行为--remove
     *
     * @type {string}
297
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
298
     */
ibizdev's avatar
ibizdev committed
299
    @Prop() public removeAction!: string;
ibizdev's avatar
ibizdev committed
300 301 302 303 304
    
    /**
     * 部件行为--loaddraft
     *
     * @type {string}
305
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
306
     */
ibizdev's avatar
ibizdev committed
307
    @Prop() public loaddraftAction!: string;
ibizdev's avatar
ibizdev committed
308 309 310 311 312
    
    /**
     * 部件行为--load
     *
     * @type {string}
313
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
314
     */
ibizdev's avatar
ibizdev committed
315
    @Prop() public loadAction!: string;
ibizdev's avatar
ibizdev committed
316 317 318 319 320
    
    /**
     * 部件行为--create
     *
     * @type {string}
321
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
322
     */
ibizdev's avatar
ibizdev committed
323
    @Prop() public createAction!: string;
ibizdev's avatar
ibizdev committed
324 325 326 327 328

    /**
     * 部件行为--create
     *
     * @type {string}
329
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
330
     */
ibizdev's avatar
ibizdev committed
331
    @Prop() public searchAction!: string;
ibizdev's avatar
ibizdev committed
332 333 334 335 336

    /**
     * 视图标识
     *
     * @type {string}
337
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
338
     */
ibizdev's avatar
ibizdev committed
339
    @Prop() public viewtag!: string;
ibizdev's avatar
ibizdev committed
340 341 342 343 344

    /**
     * 表单状态
     *
     * @type {Subject<any>}
345
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
346
     */
ibizdev's avatar
ibizdev committed
347
    public formState: Subject<any> = new Subject();
ibizdev's avatar
ibizdev committed
348 349 350 351 352

    /**
     * 忽略表单项值变化
     *
     * @type {boolean}
353
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
354
     */
ibizdev's avatar
ibizdev committed
355
    public ignorefieldvaluechange: boolean = false;
ibizdev's avatar
ibizdev committed
356 357 358 359

    /**
     * 数据变化
     *
ibizdev's avatar
ibizdev committed
360
     * @public
ibizdev's avatar
ibizdev committed
361
     * @type {Subject<any>}
362
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
363
     */
ibizdev's avatar
ibizdev committed
364
    public dataChang: Subject<any> = new Subject();
ibizdev's avatar
ibizdev committed
365 366 367 368

    /**
     * 视图状态事件
     *
ibizdev's avatar
ibizdev committed
369
     * @public
ibizdev's avatar
ibizdev committed
370
     * @type {(Subscription | undefined)}
371
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
372
     */
ibizdev's avatar
ibizdev committed
373
    public dataChangEvent: Subscription | undefined;
ibizdev's avatar
ibizdev committed
374 375 376 377

    /**
     * 原始数据
     *
ibizdev's avatar
ibizdev committed
378
     * @public
ibizdev's avatar
ibizdev committed
379
     * @type {*}
380
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
381
     */
ibizdev's avatar
ibizdev committed
382
    public oldData: any = {};
ibizdev's avatar
ibizdev committed
383

384 385 386 387 388 389 390 391
    /**
     * 混入表单数据对象
     *
     * @type {*}
     * @memberof MainBase
     */
    public mixinData:any = {};

392 393 394 395 396
    /**
     * 表单项校验错误提示信息
     * 
     *  @memberof  MainBase
     */
397 398 399 400 401 402 403 404 405 406
    public errorMessages: Array<any> = []; 

    /**
     * 应用状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     * @memberof MainBase
     */
    public appStateEvent: Subscription | undefined;
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

    /**
     * 设置表单项错误提示信息
     * 
     * @param {*} prop 表单项字段名
     * @param {*} status 校验状态
     * @param {*} error 错误信息
     * @memberof MainBase
     */
    public formItemValidate(prop: string,status: boolean, error: string){
        error = error ? error : '';
        if(this.errorMessages && this.errorMessages.length > 0){
            const index = this.errorMessages.findIndex((errorMessage:any) => Object.is(errorMessage.prop,prop));
            if(index != -1){
                this.errorMessages[index].error = error;
            }else{
                this.errorMessages.push({prop: prop,error: error});
            }
        }else{
            this.errorMessages.push({prop: prop,error: error});
        }
    }

ibizdev's avatar
ibizdev committed
430 431 432 433
    /**
     * 表单数据对象
     *
     * @type {*}
434
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
435
     */
ibizdev's avatar
ibizdev committed
436
    public data: any = {
ibizdev's avatar
ibizdev committed
437 438 439 440 441 442 443
        srforikey: null,
        srfkey: null,
        srfmajortext: null,
        srftempmode: null,
        srfuf: null,
        srfdeid: null,
        srfsourcekey: null,
ibizdev's avatar
ibizdev committed
444 445
        personname: null,
        username: null,
ibizdev's avatar
ibizdev committed
446 447 448 449 450 451 452 453
        userid: null,
        wfuser:null,
    };

    /**
      * 当前执行的行为逻辑
      *
      * @type {string}
454
      * @memberof MainBase
ibizdev's avatar
ibizdev committed
455
      */
ibizdev's avatar
ibizdev committed
456
    public currentAction: string = "";
ibizdev's avatar
ibizdev committed
457 458 459 460 461

    /**
      * 关系界面计数器
      *
      * @type {number}
462
      * @memberof MainBase
ibizdev's avatar
ibizdev committed
463
      */
ibizdev's avatar
ibizdev committed
464
    public drcounter: number = 0;
ibizdev's avatar
ibizdev committed
465 466 467 468 469

    /**
      * 需要等待关系界面保存时,第一次调用save参数的备份
      *
      * @type {number}
470
      * @memberof MainBase
ibizdev's avatar
ibizdev committed
471
      */
ibizdev's avatar
ibizdev committed
472
    public drsaveopt: any = {};
ibizdev's avatar
ibizdev committed
473 474 475 476 477

    /**
      * 表单保存回调存储对象
      *
      * @type {any}
478
      * @memberof MainBase
ibizdev's avatar
ibizdev committed
479
      */
ibizdev's avatar
ibizdev committed
480
    public saveState:any ;
ibizdev's avatar
ibizdev committed
481

482 483 484 485 486 487 488 489
    /**
     * 主信息属性映射表单项名称
     *
     * @type {string}
     * @memberof MainBase
     */
    public majorMessageField: string = "personname";

ibizdev's avatar
ibizdev committed
490
    /**
491
     * 值规则
ibizdev's avatar
ibizdev committed
492 493
     *
     * @type {*}
494
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
495
     */
496 497
    public rules() :any {
    return {
ibizdev's avatar
ibizdev committed
498
        personname: [
499 500
            { required: this.detailsModel.personname.required, type: 'string', message: '用户名称 值不能为空', trigger: 'change' },
            { required: this.detailsModel.personname.required, type: 'string', message: '用户名称 值不能为空', trigger: 'blur' },
ibizdev's avatar
ibizdev committed
501 502
        ],
        username: [
503 504
            { required: this.detailsModel.username.required, type: 'string', message: '用户全局名 值不能为空', trigger: 'change' },
            { required: this.detailsModel.username.required, type: 'string', message: '用户全局名 值不能为空', trigger: 'blur' },
ibizdev's avatar
ibizdev committed
505
        ],
506 507 508 509 510 511 512 513 514
        }
    }

    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof MainBase
     */
515 516 517 518
    public deRules(){
        return {
        }
    }
519 520 521 522 523 524 525 526

    /**
     * 校验属性值规则
     *
     * @public
     * @param {{ name: string }} { name }
     * @memberof MainBase
     */
527
    public verifyDeRules(name:string,rule:any = this.deRules(),op:string = "AND") :{isPast:boolean,infoMessage:string}{
528
        let falg:any = {infoMessage:""};
529 530 531
        if(!rule[name]){
            return falg;
        }
532 533 534 535
        let opValue = op == 'AND'? true :false;
        let startOp = (val:boolean)=>{
            if(falg.isPast){
                if(opValue){
536
                    falg.isPast = falg.isPast && val;
537
                }else{
538
                    falg.isPast = falg.isPast || val;
539 540 541 542 543
                }
            }else{
                falg.isPast = val;
            }
        }
544 545
        for(let i=0;i<rule[name].length;i++){
            let item:any = rule[name][i];
546
            let dataValue = item.deName?this.data[this.service.getItemNameByDeName(item.deName)]:"";
547 548 549 550 551
            item.ruleInfo = item.ruleInfo ? item.ruleInfo : this.$t('app.formpage.valuecheckex');
            if((dataValue === null || dataValue === undefined || dataValue === "") && (item.type != 'GROUP')){
                startOp(true);
                return falg;
            }
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
           try {
                // 常规规则
                if(item.type == 'SIMPLE'){
                    startOp(!this.$verify.checkFieldSimpleRule(dataValue,item.condOP,item.paramValue,item.ruleInfo,item.paramType,this.data,item.isKeyCond));
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
                // 数值范围
                if(item.type == 'VALUERANGE2'){
                    startOp( !this.$verify.checkFieldValueRangeRule(dataValue,item.minValue,item.isIncludeMinValue,item.maxValue,item.isIncludeMaxValue,item.ruleInfo,item.isKeyCond));
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
                // 正则式
                if (item.type == "REGEX") {
                    startOp(!this.$verify.checkFieldRegExRule(dataValue,item.regExCode,item.ruleInfo,item.isKeyCond));
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
                // 长度
                if (item.type == "STRINGLENGTH") {
                    startOp(!this.$verify.checkFieldStringLengthRule(dataValue,item.minValue,item.isIncludeMinValue,item.maxValue,item.isIncludeMaxValue,item.ruleInfo,item.isKeyCond)); 
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
                // 系统值规则
                if(item.type == "SYSVALUERULE") {
                    startOp(!this.$verify.checkFieldSysValueRule(dataValue,item.sysRule.regExCode,item.ruleInfo,item.isKeyCond));
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
            } catch(error) {
584
                falg.infoMessage = item.ruleInfo;
585
                startOp(false);
586
                if(!falg.isPast) return falg;
587 588
            }
            // 分组
589
            if(item.type == 'GROUP'){
590
                falg = this.verifyDeRules('group',item,item.condOP?item.condOP:"AND");
591 592 593
                if(item.isNotMode){
                   falg.isPast = !falg.isPast;
                }
594 595 596
                if(!falg.isPast) return falg;
            }   
        }
597 598 599
        if(!falg.hasOwnProperty("isPast")){
            falg.isPast = true;
        }
600
        if(!this.data[name] && this.data[name] != 0){
601 602
           falg.isPast = true;
        }
603
        return falg;
ibizdev's avatar
ibizdev committed
604 605 606 607 608 609
    }

    /**
     * 详情模型集合
     *
     * @type {*}
610
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
611
     */
ibizdev's avatar
ibizdev committed
612
    public detailsModel: any = {
613
        group1: new FormGroupPanelModel({ caption: '用户基本信息', detailType: 'GROUPPANEL', name: 'group1', visible: true, isShowCaption: true, form: this, isControlledContent: false , uiActionGroup: { caption: '', langbase: 'entities.wfuser.main_form', extractMode: 'ITEM', details: [] }, isManageContainer: false, showMoreModeItems: []  })
ibizdev's avatar
ibizdev committed
614
, 
615
        formpage1: new FormPageModel({ caption: '基本信息', detailType: 'FORMPAGE', name: 'formpage1', visible: true, isShowCaption: true, form: this, isControlledContent: false  })
ibizdev's avatar
ibizdev committed
616
, 
617
        srforikey: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srforikey', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
618
, 
619
        srfkey: new FormItemModel({ caption: '用户标识', detailType: 'FORMITEM', name: 'srfkey', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
620
, 
621
        srfmajortext: new FormItemModel({ caption: '用户名称', detailType: 'FORMITEM', name: 'srfmajortext', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
622
, 
623
        srftempmode: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srftempmode', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
624
, 
625
        srfuf: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srfuf', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
626
, 
627
        srfdeid: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srfdeid', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
628
, 
629
        srfsourcekey: new FormItemModel({ caption: '', detailType: 'FORMITEM', name: 'srfsourcekey', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
630
, 
631
        personname: new FormItemModel({ caption: '用户名称', detailType: 'FORMITEM', name: 'personname', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
632
, 
633
        username: new FormItemModel({ caption: '用户全局名', detailType: 'FORMITEM', name: 'username', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
634
, 
635
        userid: new FormItemModel({ caption: '用户标识', detailType: 'FORMITEM', name: 'userid', visible: true, isShowCaption: true, form: this, isControlledContent: false , required:false, disabled: false, enableCond: 3 })
ibizdev's avatar
ibizdev committed
636 637 638 639 640 641 642 643
, 
    };

    /**
     * 监控表单属性 srforikey 值
     *
     * @param {*} newVal
     * @param {*} oldVal
644
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
645 646 647 648 649 650 651 652 653 654 655
     */
    @Watch('data.srforikey')
    onSrforikeyChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'srforikey', newVal: newVal, oldVal: oldVal });
    }

    /**
     * 监控表单属性 srfkey 值
     *
     * @param {*} newVal
     * @param {*} oldVal
656
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
657 658 659 660 661 662 663 664 665 666 667
     */
    @Watch('data.srfkey')
    onSrfkeyChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'srfkey', newVal: newVal, oldVal: oldVal });
    }

    /**
     * 监控表单属性 srfmajortext 值
     *
     * @param {*} newVal
     * @param {*} oldVal
668
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
669 670 671 672 673 674 675 676 677 678 679
     */
    @Watch('data.srfmajortext')
    onSrfmajortextChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'srfmajortext', newVal: newVal, oldVal: oldVal });
    }

    /**
     * 监控表单属性 srftempmode 值
     *
     * @param {*} newVal
     * @param {*} oldVal
680
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
681 682 683 684 685 686 687 688 689 690 691
     */
    @Watch('data.srftempmode')
    onSrftempmodeChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'srftempmode', newVal: newVal, oldVal: oldVal });
    }

    /**
     * 监控表单属性 srfuf 值
     *
     * @param {*} newVal
     * @param {*} oldVal
692
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
693 694 695 696 697 698 699 700 701 702 703
     */
    @Watch('data.srfuf')
    onSrfufChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'srfuf', newVal: newVal, oldVal: oldVal });
    }

    /**
     * 监控表单属性 srfdeid 值
     *
     * @param {*} newVal
     * @param {*} oldVal
704
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
705 706 707 708 709 710 711 712 713 714 715
     */
    @Watch('data.srfdeid')
    onSrfdeidChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'srfdeid', newVal: newVal, oldVal: oldVal });
    }

    /**
     * 监控表单属性 srfsourcekey 值
     *
     * @param {*} newVal
     * @param {*} oldVal
716
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
717 718 719 720 721 722
     */
    @Watch('data.srfsourcekey')
    onSrfsourcekeyChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'srfsourcekey', newVal: newVal, oldVal: oldVal });
    }

ibizdev's avatar
ibizdev committed
723 724 725 726 727
    /**
     * 监控表单属性 personname 值
     *
     * @param {*} newVal
     * @param {*} oldVal
728
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
729 730 731 732 733 734 735 736 737 738 739
     */
    @Watch('data.personname')
    onPersonnameChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'personname', newVal: newVal, oldVal: oldVal });
    }

    /**
     * 监控表单属性 username 值
     *
     * @param {*} newVal
     * @param {*} oldVal
740
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
741 742 743 744 745 746
     */
    @Watch('data.username')
    onUsernameChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'username', newVal: newVal, oldVal: oldVal });
    }

ibizdev's avatar
ibizdev committed
747 748 749 750 751
    /**
     * 监控表单属性 userid 值
     *
     * @param {*} newVal
     * @param {*} oldVal
752
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
753 754 755 756 757 758 759
     */
    @Watch('data.userid')
    onUseridChange(newVal: any, oldVal: any) {
        this.formDataChange({ name: 'userid', newVal: newVal, oldVal: oldVal });
    }


760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
    /**
     * 显示更多模式切换操作
     *
     * @type {string}
     * @memberof MainBase
     */
    public manageContainerClick(name: string){
        let model = this.detailsModel[name];
        if(model.isManageContainer){
            model.setManageContainerStatus(!model.manageContainerStatus);
            model.showMoreModeItems.forEach((item:any) => {
                if(this.detailsModel[item].isControlledContent){
                    this.detailsModel[item].setVisible(model.manageContainerStatus? this.detailsModel[item].oldVisible : false);
                }
            });
        }
    }

ibizdev's avatar
ibizdev committed
778 779 780
    /**
     * 重置表单项值
     *
ibizdev's avatar
ibizdev committed
781
     * @public
ibizdev's avatar
ibizdev committed
782
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
783
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
784
     */
ibizdev's avatar
ibizdev committed
785
    public resetFormData({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
ibizdev's avatar
ibizdev committed
786 787 788 789 790 791
    }

    /**
      * 置空对象
      *
      * @param {any[]} args
792
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
793
      */
ibizdev's avatar
ibizdev committed
794
    public ResetData(_datas:any){
ibizdev's avatar
ibizdev committed
795 796 797 798 799 800 801 802 803 804 805 806
        if(Object.keys(_datas).length >0){
            Object.keys(_datas).forEach((name: string) => {
                if (this.data.hasOwnProperty(name)) {
                    this.data[name] = null;
                }
            });
        }
    }

    /**
     * 表单逻辑
     *
ibizdev's avatar
ibizdev committed
807
     * @public
ibizdev's avatar
ibizdev committed
808
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
809
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
810
     */
811
    public async formLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }){
ibizdev's avatar
ibizdev committed
812 813 814 815 816 817 818 819 820 821 822 823 824
                












825 826 827 828 829 830 831 832 833 834 835
    }

    /**
     * 表单项检查逻辑
     *
     * @public
     * @param name 属性名
     * @memberof MainBase
     */
    public checkItem(name:string):Promise<any> {
        return new Promise((resolve, reject) => {
836
                var validator = new schema({[name]:this.rules()[name]});
837 838 839 840 841 842 843
                validator.validate({[name]:this.data[name]}).then(()=>{
                    resolve(true);
                })
                .catch(() => {
                    resolve(false);
                });;
        })
ibizdev's avatar
ibizdev committed
844 845 846 847 848
    }

    /**
     * 表单值变化
     *
ibizdev's avatar
ibizdev committed
849
     * @public
ibizdev's avatar
ibizdev committed
850 851
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @returns {void}
852
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
853
     */
ibizdev's avatar
ibizdev committed
854
    public formDataChange({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
ibizdev's avatar
ibizdev committed
855 856 857 858 859 860 861 862 863 864 865
        if (this.ignorefieldvaluechange) {
            return;
        }
        this.resetFormData({ name: name, newVal: newVal, oldVal: oldVal });
        this.formLogic({ name: name, newVal: newVal, oldVal: oldVal });
        this.dataChang.next(JSON.stringify(this.data));
    }

    /**
     * 表单加载完成
     *
ibizdev's avatar
ibizdev committed
866
     * @public
ibizdev's avatar
ibizdev committed
867 868
     * @param {*} [data={}]
     * @param {string} [action]
869
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
870
     */
ibizdev's avatar
ibizdev committed
871
    public onFormLoad(data: any = {},action:string): void {
ibizdev's avatar
ibizdev committed
872
        if(Object.is(action,"save") || Object.is(action,"autoSave") || Object.is(action,"submit"))
ibizdev's avatar
ibizdev committed
873 874 875 876 877
        // 更新context的实体主键
        if(data.wfuser){
            Object.assign(this.context,{wfuser:data.wfuser})
        }
        this.setFormEnableCond(data);
878
        this.computeButtonState(data);
ibizdev's avatar
ibizdev committed
879 880 881 882 883 884 885 886 887 888 889 890
        this.fillForm(data,action);
        this.oldData = {};
        Object.assign(this.oldData, JSON.parse(JSON.stringify(this.data)));
        this.$store.commit('viewaction/setViewDataChange', { viewtag: this.viewtag, viewdatachange: false });
        this.formLogic({ name: '', newVal: null, oldVal: null });
    }

    /**
     * 值填充
     *
     * @param {*} [_datas={}]
     * @param {string} [action]
891
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
892
     */
ibizdev's avatar
ibizdev committed
893
    public fillForm(_datas: any = {},action:string): void {
894
        this.mixinData = _datas;
ibizdev's avatar
ibizdev committed
895 896 897 898 899 900 901 902 903
        this.ignorefieldvaluechange = true;
        Object.keys(_datas).forEach((name: string) => {
            if (this.data.hasOwnProperty(name)) {
                this.data[name] = _datas[name];
            }
        });
        if(Object.is(action,'loadDraft')){
            this.createDefault();
        }
ibizdev's avatar
ibizdev committed
904 905 906
        if(Object.is(action,'load')){
            this.updateDefault();
        }
ibizdev's avatar
ibizdev committed
907 908 909 910 911 912 913 914
        this.$nextTick(function () {
            this.ignorefieldvaluechange = false;
        })
    }

    /**
     * 设置表单项是否启用
     *
ibizdev's avatar
ibizdev committed
915
     * @public
ibizdev's avatar
ibizdev committed
916
     * @param {*} data
917
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
918
     */
ibizdev's avatar
ibizdev committed
919
    public setFormEnableCond(data: any): void {
ibizdev's avatar
ibizdev committed
920 921 922 923 924 925 926 927 928 929 930 931
        Object.values(this.detailsModel).forEach((detail: any) => {
            if (!Object.is(detail.detailType, 'FORMITEM')) {
                return;
            }
            const formItem: FormItemModel = detail;
            formItem.setEnableCond(data.srfuf);
        });
    }

    /**
     * 重置草稿表单状态
     *
ibizdev's avatar
ibizdev committed
932
     * @public
933
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
934
     */
ibizdev's avatar
ibizdev committed
935
    public resetDraftFormStates(): void {
ibizdev's avatar
ibizdev committed
936 937 938 939 940 941 942 943 944
        const form: any = this.$refs.form;
        if (form) {
            form.resetFields();
        }
    }

    /**
     * 重置校验结果
     *
945
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
946
     */
ibizdev's avatar
ibizdev committed
947
    public resetValidates(): void {
ibizdev's avatar
ibizdev committed
948 949 950 951 952 953 954 955 956 957 958 959 960
        Object.values(this.detailsModel).forEach((detail: any) => {
            if (!Object.is(detail.detailType, 'FORMITEM')) {
                return;
            }
            const formItem: FormItemModel = detail;
            formItem.setError('');
        });
    }

    /**
     * 填充校验结果 (后台)
     *
     * @param {any[]} fieldErrors
961
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
962
     */
ibizdev's avatar
ibizdev committed
963
    public fillValidates(fieldErrors: any[]): void {
ibizdev's avatar
ibizdev committed
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
        fieldErrors.forEach((error: any) => {
            const formItem: FormItemModel = this.detailsModel[error.field];
            if (!formItem) {
                return;
            }
            this.$nextTick(() => {
                formItem.setError(error.message);
            });
        });
    }

    /**
     * 表单校验状态
     *
     * @returns {boolean} 
979
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
980
     */
ibizdev's avatar
ibizdev committed
981
    public formValidateStatus(): boolean {
ibizdev's avatar
ibizdev committed
982 983 984 985 986 987 988 989 990 991 992 993
        const form: any = this.$refs.form;
        let validatestate: boolean = true;
        form.validate((valid: boolean) => {
            validatestate = valid ? true : false;
        });
        return validatestate
    }

    /**
     * 获取全部值
     *
     * @returns {*}
994
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
995
     */
ibizdev's avatar
ibizdev committed
996
    public getValues(): any {
ibizdev's avatar
ibizdev committed
997 998 999 1000 1001 1002 1003 1004
        return this.data;
    }

    /**
     * 表单项值变更
     *
     * @param {{ name: string, value: any }} $event
     * @returns {void}
1005
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1006
     */
ibizdev's avatar
ibizdev committed
1007
    public onFormItemValueChange($event: { name: string, value: any }): void {
ibizdev's avatar
ibizdev committed
1008 1009 1010 1011 1012 1013 1014 1015 1016
        if (!$event) {
            return;
        }
        if (!$event.name || Object.is($event.name, '') || !this.data.hasOwnProperty($event.name)) {
            return;
        }
        this.data[$event.name] = $event.value;
    }

1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
    /**
     * 编辑器行为触发
     *
     * @param {*} arg
     * @returns {void}
     * @memberof MainBase
     */
    public onFormItemActionClick(arg:any){
        if(arg && (arg instanceof Function)) arg();
    }

ibizdev's avatar
ibizdev committed
1028 1029 1030 1031 1032 1033
    /**
     * 设置数据项值
     *
     * @param {string} name
     * @param {*} value
     * @returns {void}
1034
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1035
     */
ibizdev's avatar
ibizdev committed
1036
    public setDataItemValue(name: string, value: any): void {
ibizdev's avatar
ibizdev committed
1037 1038 1039 1040 1041 1042 1043 1044 1045
        if (!name || Object.is(name, '') || !this.data.hasOwnProperty(name)) {
            return;
        }
        if (Object.is(this.data[name], value)) {
            return;
        }
        this.data[name] = value;
    }

1046 1047 1048 1049 1050 1051 1052
    /**
     * 计算表单按钮权限状态
     *
     * @param {*} [data] 传入数据
     * @memberof MainBase
     */
    public computeButtonState(data:any){
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
        let targetData:any = this.transformData(data);
        if(this.detailsModel && Object.keys(this.detailsModel).length >0){
            Object.keys(this.detailsModel).forEach((name:any) =>{
                if(this.detailsModel[name] && this.detailsModel[name].uiaction && this.detailsModel[name].uiaction.dataaccaction && Object.is(this.detailsModel[name].detailType,"BUTTON")){
                    this.detailsModel[name].isPower = true;
                    let tempUIAction:any = JSON.parse(JSON.stringify(this.detailsModel[name].uiaction));
                    let result: any[] = ViewTool.calcActionItemAuthState(targetData,[tempUIAction],this.appUIService);
                    this.detailsModel[name].visible = tempUIAction.visabled;
                    this.detailsModel[name].disabled = tempUIAction.disabled;
                    this.detailsModel[name].isPower = result[0] === 1 ? true : false;
                }
            })
1065 1066 1067
        }
    }

ibizdev's avatar
ibizdev committed
1068 1069 1070 1071 1072 1073


    /**
     * 分组界面行为事件
     *
     * @param {*} $event
1074
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1075
     */
ibizdev's avatar
ibizdev committed
1076
    public groupUIActionClick($event: any): void {
ibizdev's avatar
ibizdev committed
1077 1078 1079 1080 1081 1082 1083 1084 1085
        if (!$event) {
            return;
        }
        const item:any = $event.item;
    }

    /**
     * Vue声明周期(处理组件的输入属性)
     *
1086
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1087
     */
ibizdev's avatar
ibizdev committed
1088
    public created(): void {
ibizdev's avatar
ibizdev committed
1089 1090 1091 1092 1093 1094
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
1095
     *  @memberof MainBase
ibizdev's avatar
ibizdev committed
1096
     */    
ibizdev's avatar
ibizdev committed
1097
    public afterCreated(){
1098
        if(this.isautoload){
1099
            this.autoLoad({srfkey:this.context.wfuser});
1100
        }
ibizdev's avatar
ibizdev committed
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('autoload', action)) {
                    this.autoLoad(data);
                }
                if (Object.is('load', action)) {
                    this.load(data);
                }
                if (Object.is('loaddraft', action)) {
1113
                    this.loadDraft(data);
ibizdev's avatar
ibizdev committed
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
                }
                if (Object.is('save', action)) {
                    this.save(data,data.showResultInfo);
                }
                if (Object.is('remove', action)) {
                    this.remove(data);
                }
                if (Object.is('saveandexit', action)) {
                    this.saveAndExit(data);
                }
                if (Object.is('saveandnew', action)) {
                    this.saveAndNew(data);
                }
                if (Object.is('removeandexit', action)) {
                    this.removeAndExit(data);
                }
                if (Object.is('refresh', action)) {
                    this.refresh(data);
                }
1133
                if (Object.is('panelaction', action)) {
1134
                    this.panelAction(data.action,data.emitAction,data.data);
1135
                }
ibizdev's avatar
ibizdev committed
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
            });
        }
        this.dataChang
            .pipe(
                debounceTime(300),
                distinctUntilChanged()
            ).subscribe((data: any) => {
                if (this.autosave) {
                    this.autoSave();
                }
                const state = !Object.is(JSON.stringify(this.oldData), JSON.stringify(this.data)) ? true : false;
                this.$store.commit('viewaction/setViewDataChange', { viewtag: this.viewtag, viewdatachange: state });
            });
    }

    /**
     * vue 生命周期
     *
1154
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1155
     */
ibizdev's avatar
ibizdev committed
1156
    public destroyed() {
ibizdev's avatar
ibizdev committed
1157 1158 1159 1160 1161 1162
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
1163
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1164
     */
ibizdev's avatar
ibizdev committed
1165
    public afterDestroy() {
ibizdev's avatar
ibizdev committed
1166 1167 1168 1169 1170 1171
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        if (this.dataChangEvent) {
            this.dataChangEvent.unsubscribe();
        }
1172 1173 1174
        if(this.appStateEvent){
            this.appStateEvent.unsubscribe();
        }
ibizdev's avatar
ibizdev committed
1175 1176 1177 1178
    }

    /**
     *打印
1179
     *@memberof @memberof MainBase
ibizdev's avatar
ibizdev committed
1180
     */
ibizdev's avatar
ibizdev committed
1181
    public print(){
ibizdev's avatar
ibizdev committed
1182
        let _this:any = this;
1183
        _this.$print({id:'wfuser_main',popTitle:'主编辑表单'});
ibizdev's avatar
ibizdev committed
1184 1185 1186 1187 1188
    }

    /**
     * 部件刷新
     *
1189
     * @param {any} args
1190
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1191
     */
1192
    public refresh(args?: any): void {
ibizdev's avatar
ibizdev committed
1193
        let arg: any = {};
1194
        Object.assign(arg,args?args[0]:{});
ibizdev's avatar
ibizdev committed
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
        if (this.data.srfkey && !Object.is(this.data.srfkey, '')) {
            Object.assign(arg, { srfkey: this.data.srfkey });
            this.load(arg);
            return;
        }
        if (this.data.srfkeys && !Object.is(this.data.srfkeys, '')) {
            Object.assign(arg, { srfkey: this.data.srfkeys });
            this.load(arg);
            return;
        }
    }

    /**
     * 自动加载
     *
     * @param {*} [arg={}]
     * @returns {void}
1212
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1213
     */
ibizdev's avatar
ibizdev committed
1214
    public autoLoad(arg: any = {}): void {
ibizdev's avatar
ibizdev committed
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
        if (arg.srfkey && !Object.is(arg.srfkey, '')) {
            Object.assign(arg, { srfkey: arg.srfkey });
            this.load(arg);
            return;
        }
        if (arg.srfkeys && !Object.is(arg.srfkeys, '')) {
            Object.assign(arg, { srfkey: arg.srfkeys });
            this.load(arg);
            return;
        }
        this.loadDraft(arg);
    }

    /**
     * 加载
     *
ibizdev's avatar
ibizdev committed
1231
     * @public
ibizdev's avatar
ibizdev committed
1232
     * @param {*} [opt={}]
1233
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1234
     */
ibizdev's avatar
ibizdev committed
1235
    public load(opt: any = {}): void {
ibizdev's avatar
ibizdev committed
1236
        if(!this.loadAction){
1237
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserEditView' + (this.$t('app.formpage.notconfig.loadaction') as string) });
ibizdev's avatar
ibizdev committed
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
            return;
        }
        const arg: any = { ...opt };
        let viewparamResult:any = Object.assign(arg,this.viewparams);
        const get: Promise<any> = this.service.get(this.loadAction,JSON.parse(JSON.stringify(this.context)),{viewparams:viewparamResult}, this.showBusyIndicator);
        get.then((response: any) => {
            if (response && response.status === 200) {
                const data = response.data;
                this.onFormLoad(data,'load');
                this.$emit('load', data);
                this.$nextTick(() => {
                    this.formState.next({ type: 'load', data: data });
                });
            }
        }).catch((response: any) => {
ibizdev's avatar
ibizdev committed
1253
            if (response && response.status && response.data) {
1254
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1255 1256 1257
                return;
            }
            if (!response || !response.status || !response.data) {
1258
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
1259 1260 1261 1262 1263 1264 1265 1266 1267
                return;
            }
        });
    }

    /**
     * 加载草稿
     *
     * @param {*} [opt={}]
1268
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1269
     */
ibizdev's avatar
ibizdev committed
1270
    public loadDraft(opt: any = {}): void {
ibizdev's avatar
ibizdev committed
1271
        if(!this.loaddraftAction){
1272
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserEditView' + (this.$t('app.formpage.notconfig.loaddraftaction') as string) });
ibizdev's avatar
ibizdev committed
1273 1274 1275 1276 1277 1278 1279
            return;
        }
        const arg: any = { ...opt } ;
        let viewparamResult:any = Object.assign(arg,this.viewparams);
        let post: Promise<any> = this.service.loadDraft(this.loaddraftAction,JSON.parse(JSON.stringify(this.context)),{viewparams:viewparamResult}, this.showBusyIndicator);
        post.then((response: any) => {
            if (!response.status || response.status !== 200) {
ibizdev's avatar
ibizdev committed
1280
                if (response.data) {
1281
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1282 1283 1284 1285 1286 1287 1288
                }
                return;
            }

            const data = response.data;
            this.resetDraftFormStates();
            this.onFormLoad(data,'loadDraft');
1289
            data.wfuser = null;
ibizdev's avatar
ibizdev committed
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
            this.$emit('load', data);
            this.$nextTick(() => {
                this.formState.next({ type: 'load', data: data });
            });
            setTimeout(() => {
                const form: any = this.$refs.form;
                if (form) {
                    form.fields.forEach((field: any) => {
                        field.validateMessage = "";
                        field.validateState = "";
                        field.validateStatus = false;
                    });
                }
            });
        }).catch((response: any) => {
ibizdev's avatar
ibizdev committed
1305
            if (response && response.status  && response.data) {
1306
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1307 1308 1309
                return;
            }
            if (!response || !response.status || !response.data) {
1310
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
1311 1312 1313 1314 1315 1316 1317 1318 1319
                return;
            }
        });
    }

    /**
     * 自动保存
     *
     * @param {*} [opt={}]
1320
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1321
     */
ibizdev's avatar
ibizdev committed
1322
    public autoSave(opt: any = {}): void {
ibizdev's avatar
ibizdev committed
1323 1324 1325 1326 1327 1328
        if (!this.formValidateStatus()) {
            return;
        }
        const arg: any = { ...opt };
        const data = this.getValues();
        Object.assign(arg, data);
1329
        Object.assign(arg,{srfmajortext:data[this.majorMessageField]});
ibizdev's avatar
ibizdev committed
1330 1331 1332
        const action: any = Object.is(data.srfuf, '1') ? this.updateAction : this.createAction;
        if(!action){
            let actionName:any = Object.is(data.srfuf, '1')?"updateAction":"createAction";
1333
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserEditView' + (this.$t('app.formpage.notconfig.actionname') as string) });
ibizdev's avatar
ibizdev committed
1334 1335 1336 1337 1338 1339
            return;
        }
        Object.assign(arg,{viewparams:this.viewparams});
        const post: Promise<any> = this.service.add(action, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator);
        post.then((response: any) => {
            if (!response.status || response.status !== 200) {
ibizdev's avatar
ibizdev committed
1340
                if (response.data) {
1341
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1342 1343 1344 1345 1346 1347 1348
                }
                return;
            }

            const data = response.data;
            this.onFormLoad(data,'autoSave');
            this.$emit('save', data);
1349
            AppCenterService.notifyMessage({name:"WFUser",action:'appRefresh',data:data});
ibizdev's avatar
ibizdev committed
1350 1351 1352 1353
            this.$nextTick(() => {
                this.formState.next({ type: 'save', data: data });
            });
        }).catch((response: any) => {
ibizdev's avatar
ibizdev committed
1354
            if (response && response.status && response.data) {
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
                    if (response.data.errorKey) {
                        if(Object.is(response.data.errorKey, "versionCheck")) {
                            this.$Modal.confirm({
                                title: (this.$t('app.formpage.saveerror') as string),
                                content: (this.$t('app.formpage.savecontent') as string),
                                onOk: () => {
                                    this.refresh([]);
                                },
                                onCancel: () => { }
                            });
                        } else if(Object.is(response.data.errorKey, 'DupCheck')) {
                            let errorProp: string = response.data.message.match(/\[[a-zA-Z]*\]/)[0];
                            let name: string = this.service.getNameByProp(errorProp.substr(1, errorProp.length-2));
                            if(name) {
                                this.$Notice.error({
                                    title: (this.$t('app.commonWords.createFailed') as string),
                                    desc: this.detailsModel[name].caption + " : " + arg[name] + (this.$t('app.commonWords.isExist') as string) + '!',
                                });
                            } else {
                                this.$Notice.error({
                                    title: (this.$t('app.commonWords.createFailed') as string),
                                    desc: response.data.message?response.data.message:(this.$t('app.commonWords.sysException') as string),
                                })
                            }
                        }else if(Object.is(response.data.errorKey, 'DuplicateKeyException')){
                            this.$Notice.error({
                                title: (this.$t('app.commonWords.createFailed') as string),
                                desc: this.detailsModel[this.formKeyItemName].caption + " : " + arg[this.formKeyItemName] + (this.$t('app.commonWords.isExist') as string) + '!',
                            });
                        } else {
                            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message?response.data.message:(this.$t('app.commonWords.sysException') as string) });
                        }
                    } else {
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message?response.data.message:(this.$t('app.commonWords.sysException') as string) });
                    }
                    return;
                } else {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1393
                }
ibizdev's avatar
ibizdev committed
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
        });
    }

    /**
     * 保存
     *
     * @param {*} [opt={}]
     * @param {boolean} [showResultInfo] 
     * @param {boolean} [ifStateNext] formState是否下发通知
     * @returns {Promise<any>}
1404
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1405
     */
ibizdev's avatar
ibizdev committed
1406
    public async save(opt: any = {}, showResultInfo?: boolean, ifStateNext: boolean = true): Promise<any> {
ibizdev's avatar
ibizdev committed
1407 1408 1409
        return new Promise((resolve: any, reject: any) => {
            showResultInfo = showResultInfo === undefined ? true : false;
            if (!this.formValidateStatus()) {
1410 1411 1412 1413 1414 1415 1416 1417 1418
                if(this.errorMessages && this.errorMessages.length > 0) {
                    let descMessage: string = '';
                    this.errorMessages.forEach((message: any) => {
                        descMessage = descMessage + '<p>' + message.error + '<p>';
                    })
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: descMessage });
                } else {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.formpage.valuecheckex') as string) });
                }
ibizdev's avatar
ibizdev committed
1419 1420 1421 1422 1423
                return;
            }
            const arg: any = { ...opt };
            const data = this.getValues();
            Object.assign(arg, this.context);
1424
            Object.assign(arg, data);
1425
            Object.assign(arg,{srfmajortext:data[this.majorMessageField]});
ibizdev's avatar
ibizdev committed
1426 1427 1428 1429 1430 1431 1432 1433 1434
            if (ifStateNext) {
                this.drcounter = 0;
                if(this.drcounter !== 0){
                    this.drsaveopt = opt;
                    this.formState.next({ type: 'beforesave', data: arg });//先通知关系界面保存
                    this.saveState = resolve;
                    return;
                }
            }
1435 1436 1437
            if(this.viewparams && this.viewparams.copymode){
                data.srfuf = '0';
            }
ibizdev's avatar
ibizdev committed
1438 1439 1440
            const action: any = Object.is(data.srfuf, '1') ? this.updateAction : this.createAction;
            if(!action){
                let actionName:any = Object.is(data.srfuf, '1')?"updateAction":"createAction";
1441
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserEditView' + (this.$t('app.formpage.notconfig.actionname') as string) });
ibizdev's avatar
ibizdev committed
1442 1443 1444 1445 1446 1447
                return;
            }
            Object.assign(arg,{viewparams:this.viewparams});
            const post: Promise<any> = Object.is(data.srfuf, '1')?this.service.update(action, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator):this.service.add(action,JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator);
            post.then((response: any) => {
                if (!response.status || response.status !== 200) {
ibizdev's avatar
ibizdev committed
1448
                    if (response.data) {
1449
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1450 1451 1452
                    }
                    return;
                }
1453
                this.viewparams.copymode = false;
ibizdev's avatar
ibizdev committed
1454 1455 1456
                const data = response.data;
                this.onFormLoad(data,'save');
                this.$emit('save', data);
1457
                AppCenterService.notifyMessage({name:"WFUser",action:'appRefresh',data:data});
ibizdev's avatar
ibizdev committed
1458 1459 1460 1461
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: data });
                });
                if (showResultInfo) {
1462
                    this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;'+ (this.$t('app.formpage.savesuccess') as string) });
ibizdev's avatar
ibizdev committed
1463 1464 1465
                }
                resolve(response);
            }).catch((response: any) => {
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
                if (response && response.status && response.data) {
                    if (response.data.errorKey) {
                        if(Object.is(response.data.errorKey, "versionCheck")) {
                            this.$Modal.confirm({
                                title: (this.$t('app.formpage.saveerror') as string),
                                content: (this.$t('app.formpage.savecontent') as string),
                                onOk: () => {
                                    this.refresh([]);
                                },
                                onCancel: () => { }
                            });
                        } else if(Object.is(response.data.errorKey, 'DupCheck')) {
                            let errorProp: string = response.data.message.match(/\[[a-zA-Z]*\]/)[0];
                            let name: string = this.service.getNameByProp(errorProp.substr(1, errorProp.length-2));
                            if(name) {
                                this.$Notice.error({
                                    title: (this.$t('app.commonWords.createFailed') as string),
                                    desc: this.detailsModel[name].caption + " : " + arg[name] + (this.$t('app.commonWords.isExist') as string) + '!',
                                });
                            } else {
                                this.$Notice.error({
                                    title: (this.$t('app.commonWords.createFailed') as string),
                                    desc: response.data.message,
                                })
                            }
                        } else {
                            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
                        }
                    } else {
1495
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1496 1497
                        reject(response);
                    }
ibizdev's avatar
ibizdev committed
1498
                    return;
1499
                } else {
1500
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
1501
                    reject(response);
1502
                }    
ibizdev's avatar
ibizdev committed
1503 1504 1505 1506 1507 1508 1509 1510
                reject(response);
            });
        })
    }

    /**
    * 删除
    *
ibizdev's avatar
ibizdev committed
1511
    * @public
ibizdev's avatar
ibizdev committed
1512
    * @param {*} [opt={}]
1513
    * @memberof MainBase
ibizdev's avatar
ibizdev committed
1514
    */
ibizdev's avatar
ibizdev committed
1515
    public remove(opt:Array<any> = [],showResultInfo?: boolean): Promise<any> {
ibizdev's avatar
ibizdev committed
1516 1517
        return new Promise((resolve: any, reject: any) => {
            if(!this.removeAction){
1518
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: 'WFUserEditView' + (this.$t('app.formpage.notconfig.removeaction') as string) });
ibizdev's avatar
ibizdev committed
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
                return;
            }
            const arg: any = opt[0];
            const _this: any = this;
            Object.assign(arg,{viewparams:this.viewparams});
            this.service.delete(_this.removeAction, JSON.parse(JSON.stringify(this.context)),arg, showResultInfo).then((response: any) => {
                if (response) {
                    const data = response.data;
                    this.$emit('remove',data);
                    this.formState.next({ type: 'remove', data: data });
                    this.data.ismodify = false;
1530
                    this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;' + (this.$t('app.formpage.deletesuccess') as string) });
1531
                    AppCenterService.notifyMessage({name:"WFUser",action:'appRefresh',data:data});
ibizdev's avatar
ibizdev committed
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
                    resolve(response);
                }
            }).catch((error: any) => {
                const { data: _data } = error;
                this.$Notice.error({ title: _data.title, desc: _data.message });
                reject(error);
            });
        });
    }

    /**
     * 工作流启动
     *
     * @param {*} [data={}]
ibizdev's avatar
ibizdev committed
1546
     * @param {*} [localdata={}]
ibizdev's avatar
ibizdev committed
1547
     * @returns {Promise<any>}
1548
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1549
     */
ibizdev's avatar
ibizdev committed
1550
    public async wfstart(data: any,localdata?:any): Promise<any> {
ibizdev's avatar
ibizdev committed
1551 1552
        return new Promise((resolve: any, reject: any) => {
            const _this: any = this;
1553 1554 1555
            const formData:any = this.getData();
            const copyData:any = Util.deepCopy(formData);
            const post: Promise<any> =  Object.is(formData.srfuf, '1')?this.service.update(this.updateAction, JSON.parse(JSON.stringify(this.context)),formData, this.showBusyIndicator,true):this.service.add(this.createAction,JSON.parse(JSON.stringify(this.context)),formData, this.showBusyIndicator,true);
ibizdev's avatar
ibizdev committed
1556
            post.then((response:any) =>{
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
                const responseData:any = response.data;
                let tempResponseData:any = Util.deepCopy(response);
                this.service.handleResponse('save', tempResponseData);
                const arg:any = tempResponseData.data;
                // 保存完成UI处理
                this.onFormLoad(arg,'save');
                this.$emit('save', arg);
                AppCenterService.notifyMessage({name:"WFUser",action:'appRefresh',data:data});
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: arg });
                });
1568
                // 准备工作流数据,填充未存库数据
1569 1570
                Object.assign(arg,copyData);
                // 准备提交参数
ibizdev's avatar
ibizdev committed
1571
                if(this.viewparams){
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
                    let copyViewParams:any = Util.deepCopy(this.viewparams);
                    if(copyViewParams.w){
                        delete copyViewParams.w;
                    }
                    Object.assign(responseData,copyViewParams);
                }
                Object.assign(arg,{viewparams:responseData});
                // 强制补充srfwfmemo
                if(this.srfwfmemo){
                    Object.assign(arg,{srfwfmemo:this.srfwfmemo});
ibizdev's avatar
ibizdev committed
1582
                }
ibizdev's avatar
ibizdev committed
1583
                const result: Promise<any> = this.service.wfstart(_this.WFStartAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,localdata);
ibizdev's avatar
ibizdev committed
1584 1585
                result.then((response: any) => {
                    if (!response || response.status !== 200) {
ibizdev's avatar
ibizdev committed
1586
                        if(response.data){
1587
                            this.$Notice.error({ title: '', desc: (this.$t('app.formpage.workflow.starterror') as string) + ', ' + response.data.message });
ibizdev's avatar
ibizdev committed
1588
                        }
ibizdev's avatar
ibizdev committed
1589 1590
                        return;
                    }
1591
                    this.$Notice.info({ title: '', desc: (this.$t('app.formpage.workflow.startsuccess') as string) });
ibizdev's avatar
ibizdev committed
1592 1593
                    resolve(response);
            }).catch((response: any) => {
ibizdev's avatar
ibizdev committed
1594
                if (response && response.status && response.data) {
1595
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1596 1597 1598 1599
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
1600
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
1601 1602 1603 1604 1605 1606
                    reject(response);
                    return;
                }
                reject(response);
            });
            }).catch((response: any) => {
ibizdev's avatar
ibizdev committed
1607
                    if (response && response.status && response.data) {
1608
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1609 1610 1611 1612
                        reject(response);
                        return;
                    }
                    if (!response || !response.status || !response.data) {
1613
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625
                        reject(response);
                        return;
                    }
                    reject(response);
            })
        });
    }

    /**
     * 工作流提交
     *
     * @param {*} [data={}]
ibizdev's avatar
ibizdev committed
1626
     * @param {*} [localdata={}]
ibizdev's avatar
ibizdev committed
1627
     * @returns {Promise<any>}
1628
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1629
     */
ibizdev's avatar
ibizdev committed
1630
    public async wfsubmit(data: any,localdata?:any): Promise<any> {
ibizdev's avatar
ibizdev committed
1631 1632 1633
        return new Promise((resolve: any, reject: any) => {
        const _this: any = this;
        const arg: any = data[0];
1634
        const copyData:any = Util.deepCopy(arg);
ibizdev's avatar
ibizdev committed
1635 1636 1637 1638
        Object.assign(arg,{viewparams:this.viewparams});
        if (!arg.wfuser || Object.is(arg.wfuser, '')) {
            return;
        }
1639
        const post: Promise<any> = Object.is(arg.srfuf, '1')?this.service.update(this.updateAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,true):this.service.add(this.createAction,JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,true);
ibizdev's avatar
ibizdev committed
1640
        post.then((response:any) =>{
1641 1642 1643 1644
                const responseData:any = response.data;
                let tempResponseData:any = Util.deepCopy(response);
                this.service.handleResponse('save', tempResponseData);
                const arg:any = tempResponseData.data;
ibizdev's avatar
ibizdev committed
1645 1646 1647
                // 保存完成UI处理
                this.onFormLoad(arg,'save');
                this.$emit('save', arg);
1648
                AppCenterService.notifyMessage({name:"WFUser",action:'appRefresh',data:data});
ibizdev's avatar
ibizdev committed
1649 1650 1651
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: arg });
                });
1652
                // 准备工作流数据,填充未存库数据
1653
                Object.assign(arg,copyData);
ibizdev's avatar
ibizdev committed
1654
                // 准备提交参数
ibizdev's avatar
ibizdev committed
1655
                if(this.viewparams){
1656
                    Object.assign(responseData,this.viewparams);
ibizdev's avatar
ibizdev committed
1657
                }
1658
                Object.assign(arg,{viewparams:responseData});
1659 1660 1661 1662
                // 强制补充srfwfmemo
                if(this.srfwfmemo){
                    Object.assign(arg,{srfwfmemo:this.srfwfmemo});
                }
ibizdev's avatar
ibizdev committed
1663
                const result: Promise<any> = this.service.wfsubmit(_this.WFSubmitAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,localdata);
ibizdev's avatar
ibizdev committed
1664 1665
                result.then((response: any) => {
                    if (!response || response.status !== 200) {
ibizdev's avatar
ibizdev committed
1666
                        if(response.data){
1667
                            this.$Notice.error({ title: '', desc: (this.$t('app.formpage.workflow.submiterror') as string) + ', ' + response.data.message });
ibizdev's avatar
ibizdev committed
1668
                        }
ibizdev's avatar
ibizdev committed
1669 1670
                        return;
                    }
ibizdev's avatar
ibizdev committed
1671 1672
                    this.onFormLoad(arg,'submit');
                    this.$store.dispatch('viewaction/datasaved', { viewtag: this.viewtag });
1673
                    this.$Notice.info({ title: '', desc: (this.$t('app.formpage.workflow.submitsuccess') as string) });
ibizdev's avatar
ibizdev committed
1674 1675
                    resolve(response);
            }).catch((response: any) => {
ibizdev's avatar
ibizdev committed
1676
                if (response && response.status && response.data) {
1677
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1678 1679 1680 1681
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
1682
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
1683 1684 1685 1686 1687 1688
                    reject(response);
                    return;
                }
                reject(response);
            });
            }).catch((response: any) => {
ibizdev's avatar
ibizdev committed
1689
                    if (response && response.status && response.data) {
1690
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1691 1692 1693 1694
                        reject(response);
                        return;
                    }
                    if (!response || !response.status || !response.data) {
1695
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
1696 1697 1698 1699 1700 1701 1702 1703
                        reject(response);
                        return;
                    }
                    reject(response);
            })
        })
    }

1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
    /**
     * 面板行为
     *
     * @param {string} [action] 调用的实体行为
     * @param {string} [emitAction] 抛出行为
     * @param {*} [data={}] 传入数据
     * @param {boolean} [showloading] 是否显示加载状态
     * 
     * @memberof MainBase
     */
    public panelAction(action:string,emitAction:string,data:any ={},showloading?:boolean):void{
        if (!action || (action && Object.is(action, ''))) {
            return;
        }
        const arg: any = { ...data };
        const formdata = this.getValues();
        Object.assign(arg, formdata);
        Object.assign(arg,this.viewparams);
        const post: Promise<any> = this.service.frontLogic(action,JSON.parse(JSON.stringify(this.context)),arg, showloading);
        post.then((response: any) => {
            if (!response.status || response.status !== 200) {
                if (response.data) {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
                }
                return;
            }
            const data = response.data;
            this.onFormLoad(data,emitAction);
            this.$emit(emitAction, data);
            this.$nextTick(() => {
                this.formState.next({ type: emitAction, data: data });
            });
        }).catch((response: any) => {
            if (response && response.status && response.data) {
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
                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;
            }
        });
    }

ibizdev's avatar
ibizdev committed
1748 1749 1750 1751 1752 1753 1754 1755
    /**
     * 表单项更新
     *
     * @param {string} mode 界面行为名称
     * @param {*} [data={}] 请求数据
     * @param {string[]} updateDetails 更新项
     * @param {boolean} [showloading] 是否显示加载状态
     * @returns {void}
1756
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1757
     */
ibizdev's avatar
ibizdev committed
1758
    public updateFormItems(mode: string, data: any = {}, updateDetails: string[], showloading?: boolean): void {
ibizdev's avatar
ibizdev committed
1759 1760 1761 1762 1763 1764 1765 1766
        if (!mode || (mode && Object.is(mode, ''))) {
            return;
        }
        const arg: any = { ...data };
        Object.assign(arg,this.viewparams);
        const post: Promise<any> = this.service.frontLogic(mode,JSON.parse(JSON.stringify(this.context)),arg, showloading);
        post.then((response: any) => {
            if (!response || response.status !== 200) {
1767
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.formpage.updateerror') as string) });
ibizdev's avatar
ibizdev committed
1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
                return;
            }
            const data = response.data;
            const _data: any = {};
            updateDetails.forEach((name: string) => {
                if (!data.hasOwnProperty(name)) {
                    return;
                }
                Object.assign(_data, { [name]: data[name] });
            });
            this.setFormEnableCond(_data);
            this.fillForm(_data,'updateFormItem');
            this.formLogic({ name: '', newVal: null, oldVal: null });
            this.dataChang.next(JSON.stringify(this.data));
1782
            AppCenterService.notifyMessage({name:"WFUser",action:'appRefresh',data:data});
ibizdev's avatar
ibizdev committed
1783 1784 1785 1786
            this.$nextTick(() => {
                this.formState.next({ type: 'updateformitem', ufimode: arg.srfufimode, data: _data });
            });
        }).catch((response: any) => {
ibizdev's avatar
ibizdev committed
1787
            if (response && response.status && response.data) {
1788
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
ibizdev's avatar
ibizdev committed
1789 1790 1791
                return;
            }
            if (!response || !response.status || !response.data) {
1792
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
ibizdev's avatar
ibizdev committed
1793 1794 1795 1796 1797 1798 1799 1800 1801
                return;
            }
        });
    }

    /**
     * 回车事件
     *
     * @param {*} $event
1802
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1803
     */
ibizdev's avatar
ibizdev committed
1804
    public onEnter($event: any): void {
ibizdev's avatar
ibizdev committed
1805 1806 1807 1808 1809 1810
    }

    /**
     * 保存并退出
     *
     * @param {any[]} args
1811
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1812
     */
ibizdev's avatar
ibizdev committed
1813
    public saveAndExit(data:any[]):Promise<any>{
ibizdev's avatar
ibizdev committed
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835
        let _this = this;
        return new Promise((resolve: any, reject: any) =>{
            let arg: any = {};
            if(data && data.length > 0){
                Object.assign(arg,data[0]);
            }
            _this.currentAction = "saveAndExit";
            _this.save([arg]).then((res) =>{
                if(res){
                    _this.closeView(res.data);
                }
                resolve(res);
            }).catch((error) =>{
                reject(error);
            })
        })
    }

    /**
     * 保存并新建
     *
     * @param {any[]} args
1836
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1837
     */
ibizdev's avatar
ibizdev committed
1838
    public saveAndNew(data:any[]):Promise<any>{
ibizdev's avatar
ibizdev committed
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
        let _this = this;
        return new Promise((resolve: any, reject: any) =>{
            let arg: any = {};
            if(data && data.length > 0){
                Object.assign(arg,data[0]);
            }
            _this.currentAction = "saveAndNew";
            _this.save([arg]).then((res) =>{
                _this.ResetData(res);
                _this.loadDraft({});
            }).catch((error) =>{
                reject(error);
            })
        })
    }

    /**
     * 删除并退出
     *
     * @param {any[]} args
1859
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1860
     */
ibizdev's avatar
ibizdev committed
1861
    public removeAndExit(data:any[]):Promise<any>{
ibizdev's avatar
ibizdev committed
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882
        let _this = this;
        return new Promise((resolve: any, reject: any) =>{
            let arg: any = {};
            if(data && data.length > 0){
                Object.assign(arg,data[0]);
            }
            _this.remove([arg]).then((res) =>{
                if(res){
                  _this.closeView(res.data);
                }
                resolve(res);
            }).catch((error) =>{
                reject(error);
            })
        })
    }

    /**
    * 关系界面数据保存完成
    *
    * @param {any} $event
1883
    * @memberof MainBase
ibizdev's avatar
ibizdev committed
1884
    */
ibizdev's avatar
ibizdev committed
1885
    public drdatasaved($event:any){
ibizdev's avatar
ibizdev committed
1886 1887
        let _this = this;
        this.drcounter--;
1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
        if(this.drcounter === 0){
            this.save(this.drsaveopt, undefined, false).then((res) =>{
                this.saveState(res);
                this.drsaveopt = {};
                if(Object.is(_this.currentAction, "saveAndNew")){
                    _this.ResetData(res);
                    _this.loadDraft({});
                }else if(Object.is(_this.currentAction, "saveAndExit")){
                    if(res){
                        _this.closeView(res.data);
                    }
ibizdev's avatar
ibizdev committed
1899
                }
1900 1901
            });
        }
ibizdev's avatar
ibizdev committed
1902 1903 1904 1905
    }

    /**
     * 新建默认值
1906
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1907 1908 1909 1910
     */
    public createDefault(){                    
    }

ibizdev's avatar
ibizdev committed
1911 1912
    /**
     * 更新默认值
1913
     * @memberof MainBase
ibizdev's avatar
ibizdev committed
1914 1915 1916 1917
     */
    public updateDefault(){                    
    }

1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928

    /**
     * 面板数据变化处理事件
     * @param {any} item 当前列数据
     * @param {any} $event 面板事件数据
     *
     * @memberof MainBase
     */
    public onPanelDataChange(item:any,$event:any) {
        Object.assign(item, $event, {rowDataState:'update'});
    }
ibizdev's avatar
ibizdev committed
1929 1930 1931 1932 1933 1934 1935
    
}
</script>

<style lang='less'>
@import './main-form.less';
</style>