CONTROL-BASE.vue.ftl 80.5 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 41 42 43 44 45 46 47 48 49 50
    /**
     * 主键表单项名称
     *
     * @protected
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public formKeyItemName: string = '<#list ctrl.getPSDEFormItems() as formitem><#if formitem.getPSAppDEField?? && formitem.getPSAppDEField()??><#if !formitem.isHidden() && formitem.getPSAppDEField().isKeyField()>${formitem.getName()}</#if></#if></#list>';

    /**
     * 是否自动加载
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Prop({default:false}) public isautoload?:boolean;

tony001's avatar
tony001 committed
51 52 53 54 55 56
    /**
     * 界面UI服务对象
     *
     * @type {${srfclassname('${appde.getCodeName()}')}UIService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
RedPig97's avatar
RedPig97 committed
57
    public appUIService:${srfclassname('${appde.getCodeName()}')}UIService = new ${srfclassname('${appde.getCodeName()}')}UIService();
tony001's avatar
tony001 committed
58

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

    /**
     * 获取单项树
     *
     * @returns {*}
KK's avatar
KK committed
80
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
81 82 83 84 85 86 87 88 89
     */
    public getData(): any {
        return this.data;
    }

    /**
     * 是否默认保存
     *
     * @type {boolean}
KK's avatar
KK committed
90
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
91
     */
92
    @Prop({ default: false }) public autosave?: boolean;
93 94 95 96 97

    /**
     * 显示处理提示
     *
     * @type {boolean}
KK's avatar
KK committed
98
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
99
     */
100
    @Prop({ default: true }) public showBusyIndicator?: boolean;
101 102 103 104 105

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

    /**
     * 部件行为--create
     *
     * @type {string}
KK's avatar
KK committed
162
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
163
     */
164
    @Prop() public searchAction!: string;
165 166 167 168 169

    /**
     * 视图标识
     *
     * @type {string}
KK's avatar
KK committed
170
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
171
     */
172
    @Prop() public viewtag!: string;
173 174 175 176 177

    /**
     * 表单状态
     *
     * @type {Subject<any>}
KK's avatar
KK committed
178
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
179
     */
180
    public formState: Subject<any> = new Subject();
181 182 183 184 185

    /**
     * 忽略表单项值变化
     *
     * @type {boolean}
KK's avatar
KK committed
186
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
187
     */
188
    public ignorefieldvaluechange: boolean = false;
189 190 191 192

    /**
     * 数据变化
     *
193
     * @public
194
     * @type {Subject<any>}
KK's avatar
KK committed
195
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
196
     */
197
    public dataChang: Subject<any> = new Subject();
198 199 200 201

    /**
     * 视图状态事件
     *
202
     * @public
203
     * @type {(Subscription | undefined)}
KK's avatar
KK committed
204
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
205
     */
206
    public dataChangEvent: Subscription | undefined;
207 208 209 210

    /**
     * 原始数据
     *
211
     * @public
212
     * @type {*}
KK's avatar
KK committed
213
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
214
     */
215
    public oldData: any = {};
216

217 218 219 220 221 222 223 224
    /**
     * 混入表单数据对象
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public mixinData:any = {};

225 226 227 228 229
    /**
     * 表单项校验错误提示信息
     * 
     *  @memberof  ${srfclassname('${ctrl.codeName}')}Base
     */
230 231 232 233 234 235 236 237 238 239
    public errorMessages: Array<any> = []; 

    /**
     * 应用状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public appStateEvent: Subscription | undefined;
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262

    /**
     * 设置表单项错误提示信息
     * 
     * @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});
        }
    }

263 264 265 266
    /**
     * 表单数据对象
     *
     * @type {*}
KK's avatar
KK committed
267
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
268
     */
269
    public data: any = {
270
        <#list ctrl.getAllPSDEFormDetails() as item>
271
        <#if item.getDetailType?? && item.getDetailType()?? && (item.getDetailType() == "FORMITEM" || item.getDetailType() == "FORMPART")>
272
        ${item.getName()}: null,
273
        </#if>
274 275 276 277 278 279 280 281
        </#list>
        ${ctrl.getPSAppDataEntity().getCodeName()?lower_case}:null,
    };

    /**
      * 当前执行的行为逻辑
      *
      * @type {string}
KK's avatar
KK committed
282
      * @memberof ${srfclassname('${ctrl.codeName}')}Base
283
      */
284
    public currentAction: string = "";
285 286 287 288 289

    /**
      * 关系界面计数器
      *
      * @type {number}
KK's avatar
KK committed
290
      * @memberof ${srfclassname('${ctrl.codeName}')}Base
291
      */
292
    public drcounter: number = 0;
293 294 295 296 297

    /**
      * 需要等待关系界面保存时,第一次调用save参数的备份
      *
      * @type {number}
KK's avatar
KK committed
298
      * @memberof ${srfclassname('${ctrl.codeName}')}Base
299
      */
300
    public drsaveopt: any = {};
301 302 303 304 305

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

310 311 312 313 314 315 316 317
    /**
     * 主信息属性映射表单项名称
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    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>";

318
    /**
tony001's avatar
tony001 committed
319
     * 值规则
320 321
     *
     * @type {*}
KK's avatar
KK committed
322
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
323
     */
