CONTROL-BASE.vue.ftl 79.0 KB
Newer Older
1 2 3 4
<#ibizinclude>
../../@MACRO/LANG_FUN.ftl
</#ibizinclude>
<template>
5 6 7
<#if ctrl.render??> 
${ctrl.render.code}
<#else>
8
    ${P.getPartCode(item,'FORM').code}
9
</#if>
10 11 12 13 14
</template>

<#assign import_block>
import { FormButtonModel, FormPageModel, FormItemModel, FormDRUIPartModel, FormPartModel, FormGroupPanelModel, FormIFrameModel, FormRowItemModel, FormTabPageModel, FormTabPanelModel, FormUserControlModel } from '@/model/form-detail';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
tony001's avatar
tony001 committed
15
import schema from 'async-validator';
16
import { Environment } from '@/environments/environment';
17 18 19 20 21
</#assign>
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>

KK's avatar
KK committed
22 23 24
<#ibizinclude>
../@MACRO/FUNC/MACRO.ftl
</#ibizinclude>
tony001's avatar
tony001 committed
25 26 27 28 29 30
    /**
     * 视图默认使用
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
31
    @Inject({from:'navModel',default: 'tab'})
tony001's avatar
tony001 committed
32 33
    public navModel!:string;

34 35 36 37 38 39 40
    /**
     * 主键表单项名称
     *
     * @protected
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
41
    public formKeyItemName: string = '<#list ctrl.getPSDEFormItems() as formitem><#if formitem.getPSAppDEField?? && formitem.getPSAppDEField()??><#if !formitem.isHidden() && formitem.getPSAppDEField().isKeyField()>${formitem.getName()}</#if></#if></#list>';
42

tony001's avatar
tony001 committed
43 44 45 46 47 48 49 50
    /**
     * 界面UI服务对象
     *
     * @type {${srfclassname('${appde.getCodeName()}')}UIService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
    public appUIService:${srfclassname('${appde.getCodeName()}')}UIService = new ${srfclassname('${appde.getCodeName()}')}UIService(this.$store);

51 52 53
    /**
     * 工作流审批意见控件绑定值
     *
KK's avatar
KK committed
54
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
55 56
     */
    public srfwfmemo:string = "";