KK's avatar
KK committed
324 325
    public rules() :any {
    return {
326
        <#list ctrl.getAllPSDEFormDetails() as formdetail>
327
        <#if formdetail.getDetailType?? && formdetail.getDetailType() == 'FORMITEM' && formdetail.getEditorType() != "HIDDEN" && formdetail.isCompositeItem?? && !formdetail.isCompositeItem()>
328
        ${formdetail.getName()}: [
329 330
            { 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' },
331 332 333 334 335 336 337 338
             <#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;
                }
339
              }, message: '${formdetail.getCaption()} 必须填写', trigger: 'change' ,required:true},
340 341 342 343
            </#if>
            </#if>
          <#if ctrl.getPSDEFormItemVRs()??>
            <#list ctrl.getPSDEFormItemVRs() as fideValueRule>
344
            <#if fideValueRule.getPSDEFormItemName()?lower_case == formdetail.getName()?lower_case >
KK's avatar
KK committed
345
                <#-- 系统值规则 -->
346 347 348 349
              <#if fideValueRule.getPSSysValueRule()??>
                <#assign  valueRule = fideValueRule.getPSSysValueRule()/>
                <#if valueRule.getRuleType?? && valueRule.getRuleType()??>
                  <#if valueRule.getRuleType() == "REG">
350
            { <#if valueRule.getRegExCode?? && valueRule.getRegExCode()??>pattern: /${valueRule.getRegExCode()}/</#if><#if valueRule.getRuleInfo?? &&  valueRule.getRuleInfo()??>, message: '${valueRule.getRuleInfo()}'</#if>, trigger: 'change' },
351
                  <#elseif valueRule.getRuleType() == "SCRIPT">
352
            { <#if valueRule.getScriptCode?? && valueRule.getScriptCode()??>validator: (rule:any, value:any, callback:any) => { if (value === '' || value === null || value === undefined) { rule.message = '${formdetail.getCaption()} 值不能为空';  return false; }  ${valueRule.getScriptCode()} }</#if><#if valueRule.getRuleInfo?? &&  valueRule.getRuleInfo()??>, message: '${valueRule.getRuleInfo()}'</#if>, trigger: 'change' },
353 354 355
                  </#if>
                </#if>
              </#if>
KK's avatar
KK committed
356
              <#-- 属性值规则 -->
357
              <#if fideValueRule.getCheckMode?? && fideValueRule.getCheckMode()?? && fideValueRule.getCheckMode() != 2 && fideValueRule.getPSDEFValueRule?? && fideValueRule.getPSDEFValueRule()??>
KK's avatar
KK committed
358
                <#assign  deRule = fideValueRule.getPSDEFValueRule()/>
359 360
            {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
361
              </#if>
362 363 364 365 366
            </#if>            
            </#list>
          </#if>
        ],
        </#if>
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
<#-- 复合表单项 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 -->
400
        </#list>
KK's avatar
KK committed
401
        }
402 403
    }

KK's avatar
KK committed
404 405 406 407 408 409
    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
410 411 412 413 414 415 416 417 418 419 420 421 422 423
    public deRules(){
        return {
            <#if ctrl.getPSDEFormItemVRs?? && ctrl.getPSDEFormItemVRs()??>
            <#list ctrl.getPSDEFormItemVRs() as fideValueRule>
                <#if fideValueRule.getCheckMode?? && fideValueRule.getCheckMode()?? && fideValueRule.getCheckMode() != 2 && fideValueRule.getPSDEFValueRule?? && fideValueRule.getPSDEFValueRule()??>
                    <#assign  deRule = fideValueRule.getPSDEFValueRule()/>
                    <#if fideValueRule.getPSDEFormItemName?? && fideValueRule.getPSDEFormItemName()??>
                    ${fideValueRule.getPSDEFormItemName()?lower_case}:[
                    <#if deRule.getPSDEFVRGroupCondition?? && deRule.getPSDEFVRGroupCondition()?? && deRule.getPSDEFVRGroupCondition().getPSDEFVRConditions?? &&  deRule.getPSDEFVRGroupCondition().getPSDEFVRConditions()??>
                    <#list deRule.getPSDEFVRGroupCondition().getPSDEFVRConditions() as condItem>
                        <@getDeRule condItem deRule appde/>
                    </#list>
                    </#if>],
                    </#if>
KK's avatar
KK committed
424
                </#if>
425
            </#list>
KK's avatar
KK committed
426
            </#if>
427 428
        }
    }
KK's avatar
KK committed
429 430 431 432 433 434 435 436

    /**
     * 校验属性值规则
     *
     * @public
     * @param {{ name: string }} { name }
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
437
    public verifyDeRules(name:string,rule:any = this.deRules(),op:string = "AND") :{isPast:boolean,infoMessage:string}{
KK's avatar
KK committed
438
        let falg:any = {infoMessage:""};
KK's avatar
KK committed
439
        if(!rule[name]){
KK's avatar
KK committed
440 441
            return falg;
        }
KK's avatar
KK committed
442 443 444 445
        let opValue = op == 'AND'? true :false;
        let startOp = (val:boolean)=>{
            if(falg.isPast){
                if(opValue){
446
                    falg.isPast = falg.isPast && val;
KK's avatar
KK committed
447
                }else{
448
                    falg.isPast = falg.isPast || val;
KK's avatar
KK committed
449 450 451 452 453
                }
            }else{
                falg.isPast = val;
            }
        }
454 455
        for(let i=0;i<rule[name].length;i++){
            let item:any = rule[name][i];
456
            let dataValue = item.deName?this.data[this.service.getItemNameByDeName(item.deName)]:"";
457 458 459 460
            item.ruleInfo = item.ruleInfo ? item.ruleInfo : this.$t('app.formpage.valuecheckex');
            if((dataValue === null || dataValue === undefined || dataValue === "") && (item.type != 'GROUP')){
                startOp(true);
                return falg;
461
            }
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
           try {
                // 常规规则
                if(item.type == 'SIMPLE'){
                    startOp(!this.$verify.checkFieldSimpleRule(dataValue,item.condOP,item.paramValue,item.ruleInfo,item.paramType,this.data,item.isKeyCond));
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
                // 数值范围
                if(item.type == 'VALUERANGE2'){
                    startOp( !this.$verify.checkFieldValueRangeRule(dataValue,item.minValue,item.isIncludeMinValue,item.maxValue,item.isIncludeMaxValue,item.ruleInfo,item.isKeyCond));
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
                // 正则式
                if (item.type == "REGEX") {
                    startOp(!this.$verify.checkFieldRegExRule(dataValue,item.regExCode,item.ruleInfo,item.isKeyCond));
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
                // 长度
                if (item.type == "STRINGLENGTH") {
                    startOp(!this.$verify.checkFieldStringLengthRule(dataValue,item.minValue,item.isIncludeMinValue,item.maxValue,item.isIncludeMaxValue,item.ruleInfo,item.isKeyCond)); 
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
                // 系统值规则
                if(item.type == "SYSVALUERULE") {
                    startOp(!this.$verify.checkFieldSysValueRule(dataValue,item.sysRule.regExCode,item.ruleInfo,item.isKeyCond));
                    falg.infoMessage = item.ruleInfo;
                    if(!falg.isPast) return falg;
                }
            } catch(error) {
KK's avatar
KK committed
494
                falg.infoMessage = item.ruleInfo;
495
                startOp(false);
496
                if(!falg.isPast) return falg;
497 498
            }
            // 分组
KK's avatar
KK committed
499
            if(item.type == 'GROUP'){
500
                falg = this.verifyDeRules('group',item,item.condOP?item.condOP:"AND");
KK's avatar
KK committed
501 502 503
                if(item.isNotMode){
                   falg.isPast = !falg.isPast;
                }
504
                if(!falg.isPast) return falg;
505 506
            }   
        }
507 508
        if(!falg.hasOwnProperty("isPast")){
            falg.isPast = true;
509
        }
510
        if(!this.data[name] && this.data[name] != 0){
511
           falg.isPast = true;
512
        }
KK's avatar
KK committed
513 514
        return falg;
    }
KK's avatar
KK committed
515

516 517 518 519
    /**
     * 详情模型集合
     *
     * @type {*}
KK's avatar
KK committed
520
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
521
     */
522
    public detailsModel: any = {
523 524 525 526 527 528 529 530 531 532 533 534 535 536
        <#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
537
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
     */
    @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
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
    /**
     * 显示更多模式切换操作
     *
     * @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);
                }
            });
        }
    }

573 574 575
    /**
     * 重置表单项值
     *
576
     * @public
577
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
KK's avatar
KK committed
578
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
579
     */
580
    public resetFormData({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
        <#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
597
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
598
      */
599
    public ResetData(_datas:any){
600 601 602 603 604 605 606 607 608 609 610 611
        if(Object.keys(_datas).length >0){
            Object.keys(_datas).forEach((name: string) => {
                if (this.data.hasOwnProperty(name)) {
                    this.data[name] = null;
                }
            });
        }
    }

    /**
     * 表单逻辑
     *
612
     * @public
613
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
KK's avatar
KK committed
614
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
615
     */
tony001's avatar
tony001 committed
616
    public async formLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }){
617 618 619 620 621 622 623 624 625
        <#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
626 627 628
            if(await this.checkItem('${formitem.name}')){
                this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c});
            }
629 630 631 632 633 634
        }
        </#if>
        </#list>
        </#if>
    }