57 58 59 60 61
    
    /**
     * 获取多项数据
     *
     * @returns {any[]}
KK's avatar
KK committed
62
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
63 64 65 66 67 68 69 70 71
     */
    public getDatas(): any[] {
        return [this.data];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
KK's avatar
KK committed
72
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
73 74 75 76 77 78 79 80 81
     */
    public getData(): any {
        return this.data;
    }

    /**
     * 是否默认保存
     *
     * @type {boolean}
KK's avatar
KK committed
82
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
83
     */
84
    @Prop({ default: false }) public autosave?: boolean;
85 86 87 88 89

    /**
     * 显示处理提示
     *
     * @type {boolean}
KK's avatar
KK committed
90
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
91
     */
92
    @Prop({ default: true }) public showBusyIndicator?: boolean;
93 94 95 96 97

    /**
     * 部件行为--submit
     *
     * @type {string}
KK's avatar
KK committed
98
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
99
     */
100
    @Prop() public WFSubmitAction!: string;
101 102 103 104 105
    
    /**
     * 部件行为--start
     *
     * @type {string}
KK's avatar
KK committed
106
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
107
     */
108
    @Prop() public WFStartAction!: string;
109 110 111 112 113
    
    /**
     * 部件行为--update
     *
     * @type {string}
KK's avatar
KK committed
114
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
115
     */
116
    @Prop() public updateAction!: string;
117 118 119 120 121
    
    /**
     * 部件行为--remove
     *
     * @type {string}
KK's avatar
KK committed
122
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
123
     */
124
    @Prop() public removeAction!: string;
125 126 127 128 129
    
    /**
     * 部件行为--loaddraft
     *
     * @type {string}
KK's avatar
KK committed
130
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
131
     */
132
    @Prop() public loaddraftAction!: string;
133 134 135 136 137
    
    /**
     * 部件行为--load
     *
     * @type {string}
KK's avatar
KK committed
138
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
139
     */
140
    @Prop() public loadAction!: string;
141 142 143 144 145
    
    /**
     * 部件行为--create
     *
     * @type {string}
KK's avatar
KK committed
146
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
147
     */
148
    @Prop() public createAction!: string;
149 150 151 152 153

    /**
     * 部件行为--create
     *
     * @type {string}
KK's avatar
KK committed
154
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
155
     */
156
    @Prop() public searchAction!: string;
157 158 159 160 161

    /**
     * 视图标识
     *
     * @type {string}
KK's avatar
KK committed
162
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
163
     */
164
    @Prop() public viewtag!: string;
165 166 167 168 169

    /**
     * 表单状态
     *
     * @type {Subject<any>}
KK's avatar
KK committed
170
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
171
     */
172
    public formState: Subject<any> = new Subject();
173 174 175 176 177

    /**
     * 忽略表单项值变化
     *
     * @type {boolean}
KK's avatar
KK committed
178
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
179
     */
180
    public ignorefieldvaluechange: boolean = false;
181 182 183 184

    /**
     * 数据变化
     *
185
     * @public
186
     * @type {Subject<any>}
KK's avatar
KK committed
187
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
188
     */
189
    public dataChang: Subject<any> = new Subject();
190 191 192 193

    /**
     * 视图状态事件
     *
194
     * @public
195
     * @type {(Subscription | undefined)}
KK's avatar
KK committed
196
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
197
     */
198
    public dataChangEvent: Subscription | undefined;
199 200 201 202

    /**
     * 原始数据
     *
203
     * @public
204
     * @type {*}
KK's avatar
KK committed
205
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
206
     */
207
    public oldData: any = {};
208

209 210 211 212 213 214 215 216
    /**
     * 混入表单数据对象
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public mixinData:any = {};

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    /**
     * 表单项校验错误提示信息
     * 
     *  @memberof  ${srfclassname('${ctrl.codeName}')}Base
     */
    public errorMessages: Array<any> = [];   

    /**
     * 设置表单项错误提示信息
     * 
     * @param {*} prop 表单项字段名
     * @param {*} status 校验状态
     * @param {*} error 错误信息
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    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});
        }
    }

246 247 248 249
    /**
     * 表单数据对象
     *
     * @type {*}
KK's avatar
KK committed
250
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
251
     */
252
    public data: any = {
253
        <#list ctrl.getAllPSDEFormDetails() as item>
254
        <#if item.getDetailType?? && item.getDetailType()?? && (item.getDetailType() == "FORMITEM" || item.getDetailType() == "FORMPART")>
255
        ${item.getName()}: null,
256
        </#if>
257 258 259 260 261 262 263 264
        </#list>
        ${ctrl.getPSAppDataEntity().getCodeName()?lower_case}:null,
    };

    /**
      * 当前执行的行为逻辑
      *
      * @type {string}
KK's avatar
KK committed
265
      * @memberof ${srfclassname('${ctrl.codeName}')}Base
266
      */
267
    public currentAction: string = "";
268 269 270 271 272

    /**
      * 关系界面计数器
      *
      * @type {number}
KK's avatar
KK committed
273
      * @memberof ${srfclassname('${ctrl.codeName}')}Base
274
      */
275
    public drcounter: number = 0;
276 277 278 279 280

    /**
      * 需要等待关系界面保存时,第一次调用save参数的备份
      *
      * @type {number}
KK's avatar
KK committed
281
      * @memberof ${srfclassname('${ctrl.codeName}')}Base
282
      */
283
    public drsaveopt: any = {};
284 285 286 287 288

    /**
      * 表单保存回调存储对象
      *
      * @type {any}
KK's avatar
KK committed
289
      * @memberof ${srfclassname('${ctrl.codeName}')}Base
290
      */
291
    public saveState:any ;
292

293 294 295 296 297 298
    /**
     * 主信息属性映射表单项名称
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
299
    public majorMessageField: string = "<#list ctrl.getAllPSDEFormDetails() as item><#if item.getDetailType?? && item.getDetailType()?? && (item.getDetailType() == "FORMITEM") && !item.isHidden()><#if item.getPSAppDEField?? && item.getPSAppDEField()?? && item.getPSAppDEField().isMajorField()>${item.getName()}</#if></#if></#list>";
300

301
    /**
tony001's avatar
tony001 committed
302
     * 值规则
303 304
     *
     * @type {*}
KK's avatar
KK committed
305
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
306
     */
KK's avatar
KK committed
307 308
    public rules() :any {
    return {
309
        <#list ctrl.getAllPSDEFormDetails() as formdetail>
310
        <#if formdetail.getDetailType?? && formdetail.getDetailType() == 'FORMITEM' && formdetail.getEditorType() != "HIDDEN" && formdetail.isCompositeItem?? && !formdetail.isCompositeItem()>
311
        ${formdetail.getName()}: [
312 313
            { required: this.detailsModel.${formdetail.getName()}.required, type: '<#assign datatype=srfjavatype(formdetail.getStdDataType())><#if datatype=='BigInteger' || datatype=='Integer' || datatype=='Double' || datatype=='Decimal' || datatype=='Float' || datatype=='BigDecimal'>number<#else>string</#if>', message: '${formdetail.getCaption()} 值不能为空', trigger: 'change' },
            { required: this.detailsModel.${formdetail.getName()}.required, type: '<#assign datatype=srfjavatype(formdetail.getStdDataType())><#if datatype=='BigInteger' || datatype=='Integer' || datatype=='Double' || datatype=='Decimal' || datatype=='Float' || datatype=='BigDecimal'>number<#else>string</#if>', message: '${formdetail.getCaption()} 值不能为空', trigger: 'blur' },
314 315 316 317 318 319 320 321 322 323 324 325 326
             <#if formdetail.getEditorType?? && formdetail.getEditorType()?? &&  formdetail.isAllowEmpty?? && formdetail.isAllowEmpty()??>
            <#if  formdetail.getEditorType() == 'CHECKBOX' &&  !formdetail.isAllowEmpty()>
            { validator: (rule:any, value:any, callback:any) => { 
                if(rule.required && value != 1){
                   return false;
                }else{
                   return true;
                }
              }, message: '${formdetail.getCaption()} 必须填写', trigger: 'change' ,required:true}
            </#if>
            </#if>
          <#if ctrl.getPSDEFormItemVRs()??>
            <#list ctrl.getPSDEFormItemVRs() as fideValueRule>
327
            <#if fideValueRule.getPSDEFormItemName()?lower_case == formdetail.getName()?lower_case >
KK's avatar
KK committed
328
                <#-- 系统值规则 -->
329 330 331 332
              <#if fideValueRule.getPSSysValueRule()??>
                <#assign  valueRule = fideValueRule.getPSSysValueRule()/>
                <#if valueRule.getRuleType?? && valueRule.getRuleType()??>
                  <#if valueRule.getRuleType() == "REG">
333
            { <#if valueRule.getRegExCode?? && valueRule.getRegExCode()??>pattern: /${valueRule.getRegExCode()}/</#if><#if valueRule.getRuleInfo?? &&  valueRule.getRuleInfo()??>, message: '${valueRule.getRuleInfo()}'</#if>, trigger: 'change' },
334 335 336 337 338
                  <#elseif valueRule.getRuleType() == "SCRIPT">
            { <#if valueRule.getScriptCode?? && valueRule.getScriptCode()??>validator: (rule:any, value:any, callback:any) => { ${valueRule.getScriptCode()} }</#if><#if valueRule.getRuleInfo?? &&  valueRule.getRuleInfo()??>, message: '${valueRule.getRuleInfo()}'</#if>, trigger: 'change' },
                  </#if>
                </#if>
              </#if>
KK's avatar
KK committed
339
              <#-- 属性值规则 -->
340
              <#if fideValueRule.getCheckMode?? && fideValueRule.getCheckMode()?? && fideValueRule.getCheckMode() != 2 && fideValueRule.getPSDEFValueRule?? && fideValueRule.getPSDEFValueRule()??>
KK's avatar
KK committed
341
                <#assign  deRule = fideValueRule.getPSDEFValueRule()/>
342 343
            {validator:(rule:any, value:any)=>{return this.verifyDeRules("${fideValueRule.getPSDEFormItemName()?lower_case}").isPast},message: this.verifyDeRules("${fideValueRule.getPSDEFormItemName()?lower_case}").infoMessage, trigger: 'change' },
            {validator:(rule:any, value:any)=>{return this.verifyDeRules("${fideValueRule.getPSDEFormItemName()?lower_case}").isPast},message: this.verifyDeRules("${fideValueRule.getPSDEFormItemName()?lower_case}").infoMessage, trigger: 'blur' },
KK's avatar
KK committed
344
              </#if>
345 346 347 348 349
            </#if>            
            </#list>
          </#if>
        ],
        </#if>
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
<#-- 复合表单项 atart -->
    <#if formdetail.isCompositeItem?? && formdetail.isCompositeItem() && formdetail.getEditorType() != "USERCONTROL">
    ${formdetail.getName()}: [
        <#if formdetail.getPSDEFormItems?? && formdetail.getPSDEFormItems()??>
            <#list formdetail.getPSDEFormItems() as childFormItem>
                <#if ctrl.getPSDEFormItemVRs()??>
                    <#list ctrl.getPSDEFormItemVRs() as fideValueRule>
                        <#if childFormItem.getName()?lower_case == fideValueRule.getPSDEFormItemName()?lower_case>
                        <#-- 系统值规则 -->
              <#if fideValueRule.getPSSysValueRule()??>
                <#assign  valueRule = fideValueRule.getPSSysValueRule()/>
                <#if valueRule.getRuleType?? && valueRule.getRuleType()??>
                  <#if valueRule.getRuleType() == "REG">
            { <#if valueRule.getRegExCode?? && valueRule.getRegExCode()??>pattern: /${valueRule.getRegExCode()}/</#if><#if valueRule.getRuleInfo?? &&  valueRule.getRuleInfo()??>, message: '${valueRule.getRuleInfo()}'</#if>, trigger: 'change' },
                  <#elseif valueRule.getRuleType() == "SCRIPT">
            { <#if valueRule.getScriptCode?? && valueRule.getScriptCode()??>validator: (rule:any, value:any, callback:any) => { ${valueRule.getScriptCode()} }</#if><#if valueRule.getRuleInfo?? &&  valueRule.getRuleInfo()??>, message: '${valueRule.getRuleInfo()}'</#if>, trigger: 'change' },
                  </#if>
                </#if>
              </#if>
              <#-- 属性值规则 -->
              <#if fideValueRule.getCheckMode?? && fideValueRule.getCheckMode()?? && fideValueRule.getCheckMode() != 2 && fideValueRule.getPSDEFValueRule?? && fideValueRule.getPSDEFValueRule()??>
                <#assign  deRule = fideValueRule.getPSDEFValueRule()/>
            {validator:(rule:any, value:any)=>{return this.verifyDeRules("${fideValueRule.getPSDEFormItemName()?lower_case}").isPast},message: this.verifyDeRules("${fideValueRule.getPSDEFormItemName()?lower_case}").infoMessage, trigger: 'change' },
            {validator:(rule:any, value:any)=>{return this.verifyDeRules("${fideValueRule.getPSDEFormItemName()?lower_case}").isPast},message: this.verifyDeRules("${fideValueRule.getPSDEFormItemName()?lower_case}").infoMessage, trigger: 'blur' },
              </#if>
                        </#if>
                    </#list>
                </#if>
            </#list>
        </#if>
        ],
    </#if>
<#-- 复合表单项 end -->
383
        </#list>
KK's avatar
KK committed
384
        }
385 386
    }

KK's avatar
KK committed
387 388 389 390 391 392 393 394 395
    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public deRules:any = {
        <#if ctrl.getPSDEFormItemVRs?? && ctrl.getPSDEFormItemVRs()??>
        <#list ctrl.getPSDEFormItemVRs() as fideValueRule>
396
            <#if fideValueRule.getCheckMode?? && fideValueRule.getCheckMode()?? && fideValueRule.getCheckMode() != 2 && fideValueRule.getPSDEFValueRule?? && fideValueRule.getPSDEFValueRule()??>
KK's avatar
KK committed
397 398
                <#assign  deRule = fideValueRule.getPSDEFValueRule()/>
                <#if fideValueRule.getPSDEFormItemName?? && fideValueRule.getPSDEFormItemName()??>
399
                ${fideValueRule.getPSDEFormItemName()?lower_case}:[
KK's avatar
KK committed
400 401
                <#if deRule.getPSDEFVRGroupCondition?? && deRule.getPSDEFVRGroupCondition()?? && deRule.getPSDEFVRGroupCondition().getPSDEFVRConditions?? &&  deRule.getPSDEFVRGroupCondition().getPSDEFVRConditions()??>
                <#list deRule.getPSDEFVRGroupCondition().getPSDEFVRConditions() as condItem>
KK's avatar
KK committed
402
                    <@getDeRule condItem />
KK's avatar
KK committed
403
                </#list>
404
                </#if>],
KK's avatar
KK committed
405 406 407 408 409 410 411 412 413 414 415 416 417
                </#if>
            </#if>
        </#list>
        </#if>
    };

    /**
     * 校验属性值规则
     *
     * @public
     * @param {{ name: string }} { name }
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
KK's avatar
KK committed
418 419
    public verifyDeRules(name:string,rule:any = this.deRules,op:string = "AND") :{isPast:boolean,infoMessage:string}{
        let falg:any = {infoMessage:""};
KK's avatar
KK committed
420
        if(!rule[name]){
KK's avatar
KK committed
421 422
            return falg;
        }
KK's avatar
KK committed
423 424 425 426
        let opValue = op == 'AND'? true :false;
        let startOp = (val:boolean)=>{
            if(falg.isPast){
                if(opValue){
tony001's avatar
tony001 committed
427
                    falg.isPast = falg.isPast && val;
KK's avatar
KK committed
428
                }else{
tony001's avatar
tony001 committed
429
                    falg.isPast = falg.isPast || val;
KK's avatar
KK committed
430 431 432 433 434
                }
            }else{
                falg.isPast = val;
            }
        }
435 436
        for(let i=0;i<rule[name].length;i++){
            let item:any = rule[name][i];
437
            let dataValue = item.deName?this.data[this.service.getItemNameByDeName(item.deName)]:"";
438
            item.ruleInfo = item.ruleInfo ? item.ruleInfo : this.$t('app.formpage.valuecheckex');
tony001's avatar
tony001 committed
439
            if((dataValue === null || dataValue === undefined || dataValue === "") && (item.type != 'GROUP')){
440 441 442
                startOp(true);
                return falg;
            }
443
            // 常规规则
444
            if(item.type == 'SIMPLE'){
445
                startOp(!this.$verify.checkFieldSimpleRule(dataValue,item.condOP,item.paramValue,item.ruleInfo,item.paramType,this.data,item.isKeyCond));
KK's avatar
KK committed
446
                falg.infoMessage = item.ruleInfo;
447
                if(!falg.isPast) return falg;
KK's avatar
KK committed
448
            }
KK's avatar
KK committed
449 450
            // 数值范围
            if(item.type == 'VALUERANGE2'){
KK's avatar
KK committed
451
                startOp( !this.$verify.checkFieldValueRangeRule(dataValue,item.minValue,item.isIncludeMinValue,item.maxValue,item.isIncludeMaxValue,item.ruleInfo,item.isKeyCond));
KK's avatar
KK committed
452
                falg.infoMessage = item.ruleInfo;
453
                if(!falg.isPast) return falg;
KK's avatar
KK committed
454 455 456
            }
            // 正则式
            if (item.type == "REGEX") {
KK's avatar
KK committed
457
                startOp(!this.$verify.checkFieldRegExRule(dataValue,item.regExCode,item.ruleInfo,item.isKeyCond));
KK's avatar
KK committed
458
                falg.infoMessage = item.ruleInfo;
459
                if(!falg.isPast) return falg;
KK's avatar
KK committed
460
            }
461
            // 长度
462
            if (item.type == "STRINGLENGTH") {
KK's avatar
KK committed
463
                startOp(!this.$verify.checkFieldStringLengthRule(dataValue,item.minValue,item.isIncludeMinValue,item.maxValue,item.isIncludeMaxValue,item.ruleInfo,item.isKeyCond)); 
KK's avatar
KK committed
464
                falg.infoMessage = item.ruleInfo;
465
                if(!falg.isPast) return falg;
KK's avatar
KK committed
466
            }
467
            // 系统值规则
KK's avatar
KK committed
468
            if(item.type == "SYSVALUERULE") {
KK's avatar
KK committed
469
                startOp(!this.$verify.checkFieldSysValueRule(dataValue,item.sysRule.regExCode,item.ruleInfo,item.isKeyCond));
KK's avatar
KK committed
470
                falg.infoMessage = item.ruleInfo;
471
                if(!falg.isPast) return falg;
472 473
            }
            // 分组
KK's avatar
KK committed
474
            if(item.type == 'GROUP'){
tony001's avatar
tony001 committed
475
                falg = this.verifyDeRules('group',item,item.condOP?item.condOP:"AND");
KK's avatar
KK committed
476 477 478
                if(item.isNotMode){
                   falg.isPast = !falg.isPast;
                }
479
                if(!falg.isPast) return falg;
480 481
            }   
        }
482 483
        if(!falg.hasOwnProperty("isPast")){
            falg.isPast = true;
484 485 486
        }
        if(!this.data[name]){
           falg.isPast = true;
487
        }
KK's avatar
KK committed
488 489
        return falg;
    }
KK's avatar
KK committed
490

491 492 493 494
    /**
     * 详情模型集合
     *
     * @type {*}
KK's avatar
KK committed
495
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
496
     */
497
    public detailsModel: any = {
498 499 500 501 502 503 504 505 506 507 508 509 510 511
        <#list ctrl.getAllPSDEFormDetails() as formdetail>
        ${formdetail.name}: ${P.getPartCode(formdetail, 'DETAIL_MODEL').code}, 
        </#list>
        <#if !ctrl.isNoTabHeader()>
        ${ctrl.name}: new FormTabPanelModel({ caption: '${ctrl.name}', detailType: 'TABPANEL', name: '${ctrl.name}', visible: true, isShowCaption: true, form: this, tabPages: [<#list ctrl.getPSDEFormPages() as formmenber><#if formmenber_index gt 0>, </#if>{ name: '${formmenber.name}', index: ${formmenber_index}, visible: <#if formmenber.getPSDEFDGroupLogic('PANELVISIBLE')??>false<#else>true</#if> }</#list>] }),
        </#if>
    };

    <#list ctrl.getPSDEFormItems() as item>
    /**
     * 监控表单属性 ${item.getName()} 值
     *
     * @param {*} newVal
     * @param {*} oldVal
KK's avatar
KK committed
512
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
     */
    @Watch('data.${item.getName()}')
    on${srfclassname('${item.getName()}')}Change(newVal: any, oldVal: any) {
        this.formDataChange({ name: '${item.getName()}', newVal: newVal, oldVal: oldVal });
        <#if item.getEditorType?? && item.getEditorType()?? &&  item.isAllowEmpty?? && item.isAllowEmpty()??>
        <#if  item.getEditorType() == 'CHECKBOX' &&  !item.isAllowEmpty()>
        if(newVal !== null){
            this.formDataChange({ name: '${item.getName()}', newVal: newVal, oldVal: oldVal });
        }else{
            this.data.${item.getName()} = oldVal;
        }
        </#if>
        </#if>
    }

    </#list>

tony001's avatar
tony001 committed
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
    /**
     * 显示更多模式切换操作
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    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);
                }
            });
        }
    }

548 549 550
    /**
     * 重置表单项值
     *
551
     * @public
552
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
KK's avatar
KK committed
553
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
554
     */
555
    public resetFormData({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
        <#list ctrl.getPSDEFormItems() as item>
        <#if item.getResetItemName?? && item.getResetItemName()??>
        if (Object.is(name, '${item.getResetItemName()}')) {
            this.onFormItemValueChange({ name: '${item.getName()}', value: null });
            <#if item.getValueItemName()?? && item.getValueItemName() != ''>
            this.onFormItemValueChange({ name: '${item.getValueItemName()}', value: null });
            </#if>
        }
        </#if>
        </#list>
    }

    /**
      * 置空对象
      *
      * @param {any[]} args
KK's avatar
KK committed
572
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
573
      */
574
    public ResetData(_datas:any){
575 576 577 578 579 580 581 582 583 584 585 586
        if(Object.keys(_datas).length >0){
            Object.keys(_datas).forEach((name: string) => {
                if (this.data.hasOwnProperty(name)) {
                    this.data[name] = null;
                }
            });
        }
    }

    /**
     * 表单逻辑
     *
587
     * @public
588
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
KK's avatar
KK committed
589
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
590
     */
tony001's avatar
tony001 committed
591
    public async formLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }){
592 593 594 595 596 597 598 599 600 601
        <#if P.getPartCode(item,'FORM_LOGIC').code?length gt 0>
        ${P.getPartCode(item,'FORM_LOGIC').code}
        </#if>
        <#if ctrl.getPSDEFormItems()??>
        <#list ctrl.getPSDEFormItems() as formitem>
        <#if formitem.getPSDEFormItemUpdate()??>
        <#assign itemUpdate=formitem.getPSDEFormItemUpdate()/>

        if(Object.is(name, '${formitem.name}')){
            const details: string[] = [<#list itemUpdate.getPSDEFIUpdateDetails() as detail><#if detail_index gt 0>, </#if>'${detail.getPSDEFormDetailName()?lower_case}'</#list>];
tony001's avatar
tony001 committed
602 603 604
            if(await this.checkItem('${formitem.name}')){
                this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c});
            }
605 606 607 608 609 610
        }
        </#if>
        </#list>
        </#if>
    }

tony001's avatar
tony001 committed
611 612 613 614 615 616 617 618 619
    /**
     * 表单项检查逻辑
     *
     * @public
     * @param name 属性名
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public checkItem(name:string):Promise<any> {
        return new Promise((resolve, reject) => {
KK's avatar
KK committed
620
                var validator = new schema({[name]:this.rules()[name]});
tony001's avatar
tony001 committed
621 622 623 624 625 626 627 628 629
                validator.validate({[name]:this.data[name]}).then(()=>{
                    resolve(true);
                })
                .catch(() => {
                    resolve(false);
                });;
        })
    }

630 631 632
    /**
     * 表单值变化
     *
633
     * @public
634 635
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @returns {void}
KK's avatar
KK committed
636
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
637
     */
638
    public formDataChange({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
639 640 641 642 643 644 645 646 647 648 649
        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));
    }

    /**
     * 表单加载完成
     *
650
     * @public
651 652
     * @param {*} [data={}]
     * @param {string} [action]
KK's avatar
KK committed
653
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
654
     */
655
    public onFormLoad(data: any = {},action:string): void {
656
<#if de??>
657
        if(Object.is(action,"save") || Object.is(action,"autoSave") || Object.is(action,"submit"))
658 659 660 661 662 663
        // 更新context的实体主键
        if(data.${appde.getCodeName()?lower_case}){
            Object.assign(this.context,{${appde.getCodeName()?lower_case}:data.${appde.getCodeName()?lower_case}})
        }
</#if>
        this.setFormEnableCond(data);
664
        this.computeButtonState(data);
665 666 667 668 669 670 671 672 673 674 675 676 677 678
        this.fillForm(data,action);
        <#if ctrl.getControlType() == 'FORM'>
        this.oldData = {};
        Object.assign(this.oldData, JSON.parse(JSON.stringify(this.data)));
        this.$store.commit('viewaction/setViewDataChange', { viewtag: this.viewtag, viewdatachange: false });
        </#if>
        this.formLogic({ name: '', newVal: null, oldVal: null });
    }

    /**
     * 值填充
     *
     * @param {*} [_datas={}]
     * @param {string} [action]
KK's avatar
KK committed
679
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
680
     */
681
    public fillForm(_datas: any = {},action:string): void {
682
        this.mixinData = _datas;
683 684 685 686 687 688 689 690 691
        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();
        }
692 693 694
        if(Object.is(action,'load')){
            this.updateDefault();
        }
695 696 697 698 699 700 701 702
        this.$nextTick(function () {
            this.ignorefieldvaluechange = false;
        })
    }

    /**
     * 设置表单项是否启用
     *
703
     * @public
704
     * @param {*} data
KK's avatar
KK committed
705
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
706
     */
707
    public setFormEnableCond(data: any): void {
708 709 710 711 712 713 714 715 716 717 718 719
        Object.values(this.detailsModel).forEach((detail: any) => {
            if (!Object.is(detail.detailType, 'FORMITEM')) {
                return;
            }
            const formItem: FormItemModel = detail;
            formItem.setEnableCond(data.srfuf);
        });
    }

    /**
     * 重置草稿表单状态
     *
720
     * @public
KK's avatar
KK committed
721
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
722
     */
723
    public resetDraftFormStates(): void {
724 725 726 727 728 729 730 731 732
        const form: any = this.$refs.form;
        if (form) {
            form.resetFields();
        }
    }

    /**
     * 重置校验结果
     *
KK's avatar
KK committed
733
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
734
     */
735
    public resetValidates(): void {
736 737 738 739 740 741 742 743 744 745 746 747 748
        Object.values(this.detailsModel).forEach((detail: any) => {
            if (!Object.is(detail.detailType, 'FORMITEM')) {
                return;
            }
            const formItem: FormItemModel = detail;
            formItem.setError('');
        });
    }

    /**
     * 填充校验结果 (后台)
     *
     * @param {any[]} fieldErrors
KK's avatar
KK committed
749
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
750
     */
751
    public fillValidates(fieldErrors: any[]): void {
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
        fieldErrors.forEach((error: any) => {
            const formItem: FormItemModel = this.detailsModel[error.field];
            if (!formItem) {
                return;
            }
            this.$nextTick(() => {
                formItem.setError(error.message);
            });
        });
    }

    /**
     * 表单校验状态
     *
     * @returns {boolean} 
KK's avatar
KK committed
767
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
768
     */
769
    public formValidateStatus(): boolean {
770 771 772 773 774 775 776 777 778 779 780 781
        const form: any = this.$refs.${ctrl.name};
        let validatestate: boolean = true;
        form.validate((valid: boolean) => {
            validatestate = valid ? true : false;
        });
        return validatestate
    }

    /**
     * 获取全部值
     *
     * @returns {*}
KK's avatar
KK committed
782
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
783
     */
784
    public getValues(): any {
785 786 787 788 789 790 791 792
        return this.data;
    }

    /**
     * 表单项值变更
     *
     * @param {{ name: string, value: any }} $event
     * @returns {void}
KK's avatar
KK committed
793
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
794
     */
795
    public onFormItemValueChange($event: { name: string, value: any }): void {
796 797 798 799 800 801 802 803 804
        if (!$event) {
            return;
        }
        if (!$event.name || Object.is($event.name, '') || !this.data.hasOwnProperty($event.name)) {
            return;
        }
        this.data[$event.name] = $event.value;
    }

805 806 807 808 809 810 811 812 813 814 815
    /**
     * 编辑器行为触发
     *
     * @param {*} arg
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public onFormItemActionClick(arg:any){
        if(arg && (arg instanceof Function)) arg();
    }

816 817 818 819 820 821
    /**
     * 设置数据项值
     *
     * @param {string} name
     * @param {*} value
     * @returns {void}
KK's avatar
KK committed
822
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
823
     */
824
    public setDataItemValue(name: string, value: any): void {
825 826 827 828 829 830 831 832 833
        if (!name || Object.is(name, '') || !this.data.hasOwnProperty(name)) {
            return;
        }
        if (Object.is(this.data[name], value)) {
            return;
        }
        this.data[name] = value;
    }

834 835 836 837 838 839 840
    /**
     * 计算表单按钮权限状态
     *
     * @param {*} [data] 传入数据
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public computeButtonState(data:any){
tony001's avatar
tony001 committed
841 842 843 844 845 846 847 848 849 850 851 852
        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;
                }
            })
853 854 855
        }
    }

856 857 858 859 860 861 862 863
    <#list ctrl.getAllPSDEFormDetails() as formdetail>
    <#if formdetail.getDetailType?? && formdetail.getDetailType() == 'BUTTON'>
    <#if formdetail.getActionType?? && formdetail.getActionType()??>
    <#if formdetail.getActionType() == 'UIACTION'>

	/**
	 * 表单 ${formdetail.getCaption()} 事件
	 *
KK's avatar
KK committed
864
	 * @memberof @memberof ${srfclassname('${ctrl.codeName}')}Base
865
	 */
866
    public ${formdetail.getName()}_click($event: any): void {
867 868 869 870 871 872 873 874 875 876 877 878
        <#if formdetail.getPSUIAction?? && formdetail.getPSUIAction()??>
        <#assign uiaction = formdetail.getPSUIAction()>
        this.${ctrl.name}_${formdetail.getName()}_click(null, null, $event);
        </#if>

    }
    </#if>
    <#if formdetail.getActionType() == 'FIUPDATE'>

	/**
	 * 表单 ${formdetail.getCaption()} 事件
	 *
KK's avatar
KK committed
879
	 * @memberof @memberof ${srfclassname('${ctrl.codeName}')}Base
880
	 */
881
    public ${formdetail.getName()}_click($event: any): void {
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
    <#assign itemUpdate=formdetail.getPSDEFormItemUpdate()/>
    <#if formdetail.getParamPickupPSAppView()??>
        <#assign dataview = formdetail.getParamPickupPSAppView()>
        <#--  BEGIN:是否应用实体视图  -->
        <#if dataview.isPSDEView()>
        const deResParameters: any[] = [
            <#--  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:存在父关系路径  -->
        ];
        <#else>
        const deResParameters: any[] = [];
        </#if>
        <#--  END:是否应用实体视图  -->
        <#--  BEGIN:是否应用实体视图  -->
        <#if dataview.isPSDEView()>
        <#assign appDataEntity = dataview.getPSAppDataEntity()/>
        const parameters: any[] = [
            { pathName: '${srfpluralize(appDataEntity.codeName)?lower_case}', parameterName: '${appDataEntity.getCodeName()?lower_case}' },
        ];
        <#else>
        const parameters: any[] = [];
        </#if>
        <#--  END:是否应用实体视图  -->
        const view: any = {
            viewname: '${srffilepath2(dataview.getCodeName())}',
            title: this.<@getViewLanguageTitle dataview />,
            height: ${dataview.getHeight()?c},
            width: ${dataview.getWidth()?c},
            <#if formdetail.getParamViewParamJO()??>
            paramjo: ${formdetail.getParamViewParamJO()},
            </#if>
        }
        const data: any = {};
        if(view.paramjo) {
            Object.keys(view.paramjo).every((name: string) => {
                if (!name) {
                    return true;
                }
                let value: string = view.paramjo[name];
                if (value && value.startsWith('%') && value.endsWith('%')) {
                    const key: string = value.substring(1, value.length - 1);
                    if (!this.data.hasOwnProperty(key)) {
tony001's avatar
tony001 committed
930
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: `<#noparse>${(this.$t('app.formpage.desc1') as string)}${r'${key}'},${(this.$t('app.formpage.desc2') as string)}</#noparse>` });
931 932 933 934 935 936 937 938 939 940 941 942 943 944
                        return false;
                    }
                    value = this.data[key];
                }
                Object.assign(data, { [name]: value });
                return true;
            });
        }
        let container: Subject<any> = this.$appmodal.openModal(view, this.context,data);
        container.subscribe((result: any) => {
            if (result && Object.is(result.ret, 'OK') && result.datas && Array.isArray(result.datas)) {
                const arg: any = { ...JSON.parse(JSON.stringify(this.data)) } ;
                Object.assign(arg, { srfactionparam: result.datas });
                const details: string[] = [<#list itemUpdate.getPSDEFIUpdateDetails() as detail><#if detail_index gt 0>, </#if>'${detail.getPSDEFormDetailName()?lower_case}'</#list>];
945
                this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', arg, details, ${itemUpdate.isShowBusyIndicator()?c});
946 947 948 949
            }
        });
    <#else>
        const details: string[] = [<#list itemUpdate.getPSDEFIUpdateDetails() as detail><#if detail_index gt 0>, </#if>'${detail.getPSDEFormDetailName()?lower_case}'</#list>];
950
        this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c});
951 952 953 954 955 956 957 958 959 960 961 962
    </#if>
    }
    </#if>
    </#if>
    </#if>
    </#list>


    /**
     * 分组界面行为事件
     *
     * @param {*} $event
KK's avatar
KK committed
963
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
964
     */
965
    public groupUIActionClick($event: any): void {
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
        if (!$event) {
            return;
        }
        const item:any = $event.item;
        <#list ctrl.getAllPSDEFormDetails() as formdetail>
        <#if formdetail.getDetailType?? && formdetail.getDetailType() == 'GROUPPANEL'>
        <#if formdetail.getPSUIActionGroup()??>
        <#list formdetail.getPSUIActionGroup().getPSUIActionGroupDetails() as uadetails>
        if (Object.is(item.name, '${formdetail.getName()}_${uadetails.getName()}')) {
            this.${ctrl.name}_${formdetail.getName()}_${uadetails.getName()}_click(null, null, $event.event);
        }
        </#list>
        </#if>
        </#if>
        </#list>
    }

    /**
     * Vue声明周期(处理组件的输入属性)
     *
KK's avatar
KK committed
986
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
987
     */
988
    public created(): void {
989 990 991 992 993 994
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
KK's avatar
KK committed
995
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
996
     */    
997
    public afterCreated(){
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
        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)) {
1010
                    this.loadDraft(data);
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
                }
                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);
                }
1030
                if (Object.is('panelaction', action)) {
1031
                    this.panelAction(data.action,data.emitAction,data.data);
1032
                }
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
            });
        }
        this.dataChang
            .pipe(
                debounceTime(300),
                distinctUntilChanged()
            ).subscribe((data: any) => {
                if (this.autosave) {
                    this.autoSave();
                }
                <#if ctrl.getControlType() == 'FORM'>
                const state = !Object.is(JSON.stringify(this.oldData), JSON.stringify(this.data)) ? true : false;
                this.$store.commit('viewaction/setViewDataChange', { viewtag: this.viewtag, viewdatachange: state });
                </#if>
                <#if ctrl.getControlType() == 'SEARCHFORM' && ctrl.isEnableAutoSearch()>
                this.$emit('load', this.data);
                </#if>
            });
    }

    /**
     * vue 生命周期
     *
KK's avatar
KK committed
1056
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1057
     */
1058
    public destroyed() {
1059 1060 1061 1062 1063 1064
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
KK's avatar
KK committed
1065
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1066
     */
1067
    public afterDestroy() {
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        if (this.dataChangEvent) {
            this.dataChangEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>      
    }

    /**
     *打印
KK's avatar
KK committed
1081
     *@memberof @memberof ${srfclassname('${ctrl.codeName}')}Base
1082
     */
1083
    public print(){
1084
        let _this:any = this;
1085
        _this.$print({id:'${ctrl.getPSAppDataEntity().getCodeName()?lower_case}_${ctrl.getCodeName()?lower_case}',popTitle:'${ctrl.getLogicName()}'});
1086 1087 1088 1089 1090
    }

    /**
     * 部件刷新
     *
1091
     * @param {any} args
KK's avatar
KK committed
1092
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1093
     */
1094
    public refresh(args?: any): void {
1095
        let arg: any = {};
1096
        Object.assign(arg,args?args[0]:{});
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
        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}
KK's avatar
KK committed
1114
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1115
     */
1116
    public autoLoad(arg: any = {}): void {
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
        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);
    }

    /**
     * 加载
     *
1133
     * @public
1134
     * @param {*} [opt={}]
KK's avatar
KK committed
1135
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1136
     */
1137
    public load(opt: any = {}): void {
1138
        if(!this.loadAction){
tony001's avatar
tony001 committed
1139
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.loadaction') as string) });
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
            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) => {
1155
            if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1156
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1157 1158 1159
                return;
            }
            if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1160
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1161 1162 1163 1164 1165 1166 1167 1168 1169
                return;
            }
        });
    }

    /**
     * 加载草稿
     *
     * @param {*} [opt={}]
KK's avatar
KK committed
1170
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1171
     */