tony001's avatar
tony001 committed
635 636 637 638 639 640 641 642 643
    /**
     * 表单项检查逻辑
     *
     * @public
     * @param name 属性名
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public checkItem(name:string):Promise<any> {
        return new Promise((resolve, reject) => {
KK's avatar
KK committed
644
                var validator = new schema({[name]:this.rules()[name]});
tony001's avatar
tony001 committed
645 646 647 648 649 650 651 652 653
                validator.validate({[name]:this.data[name]}).then(()=>{
                    resolve(true);
                })
                .catch(() => {
                    resolve(false);
                });;
        })
    }

654 655 656
    /**
     * 表单值变化
     *
657
     * @public
658 659
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @returns {void}
KK's avatar
KK committed
660
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
661
     */
662
    public formDataChange({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
663 664 665 666 667 668 669 670 671 672 673
        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));
    }

    /**
     * 表单加载完成
     *
674
     * @public
675 676
     * @param {*} [data={}]
     * @param {string} [action]
KK's avatar
KK committed
677
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
678
     */
679
    public onFormLoad(data: any = {},action:string): void {
680
<#if de??>
681
        if(Object.is(action,"save") || Object.is(action,"autoSave") || Object.is(action,"submit"))
682 683 684 685 686 687
        // 更新context的实体主键
        if(data.${appde.getCodeName()?lower_case}){
            Object.assign(this.context,{${appde.getCodeName()?lower_case}:data.${appde.getCodeName()?lower_case}})
        }
</#if>
        this.setFormEnableCond(data);
688
        this.computeButtonState(data);
689 690 691 692 693 694 695 696 697 698 699 700 701 702
        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
703
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
704
     */
705
    public fillForm(_datas: any = {},action:string): void {
706
        this.mixinData = _datas;
707 708 709 710 711 712 713 714 715
        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();
        }
716 717 718
        if(Object.is(action,'load')){
            this.updateDefault();
        }
719
        this.$nextTick(function () {
720
            this.ignorefieldvaluechange = false;
721
        })
722 723 724 725 726
    }

    /**
     * 设置表单项是否启用
     *
727
     * @public
728
     * @param {*} data
KK's avatar
KK committed
729
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
730
     */