1172
    public loadDraft(opt: any = {}): void {
1173
        if(!this.loaddraftAction){
tony001's avatar
tony001 committed
1174
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.loaddraftaction') as string) });
1175 1176 1177 1178 1179 1180 1181
            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) {
1182
                if (response.data) {
tony001's avatar
tony001 committed
1183
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1184 1185 1186 1187 1188 1189 1190
                }
                return;
            }

            const data = response.data;
            this.resetDraftFormStates();
            this.onFormLoad(data,'loadDraft');
1191 1192 1193 1194 1195 1196 1197
            <#list ctrl.getPSDEFormItems() as formitem>
            <#if formitem.getPSAppDEField?? && formitem.getPSAppDEField()??>
            <#if !formitem.isHidden() && formitem.getPSAppDEField().isKeyField()>
            this.data.${formitem.getName()} = null;
            </#if>
            </#if>
            </#list>
1198
            data.${appde.getCodeName()?lower_case} = null;
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
            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) => {
1214
            if (response && response.status  && response.data) {
tony001's avatar
tony001 committed
1215
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1216 1217 1218
                return;
            }
            if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1219
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1220 1221 1222 1223 1224 1225 1226 1227 1228
                return;
            }
        });
    }

    /**
     * 自动保存
     *
     * @param {*} [opt={}]
KK's avatar
KK committed
1229
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1230
     */
1231
    public autoSave(opt: any = {}): void {
1232 1233 1234 1235 1236 1237
        if (!this.formValidateStatus()) {
            return;
        }
        const arg: any = { ...opt };
        const data = this.getValues();
        Object.assign(arg, data);
1238
        Object.assign(arg,{srfmajortext:data[this.majorMessageField]});
1239 1240 1241
        const action: any = Object.is(data.srfuf, '1') ? this.updateAction : this.createAction;
        if(!action){
            let actionName:any = Object.is(data.srfuf, '1')?"updateAction":"createAction";
tony001's avatar
tony001 committed
1242
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.actionname') as string) });
1243 1244 1245 1246 1247 1248
            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) {
1249
                if (response.data) {
tony001's avatar
tony001 committed
1250
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1251 1252 1253 1254 1255 1256 1257 1258
                }
                return;
            }

            const data = response.data;
            this.onFormLoad(data,'autoSave');
            this.$emit('save', data);
            <#if ctrl.getControlType() == 'FORM'>
tony001's avatar
tony001 committed
1259
            AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
1260 1261 1262 1263 1264
            </#if>
            this.$nextTick(() => {
                this.formState.next({ type: 'save', data: data });
            });
        }).catch((response: any) => {
1265
            if (response && response.status && response.data) {
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
                    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),
1287
                                    desc: response.data.message?response.data.message:(this.$t('app.commonWords.sysException') as string),
1288 1289
                                })
                            }