731
    public setFormEnableCond(data: any): void {
732 733 734 735 736 737 738 739 740 741 742 743
        Object.values(this.detailsModel).forEach((detail: any) => {
            if (!Object.is(detail.detailType, 'FORMITEM')) {
                return;
            }
            const formItem: FormItemModel = detail;
            formItem.setEnableCond(data.srfuf);
        });
    }

    /**
     * 重置草稿表单状态
     *
744
     * @public
KK's avatar
KK committed
745
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
746
     */
747
    public resetDraftFormStates(): void {
748 749 750 751 752 753 754 755 756
        const form: any = this.$refs.form;
        if (form) {
            form.resetFields();
        }
    }

    /**
     * 重置校验结果
     *
KK's avatar
KK committed
757
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
758
     */
759
    public resetValidates(): void {
760 761 762 763 764 765 766 767 768 769 770 771 772
        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
773
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
774
     */
775
    public fillValidates(fieldErrors: any[]): void {
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
        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
791
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
792
     */
793
    public formValidateStatus(): boolean {
794 795 796 797 798 799 800 801 802 803 804 805
        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
806
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
807
     */
808
    public getValues(): any {
809 810 811 812 813 814 815 816
        return this.data;
    }

    /**
     * 表单项值变更
     *
     * @param {{ name: string, value: any }} $event
     * @returns {void}
KK's avatar
KK committed
817
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
818
     */
819
    public onFormItemValueChange($event: { name: string, value: any }): void {
820 821 822 823 824 825 826 827 828
        if (!$event) {
            return;
        }
        if (!$event.name || Object.is($event.name, '') || !this.data.hasOwnProperty($event.name)) {
            return;
        }
        this.data[$event.name] = $event.value;
    }

829 830 831 832 833 834 835 836 837 838 839
    /**
     * 编辑器行为触发
     *
     * @param {*} arg
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public onFormItemActionClick(arg:any){
        if(arg && (arg instanceof Function)) arg();
    }

840 841 842 843 844 845
    /**
     * 设置数据项值
     *
     * @param {string} name
     * @param {*} value
     * @returns {void}
KK's avatar
KK committed
846
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
847
     */
848
    public setDataItemValue(name: string, value: any): void {
849 850 851 852 853 854 855 856 857
        if (!name || Object.is(name, '') || !this.data.hasOwnProperty(name)) {
            return;
        }
        if (Object.is(this.data[name], value)) {
            return;
        }
        this.data[name] = value;
    }

858 859 860 861 862 863 864
    /**
     * 计算表单按钮权限状态
     *
     * @param {*} [data] 传入数据
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public computeButtonState(data:any){
tony001's avatar
tony001 committed
865 866 867 868 869 870 871 872 873 874 875 876
        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;
                }
            })
877 878 879
        }
    }

880 881 882 883 884 885 886 887
    <#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
888
	 * @memberof @memberof ${srfclassname('${ctrl.codeName}')}Base
889
	 */
890
    public ${formdetail.getName()}_click($event: any): void {
891 892 893 894 895 896 897 898 899 900 901 902
        <#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
903
	 * @memberof @memberof ${srfclassname('${ctrl.codeName}')}Base
904
	 */
905
    public ${formdetail.getName()}_click($event: any): void {
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
    <#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
954
                        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>` });
955 956 957 958 959 960 961 962 963 964 965 966 967 968
                        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>];
969
                this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', arg, details, ${itemUpdate.isShowBusyIndicator()?c});
970 971 972 973
            }
        });
    <#else>
        const details: string[] = [<#list itemUpdate.getPSDEFIUpdateDetails() as detail><#if detail_index gt 0>, </#if>'${detail.getPSDEFormDetailName()?lower_case}'</#list>];
974
        this.updateFormItems('${itemUpdate.getPSAppDEMethod().getCodeName()}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c});
975 976 977 978 979 980 981 982 983 984 985 986
    </#if>
    }
    </#if>
    </#if>
    </#if>
    </#list>


    /**
     * 分组界面行为事件
     *
     * @param {*} $event
KK's avatar
KK committed
987
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
988
     */
989
    public groupUIActionClick($event: any): void {
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
        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
1010
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1011
     */
1012
    public created(): void {
1013 1014 1015 1016 1017 1018
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
KK's avatar
KK committed
1019
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
1020
     */    
1021
    public afterCreated(){
1022
        if(this.isautoload){
1023
            this.autoLoad({srfkey:this.context.${ctrl.getPSAppDataEntity().getCodeName()?lower_case}});
1024
        }
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
        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)) {
1037
                    this.loadDraft(data);
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
                }
                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);
                }
1057
                if (Object.is('panelaction', action)) {
1058
                    this.panelAction(data.action,data.emitAction,data.data);
1059
                }
1060 1061
            });
        }
1062
        this.dataChangEvent = this.dataChang
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
            .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
1083
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1084
     */
1085
    public destroyed() {
1086 1087 1088 1089 1090 1091
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
KK's avatar
KK committed
1092
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1093
     */
1094
    public afterDestroy() {
1095 1096 1097 1098 1099 1100
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        if (this.dataChangEvent) {
            this.dataChangEvent.unsubscribe();
        }
1101 1102 1103
        if(this.appStateEvent){
            this.appStateEvent.unsubscribe();
        }
1104 1105 1106 1107 1108 1109 1110
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>      
    }

    /**
     *打印
KK's avatar
KK committed
1111
     *@memberof @memberof ${srfclassname('${ctrl.codeName}')}Base
1112
     */
1113
    public print(){
1114
        let _this:any = this;
1115
        _this.$print({id:'${ctrl.getPSAppDataEntity().getCodeName()?lower_case}_${ctrl.getCodeName()?lower_case}',popTitle:'${ctrl.getLogicName()}'});
1116 1117 1118 1119 1120
    }

    /**
     * 部件刷新
     *
1121
     * @param {any} args
KK's avatar
KK committed
1122
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1123
     */
1124
    public refresh(args?: any): void {
1125
        let arg: any = {};
1126
        Object.assign(arg,args?args[0]:{});
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
        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
1144
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1145
     */
1146
    public autoLoad(arg: any = {}): void {
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
        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);
    }

    /**
     * 加载
     *
1163
     * @public
1164
     * @param {*} [opt={}]
KK's avatar
KK committed
1165
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1166
     */
1167
    public load(opt: any = {}): void {
1168
        if(!this.loadAction){
tony001's avatar
tony001 committed
1169
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.loadaction') as string) });
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184
            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) => {
1185
            if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1186
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1187 1188 1189
                return;
            }
            if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1190
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1191 1192 1193 1194 1195 1196 1197 1198 1199
                return;
            }
        });
    }

    /**
     * 加载草稿
     *
     * @param {*} [opt={}]
KK's avatar
KK committed
1200
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1201
     */
1202
    public loadDraft(opt: any = {}): void {
1203
        if(!this.loaddraftAction){
tony001's avatar
tony001 committed
1204
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.loaddraftaction') as string) });
1205 1206 1207 1208 1209 1210 1211
            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) {
1212
                if (response.data) {
tony001's avatar
tony001 committed
1213
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1214 1215 1216 1217 1218 1219 1220
                }
                return;
            }

            const data = response.data;
            this.resetDraftFormStates();
            this.onFormLoad(data,'loadDraft');
1221 1222 1223 1224 1225 1226 1227
            <#list ctrl.getPSDEFormItems() as formitem>
            <#if formitem.getPSAppDEField?? && formitem.getPSAppDEField()??>
            <#if !formitem.isHidden() && formitem.getPSAppDEField().isKeyField()>
            this.data.${formitem.getName()} = null;
            </#if>
            </#if>
            </#list>
1228
            data.${appde.getCodeName()?lower_case} = null;
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
            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) => {
1244
            if (response && response.status  && response.data) {
tony001's avatar
tony001 committed
1245
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1246 1247 1248
                return;
            }
            if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1249
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1250 1251 1252 1253 1254 1255 1256 1257 1258
                return;
            }
        });
    }

    /**
     * 自动保存
     *
     * @param {*} [opt={}]
KK's avatar
KK committed
1259
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1260
     */
1261
    public autoSave(opt: any = {}): void {
1262 1263 1264 1265 1266 1267
        if (!this.formValidateStatus()) {
            return;
        }
        const arg: any = { ...opt };
        const data = this.getValues();
        Object.assign(arg, data);
1268
        Object.assign(arg,{srfmajortext:data[this.majorMessageField]});
1269 1270 1271
        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
1272
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.actionname') as string) });
1273 1274 1275 1276 1277 1278
            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) {
1279
                if (response.data) {
tony001's avatar
tony001 committed
1280
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1281 1282 1283 1284 1285 1286 1287 1288
                }
                return;
            }

            const data = response.data;
            this.onFormLoad(data,'autoSave');
            this.$emit('save', data);
            <#if ctrl.getControlType() == 'FORM'>
tony001's avatar
tony001 committed
1289
            AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
1290 1291 1292 1293 1294
            </#if>
            this.$nextTick(() => {
                this.formState.next({ type: 'save', data: data });
            });
        }).catch((response: any) => {
1295
            if (response && response.status && response.data) {
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
                    if (response.data.errorKey) {
                        if(Object.is(response.data.errorKey, "versionCheck")) {
                            this.$Modal.confirm({
                                title: (this.$t('app.formpage.saveerror') as string),
                                content: (this.$t('app.formpage.savecontent') as string),
                                onOk: () => {
                                    this.refresh([]);
                                },
                                onCancel: () => { }
                            });
                        } else if(Object.is(response.data.errorKey, 'DupCheck')) {
                            let errorProp: string = response.data.message.match(/\[[a-zA-Z]*\]/)[0];
                            let name: string = this.service.getNameByProp(errorProp.substr(1, errorProp.length-2));
                            if(name) {
                                this.$Notice.error({
                                    title: (this.$t('app.commonWords.createFailed') as string),
                                    desc: this.detailsModel[name].caption + " : " + arg[name] + (this.$t('app.commonWords.isExist') as string) + '!',
                                });
                            } else {
                                this.$Notice.error({
                                    title: (this.$t('app.commonWords.createFailed') as string),
                                    desc: response.data.message?response.data.message:(this.$t('app.commonWords.sysException') as string),
                                })
                            }
                        }else if(Object.is(response.data.errorKey, 'DuplicateKeyException')){
                            this.$Notice.error({
                                title: (this.$t('app.commonWords.createFailed') as string),
                                desc: this.detailsModel[this.formKeyItemName].caption + " : " + arg[this.formKeyItemName] + (this.$t('app.commonWords.isExist') as string) + '!',
                            });
                        } else {
                            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message?response.data.message:(this.$t('app.commonWords.sysException') as string) });
                        }
                    } else {
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message?response.data.message:(this.$t('app.commonWords.sysException') as string) });
                    }
                    return;
                } else {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
tony001's avatar
tony001 committed
1334
                }
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
        });
    }

    /**
     * 保存
     *
     * @param {*} [opt={}]
     * @param {boolean} [showResultInfo] 
     * @param {boolean} [ifStateNext] formState是否下发通知
     * @returns {Promise<any>}
KK's avatar
KK committed
1345
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1346
     */
1347
    public async save(opt: any = {}, showResultInfo?: boolean, ifStateNext: boolean = true): Promise<any> {
1348 1349 1350
        return new Promise((resolve: any, reject: any) => {
            showResultInfo = showResultInfo === undefined ? true : false;
            if (!this.formValidateStatus()) {
1351 1352 1353 1354 1355 1356 1357 1358 1359
                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) });
                }
1360 1361 1362 1363 1364
                return;
            }
            const arg: any = { ...opt };
            const data = this.getValues();
            Object.assign(arg, this.context);
1365
            Object.assign(arg, data);
1366
            Object.assign(arg,{srfmajortext:data[this.majorMessageField]});
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
            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;
                }
            }
1382 1383 1384
            if(this.viewparams && this.viewparams.copymode){
                data.srfuf = '0';
            }
1385 1386 1387
            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
1388
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.actionname') as string) });
1389 1390 1391 1392 1393 1394
                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) {
1395
                    if (response.data) {
tony001's avatar
tony001 committed
1396
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1397 1398 1399
                    }
                    return;
                }
1400
                this.viewparams.copymode = false;
1401 1402 1403 1404
                const data = response.data;
                this.onFormLoad(data,'save');
                this.$emit('save', data);
                <#if ctrl.getControlType() == 'FORM'>
tony001's avatar
tony001 committed
1405
                AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
1406 1407 1408 1409 1410 1411
                </#if>
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: data });
                });
                <#if ctrl.getFormFuncMode()?lower_case != 'wizardform'>
                if (showResultInfo) {
tony001's avatar
tony001 committed
1412
                    this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;'+ (this.$t('app.formpage.savesuccess') as string) });
1413 1414 1415 1416
                }
                </#if>
                resolve(response);
            }).catch((response: any) => {
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
                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
1446
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
tony001's avatar
tony001 committed
1447 1448
                        reject(response);
                    }
1449
                    return;
1450
                } else {
tony001's avatar
tony001 committed
1451
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1452
                    reject(response);
1453
                }    
1454 1455 1456 1457 1458 1459 1460 1461
                reject(response);
            });
        })
    }

    /**
    * 删除
    *
1462
    * @public
1463
    * @param {*} [opt={}]
KK's avatar
KK committed
1464
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
1465
    */
1466
    public remove(opt:Array<any> = [],showResultInfo?: boolean): Promise<any> {
1467 1468
        return new Promise((resolve: any, reject: any) => {
            if(!this.removeAction){
tony001's avatar
tony001 committed
1469
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.formpage.notconfig.removeaction') as string) });
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
                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
1481
                    this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;' + (this.$t('app.formpage.deletesuccess') as string) });
tony001's avatar
tony001 committed
1482 1483 1484
                    <#if ctrl.getControlType() == 'FORM'>
                    AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
                    </#if>
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
                    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={}]
1500
     * @param {*} [localdata={}]
1501
     * @returns {Promise<any>}
KK's avatar
KK committed
1502
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1503
     */
1504
    public async wfstart(data: any,localdata?:any): Promise<any> {
1505 1506
        return new Promise((resolve: any, reject: any) => {
            const _this: any = this;
1507 1508 1509
            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);
1510
            post.then((response:any) =>{
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523
                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 });
                });
1524
                // 准备工作流数据,填充未存库数据
1525 1526
                Object.assign(arg,copyData);
                // 准备提交参数
1527
                if(this.viewparams){
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
                    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});
1538
                }
1539
                const result: Promise<any> = this.service.wfstart(_this.WFStartAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,localdata);
1540 1541
                result.then((response: any) => {
                    if (!response || response.status !== 200) {
1542
                        if(response.data){
tony001's avatar
tony001 committed
1543
                            this.$Notice.error({ title: '', desc: (this.$t('app.formpage.workflow.starterror') as string) + ', ' + response.data.message });
1544
                        }
1545 1546
                        return;
                    }
tony001's avatar
tony001 committed
1547
                    this.$Notice.info({ title: '', desc: (this.$t('app.formpage.workflow.startsuccess') as string) });
1548 1549
                    resolve(response);
            }).catch((response: any) => {
1550
                if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1551
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1552 1553 1554 1555
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1556
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1557 1558 1559 1560 1561 1562
                    reject(response);
                    return;
                }
                reject(response);
            });
            }).catch((response: any) => {
1563
                    if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1564
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1565 1566 1567 1568
                        reject(response);
                        return;
                    }
                    if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1569
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
                        reject(response);
                        return;
                    }
                    reject(response);
            })
        });
    }

    /**
     * 工作流提交
     *
     * @param {*} [data={}]
1582
     * @param {*} [localdata={}]
1583
     * @returns {Promise<any>}
KK's avatar
KK committed
1584
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1585
     */
1586
    public async wfsubmit(data: any,localdata?:any): Promise<any> {
1587 1588 1589
        return new Promise((resolve: any, reject: any) => {
        const _this: any = this;
        const arg: any = data[0];
1590
        const copyData:any = Util.deepCopy(arg);
1591 1592 1593 1594
        Object.assign(arg,{viewparams:this.viewparams});
        if (!arg.${ctrl.getPSAppDataEntity().getCodeName()?lower_case} || Object.is(arg.${ctrl.getPSAppDataEntity().getCodeName()?lower_case}, '')) {
            return;
        }
1595
        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);
1596
        post.then((response:any) =>{
1597 1598 1599 1600
                const responseData:any = response.data;
                let tempResponseData:any = Util.deepCopy(response);
                this.service.handleResponse('save', tempResponseData);
                const arg:any = tempResponseData.data;
1601 1602 1603
                // 保存完成UI处理
                this.onFormLoad(arg,'save');
                this.$emit('save', arg);
tony001's avatar
tony001 committed
1604 1605 1606
                <#if ctrl.getControlType() == 'FORM'>
                AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
                </#if>
1607 1608 1609
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: arg });
                });
1610
                // 准备工作流数据,填充未存库数据
1611
                Object.assign(arg,copyData);
1612
                // 准备提交参数
1613
                if(this.viewparams){
1614
                    Object.assign(responseData,this.viewparams);
1615
                }
1616
                Object.assign(arg,{viewparams:responseData});
1617 1618 1619 1620
                // 强制补充srfwfmemo
                if(this.srfwfmemo){
                    Object.assign(arg,{srfwfmemo:this.srfwfmemo});
                }
1621
                const result: Promise<any> = this.service.wfsubmit(_this.WFSubmitAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,localdata);
1622 1623
                result.then((response: any) => {
                    if (!response || response.status !== 200) {
1624
                        if(response.data){
tony001's avatar
tony001 committed
1625
                            this.$Notice.error({ title: '', desc: (this.$t('app.formpage.workflow.submiterror') as string) + ', ' + response.data.message });
1626
                        }
1627 1628
                        return;
                    }
1629 1630
                    this.onFormLoad(arg,'submit');
                    this.$store.dispatch('viewaction/datasaved', { viewtag: this.viewtag });
tony001's avatar
tony001 committed
1631
                    this.$Notice.info({ title: '', desc: (this.$t('app.formpage.workflow.submitsuccess') as string) });
1632 1633
                    resolve(response);
            }).catch((response: any) => {
1634
                if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1635
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1636 1637 1638 1639
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1640
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1641 1642 1643 1644 1645 1646
                    reject(response);
                    return;
                }
                reject(response);
            });
            }).catch((response: any) => {
1647
                    if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1648
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1649 1650 1651 1652
                        reject(response);
                        return;
                    }
                    if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1653
                        this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1654 1655 1656 1657 1658 1659 1660 1661 1662
                        reject(response);
                        return;
                    }
                    reject(response);
            })
        })
    }
</#if>

1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706
    /**
     * 面板行为
     *
     * @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;
            }
        });
    }

1707 1708 1709 1710 1711 1712 1713 1714
    /**
     * 表单项更新
     *
     * @param {string} mode 界面行为名称
     * @param {*} [data={}] 请求数据
     * @param {string[]} updateDetails 更新项
     * @param {boolean} [showloading] 是否显示加载状态
     * @returns {void}
KK's avatar
KK committed
1715
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1716
     */
1717
    public updateFormItems(mode: string, data: any = {}, updateDetails: string[], showloading?: boolean): void {
1718 1719 1720 1721 1722 1723 1724 1725
        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
1726
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.formpage.updateerror') as string) });
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
                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
1741 1742 1743
            <#if ctrl.getControlType() == 'FORM'>
            AppCenterService.notifyMessage({name:"${ctrl.getPSAppDataEntity().getCodeName()}",action:'appRefresh',data:data});
            </#if>
1744 1745 1746 1747
            this.$nextTick(() => {
                this.formState.next({ type: 'updateformitem', ufimode: arg.srfufimode, data: _data });
            });
        }).catch((response: any) => {
1748
            if (response && response.status && response.data) {
tony001's avatar
tony001 committed
1749
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
1750 1751 1752
                return;
            }
            if (!response || !response.status || !response.data) {
tony001's avatar
tony001 committed
1753
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
1754 1755 1756 1757 1758 1759 1760 1761 1762
                return;
            }
        });
    }

    /**
     * 回车事件
     *
     * @param {*} $event
KK's avatar
KK committed
1763
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1764
     */
1765
    public onEnter($event: any): void {
1766 1767 1768 1769 1770 1771 1772 1773 1774
        <#if ctrl.getControlType() == 'SEARCHFORM' && !ctrl.isEnableAutoSearch()>
        this.$emit('load', this.data);
        </#if>
    }

    /**
     * 保存并退出
     *
     * @param {any[]} args
KK's avatar
KK committed
1775
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1776
     */
1777
    public saveAndExit(data:any[]):Promise<any>{
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799
        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
1800
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1801
     */
1802
    public saveAndNew(data:any[]):Promise<any>{
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822
        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
1823
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1824
     */
1825
    public removeAndExit(data:any[]):Promise<any>{
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
        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
1847
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
1848
    */
1849
    public drdatasaved($event:any){
1850 1851
        let _this = this;
        this.drcounter--;
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
        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);
                    }
1863
                }
1864 1865
            });
        }
1866 1867 1868 1869
    }

    /**
     * 新建默认值
KK's avatar
KK committed
1870
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1871 1872
     */
    public createDefault(){                    
1873
<#list ctrl.getAllPSDEFormDetails() as formdetail><#t>
1874
  <#if (formdetail.getCreateDV?? || formdetail.getCreateDVT??) && (formdetail.getCreateDV()?? || formdetail.getCreateDVT()??) && (formdetail.getCreateDV() !="" || formdetail.getCreateDVT() != "")><#t>
1875
        if (this.data.hasOwnProperty('${formdetail.getCodeName()?lower_case}')) {
1876
    <#if !(formdetail.getCreateDVT() == '')><#t>
1877 1878
      <#-- 网页请求 -->
      <#if formdetail.getCreateDVT() == 'CONTEXT'>
1879
            this.data['${formdetail.getCodeName()?lower_case}'] = this.viewparams['${formdetail.getCreateDV()}'];
1880 1881
      <#-- 用户全局对象 -->
      <#elseif formdetail.getCreateDVT() == 'SESSION'>
1882
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['${formdetail.getCreateDV()}'];
1883 1884
      <#-- 当前应用数据 -->
      <#elseif formdetail.getCreateDVT() == 'APPDATA'>
1885
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['${formdetail.getCreateDV()}'];
1886 1887
      <#-- 当前操作用户(名称) -->
      <#elseif formdetail.getCreateDVT() == 'OPERATORNAME'>
1888
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['srfusername'];
1889 1890
      <#-- 当前操作用户(编号) -->
      <#elseif formdetail.getCreateDVT() == 'OPERATOR'>
1891
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['srfuserid'];
1892 1893
      <#-- 当前时间 -->
      <#elseif formdetail.getCreateDVT() == 'CURTIME'>
1894
          this.data['${formdetail.getCodeName()?lower_case}'] = this.$util.dateFormat(new Date());
1895 1896
      <#-- 数据对象属性 -->
      <#elseif formdetail.getCreateDVT() == 'PARAM'>
1897
          this.data['${formdetail.getCodeName()?lower_case}'] = this.service.getRemoteCopyData().${formdetail.getCreateDV()}?this.service.getRemoteCopyData().${formdetail.getCreateDV()}:null;
1898 1899
      </#if>
    <#else>
1900
      <#-- 默认值 -->
1901 1902
            <#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>;
1903
    </#if>
1904
        }
1905 1906
  </#if>
</#list>
1907 1908
    }

1909 1910
    /**
     * 更新默认值
KK's avatar
KK committed
1911
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1912 1913 1914
     */
    public updateDefault(){                    
        <#list ctrl.getAllPSDEFormDetails() as formdetail><#t>
1915
        <#if (formdetail.getUpdateDV?? || formdetail.getUpdateDVT??) && (formdetail.getUpdateDV()?? || formdetail.getUpdateDVT()??) && (formdetail.getUpdateDV() != "" || formdetail.getUpdateDVT() != "")><#t>
1916
        if (this.data.hasOwnProperty('${formdetail.getCodeName()?lower_case}') && !this.data.${formdetail.getCodeName()?lower_case}) {
1917
        <#if !(formdetail.getUpdateDVT() == '')><#t>
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932
        <#-- 网页请求 -->
        <#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'];
1933 1934 1935
        <#-- 当前时间 -->
        <#elseif formdetail.getUpdateDVT() == 'CURTIME'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.$util.dateFormat(new Date());
1936 1937
        <#-- 数据对象属性 -->
         <#elseif formdetail.getUpdateDVT() == 'PARAM'>
1938
            this.data['${formdetail.getCodeName()?lower_case}'] = this.service.getRemoteCopyData().${formdetail.getUpdateDV()}?this.service.getRemoteCopyData().${formdetail.getUpdateDV()}:null;
1939
        </#if>
1940 1941
        <#else>
        <#-- 默认值 -->
1942 1943
            <#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>;
1944 1945 1946 1947 1948 1949
        </#if>
        }
        </#if>
        </#list>
    }

1950 1951 1952 1953 1954 1955 1956
<#--  搜索表单:Begin  -->
<#if ctrl.getControlType() == 'SEARCHFORM'>
    <#if ctrl.getSearchButtonStyle() == 'DEFAULT'>

    /**
     * 搜索
     *
KK's avatar
KK committed
1957
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1958
     */
1959
    public onSearch() {
1960 1961 1962 1963 1964 1965
        this.$emit('load', this.data);
    }

    /**
     * 重置
     *
KK's avatar
KK committed
1966
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1967
     */
1968
    public onReset() {
1969 1970 1971 1972 1973 1974 1975 1976
        this.loadDraft();
    }
    </#if>
    <#if ctrl.getSearchButtonStyle() == 'SEARCHONLY'>

    /**
     * 搜索
     *
KK's avatar
KK committed
1977
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
1978
     */
1979
    public onSearch() {
1980 1981 1982 1983 1984
        this.$emit('load', this.data);
    }

    </#if>
</#if>
1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995

    /**
     * 面板数据变化处理事件
     * @param {any} item 当前列数据
     * @param {any} $event 面板事件数据
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public onPanelDataChange(item:any,$event:any) {
        Object.assign(item, $event, {rowDataState:'update'});
    }
1996 1997 1998 1999 2000 2001 2002 2003
    
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

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