1290 1291 1292 1293 1294
                        }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) + '!',
                            });
1295
                        } else {
1296
                            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) });
1297 1298
                        }
                    } else {
1299
                        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) });
1300 1301 1302 1303
                    }
                    return;
                } else {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
tony001's avatar
tony001 committed
1304
                }
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
        });
    }

    /**
     * 保存
     *
     * @param {*} [opt={}]
     * @param {boolean} [showResultInfo] 
     * @param {boolean} [ifStateNext] formState是否下发通知
     * @returns {Promise<any>}
KK's avatar
KK committed
1315
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1316
     */
1317
    public async save(opt: any = {}, showResultInfo?: boolean, ifStateNext: boolean = true): Promise<any> {
1318 1319 1320
        return new Promise((resolve: any, reject: any) => {
            showResultInfo = showResultInfo === undefined ? true : false;
            if (!this.formValidateStatus()) {
1321 1322 1323 1324 1325 1326 1327 1328 1329
                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) });
                }
1330 1331 1332 1333 1334
                return;
            }
            const arg: any = { ...opt };
            const data = this.getValues();
            Object.assign(arg, this.context);
1335
            Object.assign(arg, data);
1336
            Object.assign(arg,{srfmajortext:data[this.majorMessageField]});
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
            if (ifStateNext) {
                <#assign drcounter = 0>
                <#list ctrl.getAllPSDEFormDetails() as formdetail>
                <#if formdetail.getDetailType() == "DRUIPART">
                    <#assign drcounter = drcounter + 1>
                </#if>
                </#list>
                this.drcounter = ${drcounter};
                if(this.drcounter !== 0){
                    this.drsaveopt = opt;
                    this.formState.next({ type: 'beforesave', data: arg });//先通知关系界面保存
                    this.saveState = resolve;
                    return;
                }
            }
1352 1353 1354
            if(this.viewparams && this.viewparams.copymode){
                data.srfuf = '0';
            }
1355 1356 1357
            const action: any = Object.is(data.srfuf, '1') ? this.updateAction : this.createAction;
            if(!action){
                let actionName:any = Object.is(data.srfuf, '1')?"updateAction":"createAction";
tony001's avatar
tony001 committed
1358
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.actionname') as string) });
1359 1360 1361 1362 1363 1364
                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) {
1365
                    if (response.data) {
tony001's avatar
tony001 committed
1366
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1367 1368 1369
                    }
                    return;
                }
1370
                this.viewparams.copymode = false;
1371 1372 1373 1374
                const data = response.data;
                this.onFormLoad(data,'save');
                this.$emit('save', data);
                <#if ctrl.getControlType() == 'FORM'>
tony001's avatar
tony001 committed
1375
                AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
1376 1377 1378 1379 1380 1381
                </#if>
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: data });
                });
                <#if ctrl.getFormFuncMode()?lower_case != 'wizardform'>
                if (showResultInfo) {
tony001's avatar
tony001 committed
1382
                    this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;'+ (this.$t('app.formpage.savesuccess') as string) });
1383 1384 1385 1386
                }
                </#if>
                resolve(response);
            }).catch((response: any) => {
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
                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 {
tony001's avatar
tony001 committed
1416
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
tony001's avatar
tony001 committed
1417 1418
                        reject(response);
                    }
1419
                    return;
1420
                } else {
tony001's avatar
tony001 committed
1421
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1422
                    reject(response);
1423
                }    
1424 1425 1426 1427 1428 1429 1430 1431
                reject(response);
            });
        })
    }

    /**
    * 删除
    *
1432
    * @public
1433
    * @param {*} [opt={}]
KK's avatar
KK committed
1434
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
1435
    */
1436
    public remove(opt:Array<any> = [],showResultInfo?: boolean): Promise<any> {
1437 1438
        return new Promise((resolve: any, reject: any) => {
            if(!this.removeAction){
tony001's avatar
tony001 committed
1439
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.removeaction') as string) });
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
                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;
tony001's avatar
tony001 committed
1451
                    this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;' + (this.$t('app.formpage.deletesuccess') as string) });
tony001's avatar
tony001 committed
1452 1453 1454
                    <#if ctrl.getControlType() == 'FORM'>
                    AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
                    </#if>
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
                    resolve(response);
                }
            }).catch((error: any) => {
                const { data: _data } = error;
                this.$Notice.error({ title: _data.title, desc: _data.message });
                reject(error);
            });
        });
    }
<#if ctrl.getControlType() == 'FORM'>

    /**
     * 工作流启动
     *
     * @param {*} [data={}]
1470
     * @param {*} [localdata={}]
1471
     * @returns {Promise<any>}
KK's avatar
KK committed
1472
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1473
     */
1474
    public async wfstart(data: any,localdata?:any): Promise<any> {
1475 1476
        return new Promise((resolve: any, reject: any) => {
            const _this: any = this;
1477 1478 1479
            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);
1480
            post.then((response:any) =>{
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
                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);
                <#if ctrl.getControlType() == 'FORM'>
                AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
                </#if>
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: arg });
                });
1494
                // 准备工作流数据,填充未存库数据
1495 1496
                Object.assign(arg,copyData);
                // 准备提交参数
1497
                if(this.viewparams){
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
                    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});
1508
                }
1509
                const result: Promise<any> = this.service.wfstart(_this.WFStartAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,localdata);
1510 1511
                result.then((response: any) => {
                    if (!response || response.status !== 200) {
1512
                        if(response.data){
tony001's avatar
tony001 committed
1513
                            this.$Notice.error({ title: '', desc: (this.$t('app.formpage.workflow.starterror') as string) + ', ' + response.data.message });
1514
                        }
1515 1516
                        return;
                    }
tony001's avatar
tony001 committed
1517
                    this.$Notice.info({ title: '', desc: (this.$t('app.formpage.workflow.startsuccess') as string) });
1518 1519
                    resolve(response);
            }).catch((response: any) => {
1520
                if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1521
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1522 1523 1524 1525
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1526
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1527 1528 1529 1530 1531 1532
                    reject(response);
                    return;
                }
                reject(response);
            });
            }).catch((response: any) => {
1533
                    if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1534
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1535 1536 1537 1538
                        reject(response);
                        return;
                    }
                    if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1539
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551
                        reject(response);
                        return;
                    }
                    reject(response);
            })
        });
    }

    /**
     * 工作流提交
     *
     * @param {*} [data={}]
1552
     * @param {*} [localdata={}]
1553
     * @returns {Promise<any>}
KK's avatar
KK committed
1554
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1555
     */
1556
    public async wfsubmit(data: any,localdata?:any): Promise<any> {
1557 1558 1559
        return new Promise((resolve: any, reject: any) => {
        const _this: any = this;
        const arg: any = data[0];
1560
        const copyData:any = Util.deepCopy(arg);
1561 1562 1563 1564
        Object.assign(arg,{viewparams:this.viewparams});
        if (!arg.${ctrl.getPSAppDataEntity().getCodeName()?lower_case} || Object.is(arg.${ctrl.getPSAppDataEntity().getCodeName()?lower_case}, '')) {
            return;
        }
1565
        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);
1566
        post.then((response:any) =>{
1567 1568 1569 1570
                const responseData:any = response.data;
                let tempResponseData:any = Util.deepCopy(response);
                this.service.handleResponse('save', tempResponseData);
                const arg:any = tempResponseData.data;
1571 1572 1573
                // 保存完成UI处理
                this.onFormLoad(arg,'save');
                this.$emit('save', arg);
tony001's avatar
tony001 committed
1574 1575 1576
                <#if ctrl.getControlType() == 'FORM'>
                AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
                </#if>
1577 1578 1579
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: arg });
                });
1580
                // 准备工作流数据,填充未存库数据
1581
                Object.assign(arg,copyData);
1582
                // 准备提交参数
1583
                if(this.viewparams){
1584
                    Object.assign(responseData,this.viewparams);
1585
                }
1586
                Object.assign(arg,{viewparams:responseData});
1587 1588 1589 1590
                // 强制补充srfwfmemo
                if(this.srfwfmemo){
                    Object.assign(arg,{srfwfmemo:this.srfwfmemo});
                }
1591
                const result: Promise<any> = this.service.wfsubmit(_this.WFSubmitAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,localdata);
1592 1593
                result.then((response: any) => {
                    if (!response || response.status !== 200) {
1594
                        if(response.data){
tony001's avatar
tony001 committed
1595
                            this.$Notice.error({ title: '', desc: (this.$t('app.formpage.workflow.submiterror') as string) + ', ' + response.data.message });
1596
                        }
1597 1598
                        return;
                    }
1599 1600
                    this.onFormLoad(arg,'submit');
                    this.$store.dispatch('viewaction/datasaved', { viewtag: this.viewtag });
tony001's avatar
tony001 committed
1601
                    this.$Notice.info({ title: '', desc: (this.$t('app.formpage.workflow.submitsuccess') as string) });
1602 1603
                    resolve(response);
            }).catch((response: any) => {
1604
                if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1605
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1606 1607 1608 1609
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1610
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1611 1612 1613 1614 1615 1616
                    reject(response);
                    return;
                }
                reject(response);
            });
            }).catch((response: any) => {
1617
                    if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1618
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1619 1620 1621 1622
                        reject(response);
                        return;
                    }
                    if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1623
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1624 1625 1626 1627 1628 1629 1630 1631 1632
                        reject(response);
                        return;
                    }
                    reject(response);
            })
        })
    }
</#if>

1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
    /**
     * 面板行为
     *
     * @param {string} [action] 调用的实体行为
     * @param {string} [emitAction] 抛出行为
     * @param {*} [data={}] 传入数据
     * @param {boolean} [showloading] 是否显示加载状态
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    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;
            }
        });
    }

1677 1678 1679 1680 1681 1682 1683 1684
    /**
     * 表单项更新
     *
     * @param {string} mode 界面行为名称
     * @param {*} [data={}] 请求数据
     * @param {string[]} updateDetails 更新项
     * @param {boolean} [showloading] 是否显示加载状态
     * @returns {void}
KK's avatar
KK committed
1685
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1686
     */
1687
    public updateFormItems(mode: string, data: any = {}, updateDetails: string[], showloading?: boolean): void {
1688 1689 1690 1691 1692 1693 1694 1695
        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) {
tony001's avatar
tony001 committed
1696
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.formpage.updateerror') as string) });
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710
                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));
tony001's avatar
tony001 committed
1711 1712 1713
            <#if ctrl.getControlType() == 'FORM'>
            AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
            </#if>
1714 1715 1716 1717
            this.$nextTick(() => {
                this.formState.next({ type: 'updateformitem', ufimode: arg.srfufimode, data: _data });
            });
        }).catch((response: any) => {
1718
            if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1719
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1720 1721 1722
                return;
            }
            if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1723
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1724 1725 1726 1727 1728 1729 1730 1731 1732
                return;
            }
        });
    }

    /**
     * 回车事件
     *
     * @param {*} $event
KK's avatar
KK committed
1733
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1734
     */
1735
    public onEnter($event: any): void {
1736 1737 1738 1739 1740 1741 1742 1743 1744
        <#if ctrl.getControlType() == 'SEARCHFORM' && !ctrl.isEnableAutoSearch()>
        this.$emit('load', this.data);
        </#if>
    }

    /**
     * 保存并退出
     *
     * @param {any[]} args
KK's avatar
KK committed
1745
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1746
     */
1747
    public saveAndExit(data:any[]):Promise<any>{
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
        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
KK's avatar
KK committed
1770
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1771
     */
1772
    public saveAndNew(data:any[]):Promise<any>{
1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792
        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
KK's avatar
KK committed
1793
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1794
     */
1795
    public removeAndExit(data:any[]):Promise<any>{
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816
        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
KK's avatar
KK committed
1817
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
1818
    */
1819
    public drdatasaved($event:any){
1820 1821
        let _this = this;
        this.drcounter--;
1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832
        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);
                    }
1833
                }
1834 1835
            });
        }
1836 1837 1838 1839
    }

    /**
     * 新建默认值
KK's avatar
KK committed
1840
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1841 1842
     */
    public createDefault(){                    
1843
<#list ctrl.getAllPSDEFormDetails() as formdetail><#t>
1844
  <#if (formdetail.getCreateDV?? || formdetail.getCreateDVT??) && (formdetail.getCreateDV()?? || formdetail.getCreateDVT()??) && (formdetail.getCreateDV() !="" || formdetail.getCreateDVT() != "")><#t>
1845
        if (this.data.hasOwnProperty('${formdetail.getCodeName()?lower_case}')) {
1846
    <#if !(formdetail.getCreateDVT() == '')><#t>
1847 1848
      <#-- 网页请求 -->
      <#if formdetail.getCreateDVT() == 'CONTEXT'>
1849
            this.data['${formdetail.getCodeName()?lower_case}'] = this.viewparams['${formdetail.getCreateDV()}'];
1850 1851
      <#-- 用户全局对象 -->
      <#elseif formdetail.getCreateDVT() == 'SESSION'>
1852
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['${formdetail.getCreateDV()}'];
1853 1854
      <#-- 当前应用数据 -->
      <#elseif formdetail.getCreateDVT() == 'APPDATA'>
1855
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['${formdetail.getCreateDV()}'];
1856 1857
      <#-- 当前操作用户(名称) -->
      <#elseif formdetail.getCreateDVT() == 'OPERATORNAME'>
1858
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['srfusername'];
1859 1860
      <#-- 当前操作用户(编号) -->
      <#elseif formdetail.getCreateDVT() == 'OPERATOR'>
1861
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['srfuserid'];
1862 1863
      <#-- 当前时间 -->
      <#elseif formdetail.getCreateDVT() == 'CURTIME'>
1864
          this.data['${formdetail.getCodeName()?lower_case}'] = this.$util.dateFormat(new Date());
1865 1866
      <#-- 数据对象属性 -->
      <#elseif formdetail.getCreateDVT() == 'PARAM'>
1867
          this.data['${formdetail.getCodeName()?lower_case}'] = this.service.getRemoteCopyData().${formdetail.getCreateDV()}?this.service.getRemoteCopyData().${formdetail.getCreateDV()}:null;
1868 1869
      </#if>
    <#else>
1870
      <#-- 默认值 -->
1871 1872
            <#assign datatype=srfjavatype(formdetail.getStdDataType())>
            this.data['${formdetail.getCodeName()?lower_case}'] = <#if datatype=='BigInteger' || datatype=='Integer' || datatype=='Double' || datatype=='Decimal' || datatype=='Float' || datatype=='BigDecimal'>${formdetail.getCreateDV()}<#else>'${formdetail.getCreateDV()}'</#if>;
1873
    </#if>
1874
        }
1875 1876
  </#if>
</#list>
1877 1878
    }

1879 1880
    /**
     * 更新默认值
KK's avatar
KK committed
1881
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1882 1883 1884
     */
    public updateDefault(){                    
        <#list ctrl.getAllPSDEFormDetails() as formdetail><#t>
1885
        <#if (formdetail.getUpdateDV?? || formdetail.getUpdateDVT??) && (formdetail.getUpdateDV()?? || formdetail.getUpdateDVT()??) && (formdetail.getUpdateDV() != "" || formdetail.getUpdateDVT() != "")><#t>
1886
        if (this.data.hasOwnProperty('${formdetail.getCodeName()?lower_case}') && !this.data.${formdetail.getCodeName()?lower_case}) {
1887
        <#if !(formdetail.getUpdateDVT() == '')><#t>
1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902
        <#-- 网页请求 -->
        <#if formdetail.getUpdateDVT() == 'CONTEXT'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.viewparams['${formdetail.getUpdateDV()}'];
        <#-- 用户全局对象 -->
        <#elseif formdetail.getUpdateDVT() == 'SESSION'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['${formdetail.getUpdateDV()}'];
         <#-- 当前应用数据 -->
        <#elseif formdetail.getUpdateDVT() == 'APPDATA'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['${formdetail.getUpdateDV()}'];
        <#-- 当前操作用户(名称) -->
        <#elseif formdetail.getUpdateDVT() == 'OPERATORNAME'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['srfusername'];
        <#-- 当前操作用户(编号) -->
        <#elseif formdetail.getUpdateDVT() == 'OPERATOR'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['srfuserid'];
1903 1904 1905
        <#-- 当前时间 -->
        <#elseif formdetail.getUpdateDVT() == 'CURTIME'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.$util.dateFormat(new Date());
1906 1907
        <#-- 数据对象属性 -->
         <#elseif formdetail.getUpdateDVT() == 'PARAM'>
1908
            this.data['${formdetail.getCodeName()?lower_case}'] = this.service.getRemoteCopyData().${formdetail.getUpdateDV()}?this.service.getRemoteCopyData().${formdetail.getUpdateDV()}:null;
1909
        </#if>
1910 1911
        <#else>
        <#-- 默认值 -->
1912 1913
            <#assign datatype=srfjavatype(formdetail.getStdDataType())>
            this.data['${formdetail.getCodeName()?lower_case}'] = <#if datatype=='BigInteger' || datatype=='Integer' || datatype=='Double' || datatype=='Decimal' || datatype=='Float' || datatype=='BigDecimal'>${formdetail.getUpdateDV()}<#else>'${formdetail.getUpdateDV()}'</#if>;
1914 1915 1916 1917 1918 1919
        </#if>
        }
        </#if>
        </#list>
    }

1920 1921 1922 1923 1924 1925 1926
<#--  搜索表单:Begin  -->
<#if ctrl.getControlType() == 'SEARCHFORM'>
    <#if ctrl.getSearchButtonStyle() == 'DEFAULT'>

    /**
     * 搜索
     *
KK's avatar
KK committed
1927
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1928
     */
1929
    public onSearch() {
1930 1931 1932 1933 1934 1935
        this.$emit('load', this.data);
    }

    /**
     * 重置
     *
KK's avatar
KK committed
1936
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1937
     */
1938
    public onReset() {
1939 1940 1941 1942 1943 1944 1945 1946
        this.loadDraft();
    }
    </#if>
    <#if ctrl.getSearchButtonStyle() == 'SEARCHONLY'>

    /**
     * 搜索
     *
KK's avatar
KK committed
1947
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1948
     */
1949
    public onSearch() {
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962
        this.$emit('load', this.data);
    }

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

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