CONTROL-BASE.vue.ftl 54.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
<#ibizinclude>
../../@MACRO/LANG_FUN.ftl
</#ibizinclude>
<template>
    ${P.getPartCode(item,'FORM').code}
</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';
</#assign>
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>

    
    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getDatas(): any[] {
        return [this.data];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getData(): any {
        return this.data;
    }

    /**
     * 是否默认保存
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
43
    @Prop({ default: false }) public autosave?: boolean;
44 45 46 47 48 49 50

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
51
    @Prop({ default: true }) public showBusyIndicator?: boolean;
52 53 54 55 56 57 58

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

    /**
     * 部件行为--create
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
115
    @Prop() public searchAction!: string;
116 117 118 119 120 121 122

    /**
     * 视图标识
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
123
    @Prop() public viewtag!: string;
124 125 126 127 128 129 130

    /**
     * 表单状态
     *
     * @type {Subject<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
131
    public formState: Subject<any> = new Subject();
132 133 134 135 136 137 138

    /**
     * 忽略表单项值变化
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
139
    public ignorefieldvaluechange: boolean = false;
140 141 142 143

    /**
     * 数据变化
     *
144
     * @public
145 146 147
     * @type {Subject<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
148
    public dataChang: Subject<any> = new Subject();
149 150 151 152

    /**
     * 视图状态事件
     *
153
     * @public
154 155 156
     * @type {(Subscription | undefined)}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
157
    public dataChangEvent: Subscription | undefined;
158 159 160 161

    /**
     * 原始数据
     *
162
     * @public
163 164 165
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
166
    public oldData: any = {};
167 168 169 170 171 172 173

    /**
     * 表单数据对象
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
174
    public data: any = {
175 176 177 178 179 180 181 182 183 184 185 186
        <#list ctrl.getPSDEFormItems() as item>
        ${item.getName()}: null,
        </#list>
        ${ctrl.getPSAppDataEntity().getCodeName()?lower_case}:null,
    };

    /**
      * 当前执行的行为逻辑
      *
      * @type {string}
      * @memberof ${srfclassname('${ctrl.codeName}')}
      */
187
    public currentAction: string = "";
188 189 190 191 192 193 194

    /**
      * 关系界面计数器
      *
      * @type {number}
      * @memberof ${srfclassname('${ctrl.codeName}')}
      */
195
    public drcounter: number = 0;
196 197 198 199 200 201 202

    /**
      * 需要等待关系界面保存时,第一次调用save参数的备份
      *
      * @type {number}
      * @memberof ${srfclassname('${ctrl.codeName}')}
      */
203
    public drsaveopt: any = {};
204 205 206 207 208 209 210

    /**
      * 表单保存回调存储对象
      *
      * @type {any}
      * @memberof ${srfclassname('${ctrl.codeName}')}
      */
211
    public saveState:any ;
212 213 214 215 216 217 218

    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
219
    public rules: any = {
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
        <#list ctrl.getAllPSDEFormDetails() as formdetail>
        <#if formdetail.getDetailType?? && formdetail.getDetailType() == 'FORMITEM'>
        ${formdetail.getName()}: [
            { 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()} 值必须为<#if datatype=='BigInteger' || datatype=='Integer' || datatype=='Double' || datatype=='Decimal' || datatype=='Float' || datatype=='BigDecimal'>数值<#else>字符串</#if>类型', trigger: 'change' },
            { 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()} 值必须为<#if datatype=='BigInteger' || datatype=='Integer' || datatype=='Double' || datatype=='Decimal' || datatype=='Float' || datatype=='BigDecimal'>数值<#else>字符串</#if>类型', trigger: 'blur' },
            { required: <#if formdetail.isAllowEmpty()>false<#else>true</#if>, 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: <#if formdetail.isAllowEmpty()>false<#else>true</#if>, 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' },
             <#if formdetail.getEditorType?? && formdetail.getEditorType()?? &&  formdetail.isAllowEmpty?? && formdetail.isAllowEmpty()??>
            <#if  formdetail.getEditorType() == 'CHECKBOX' &&  !formdetail.isAllowEmpty()>
            { validator: (rule:any, value:any, callback:any) => { 
                if(rule.required && value != 1){
                   return false;
                }else{
                   return true;
                }
              }, message: '${formdetail.getCaption()} 必须填写', trigger: 'change' ,required:true}
            </#if>
            </#if>
          <#if ctrl.getPSDEFormItemVRs()??>
            <#list ctrl.getPSDEFormItemVRs() as fideValueRule>
            <#if fideValueRule.getPSDEFormItemName() == formdetail.getName()>
              <#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>            
            </#list>
          </#if>
        ],
        </#if>
        </#list>
    }

    /**
     * 详情模型集合
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
265
    public detailsModel: any = {
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
        <#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
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @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>

    /**
     * 重置表单项值
     *
301
     * @public
302 303 304
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
305
    public resetFormData({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
        <#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
      * @memberof EditForm
      */
324
    public ResetData(_datas:any){
325 326 327 328 329 330 331 332 333 334 335 336
        if(Object.keys(_datas).length >0){
            Object.keys(_datas).forEach((name: string) => {
                if (this.data.hasOwnProperty(name)) {
                    this.data[name] = null;
                }
            });
        }
    }

    /**
     * 表单逻辑
     *
337
     * @public
338 339 340
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
341
    public formLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
        <#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>];
            this.updateFormItems('${itemUpdate.codeName}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c});
        }
        </#if>
        </#list>
        </#if>
    }

    /**
     * 表单值变化
     *
362
     * @public
363 364 365 366
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
367
    public formDataChange({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
368 369 370 371 372 373 374 375 376 377 378
        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));
    }

    /**
     * 表单加载完成
     *
379
     * @public
380 381 382 383
     * @param {*} [data={}]
     * @param {string} [action]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
384
    public onFormLoad(data: any = {},action:string): void {
385
<#if de??>
386
        if(Object.is(action,"save") || Object.is(action,"autoSave") || Object.is(action,"submit"))
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
        // 更新context的实体主键
        if(data.${appde.getCodeName()?lower_case}){
            Object.assign(this.context,{${appde.getCodeName()?lower_case}:data.${appde.getCodeName()?lower_case}})
        }
</#if>
        this.setFormEnableCond(data);
        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]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
409
    public fillForm(_datas: any = {},action:string): void {
410 411 412 413 414 415 416 417 418
        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();
        }
419 420 421
        if(Object.is(action,'load')){
            this.updateDefault();
        }
422 423 424 425 426 427 428 429
        this.$nextTick(function () {
            this.ignorefieldvaluechange = false;
        })
    }

    /**
     * 设置表单项是否启用
     *
430
     * @public
431 432 433
     * @param {*} data
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
434
    public setFormEnableCond(data: any): void {
435 436 437 438 439 440 441 442 443 444 445 446
        Object.values(this.detailsModel).forEach((detail: any) => {
            if (!Object.is(detail.detailType, 'FORMITEM')) {
                return;
            }
            const formItem: FormItemModel = detail;
            formItem.setEnableCond(data.srfuf);
        });
    }

    /**
     * 重置草稿表单状态
     *
447
     * @public
448 449
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
450
    public resetDraftFormStates(): void {
451 452 453 454 455 456 457 458 459 460 461
        const form: any = this.$refs.form;
        if (form) {
            form.resetFields();
        }
    }

    /**
     * 重置校验结果
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
462
    public resetValidates(): void {
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
        Object.values(this.detailsModel).forEach((detail: any) => {
            if (!Object.is(detail.detailType, 'FORMITEM')) {
                return;
            }
            const formItem: FormItemModel = detail;
            formItem.setError('');
        });
    }

    /**
     * 填充校验结果 (后台)
     *
     * @param {any[]} fieldErrors
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
478
    public fillValidates(fieldErrors: any[]): void {
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
        fieldErrors.forEach((error: any) => {
            const formItem: FormItemModel = this.detailsModel[error.field];
            if (!formItem) {
                return;
            }
            this.$nextTick(() => {
                formItem.setError(error.message);
            });
        });
    }

    /**
     * 表单校验状态
     *
     * @returns {boolean} 
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
496
    public formValidateStatus(): boolean {
497 498 499 500 501 502 503 504 505 506 507 508 509 510
        const form: any = this.$refs.${ctrl.name};
        let validatestate: boolean = true;
        form.validate((valid: boolean) => {
            validatestate = valid ? true : false;
        });
        return validatestate
    }

    /**
     * 获取全部值
     *
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
511
    public getValues(): any {
512 513 514 515 516 517 518 519 520 521
        return this.data;
    }

    /**
     * 表单项值变更
     *
     * @param {{ name: string, value: any }} $event
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
522
    public onFormItemValueChange($event: { name: string, value: any }): void {
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
        if (!$event) {
            return;
        }
        if (!$event.name || Object.is($event.name, '') || !this.data.hasOwnProperty($event.name)) {
            return;
        }
        this.data[$event.name] = $event.value;
    }

    /**
     * 设置数据项值
     *
     * @param {string} name
     * @param {*} value
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
540
    public setDataItemValue(name: string, value: any): void {
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
        if (!name || Object.is(name, '') || !this.data.hasOwnProperty(name)) {
            return;
        }
        if (Object.is(this.data[name], value)) {
            return;
        }
        this.data[name] = value;
    }

    <#list ctrl.getAllPSDEFormDetails() as formdetail>
    <#if formdetail.getDetailType?? && formdetail.getDetailType() == 'BUTTON'>
    <#if formdetail.getActionType?? && formdetail.getActionType()??>
    <#if formdetail.getActionType() == 'UIACTION'>

	/**
	 * 表单 ${formdetail.getCaption()} 事件
	 *
	 * @memberof @memberof ${srfclassname('${ctrl.codeName}')}
	 */
560
    public ${formdetail.getName()}_click($event: any): void {
561 562 563 564 565 566 567 568 569 570 571 572 573 574
        <#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()} 事件
	 *
	 * @memberof @memberof ${srfclassname('${ctrl.codeName}')}
	 */
575
    public ${formdetail.getName()}_click($event: any): void {
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
    <#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)) {
                        this.$Notice.error({ title: '错误', desc: `操作失败,未能找到当前表单项${r'${key}'},无法继续操作` });
                        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>];
                this.updateFormItems('${itemUpdate.codeName}', arg, details, ${itemUpdate.isShowBusyIndicator()?c});
            }
        });
    <#else>
        const details: string[] = [<#list itemUpdate.getPSDEFIUpdateDetails() as detail><#if detail_index gt 0>, </#if>'${detail.getPSDEFormDetailName()?lower_case}'</#list>];
        this.updateFormItems('${itemUpdate.codeName}', this.data, details, ${itemUpdate.isShowBusyIndicator()?c});
    </#if>
    }
    </#if>
    </#if>
    </#if>
    </#list>


    /**
     * 分组界面行为事件
     *
     * @param {*} $event
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
659
    public groupUIActionClick($event: any): void {
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
        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声明周期(处理组件的输入属性)
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
682
    public created(): void {
683 684 685 686 687 688 689 690
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */    
691
    public afterCreated(){
692 693 694 695 696 697 698 699 700 701 702 703
        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)) {
WodahsOrez's avatar
WodahsOrez committed
704 705 706 707 708
                    if(this.context.srfsourcekey){
                        this.copy(this.context.srfsourcekey);
                    }else{
                        this.loadDraft(data);
                    }
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
                }
                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);
                }
            });
        }
        this.dataChang
            .pipe(
                debounceTime(300),
                distinctUntilChanged()
            ).subscribe((data: any) => {
                if (this.autosave) {
                    this.autoSave();
                }
                <#if ctrl.getControlType() == 'FORM'>
                const state = !Object.is(JSON.stringify(this.oldData), JSON.stringify(this.data)) ? true : false;
                this.$store.commit('viewaction/setViewDataChange', { viewtag: this.viewtag, viewdatachange: state });
                </#if>
                <#if ctrl.getControlType() == 'SEARCHFORM' && ctrl.isEnableAutoSearch()>
                this.$emit('load', this.data);
                </#if>
            });
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
753
    public destroyed() {
754 755 756 757 758 759 760 761
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
762
    public afterDestroy() {
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        if (this.dataChangEvent) {
            this.dataChangEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>      
    }

    /**
     * 拷贝内容
     *
     * @param {*} [arg={}]
     * @memberof @memberof ${srfclassname('${ctrl.codeName}')}
     */
WodahsOrez's avatar
WodahsOrez committed
780 781 782 783 784 785 786 787 788 789 790 791
    public copy(srfkey: string): void {
        let copyData = this.$store.getters.getCopyData(srfkey);
        copyData.srfkey = Util.createUUID();
        copyData.${appde.getCodeName()?lower_case} = copyData.srfkey;
        copyData.${appde.getKeyPSAppDEField().getCodeName()?lower_case} = copyData.srfkey;
        Object.assign(this.context,{${appde.getCodeName()?lower_case}:copyData.${appde.getCodeName()?lower_case}})
        this.data = copyData;
        this.$nextTick(() => {
          this.formState.next({ type: 'load', data: copyData });
          this.data.srfuf = '0';
          this.setFormEnableCond(this.data);
        });
792 793 794 795 796 797
    }

    /**
     *打印
     *@memberof @memberof ${srfclassname('${ctrl.codeName}')}
     */
798
    public print(){
799 800 801 802 803 804 805 806 807 808
        let _this:any = this;
        _this.$print({id:'${ctrl.name}',popTitle:'${ctrl.getLogicName()}'});
    }

    /**
     * 部件刷新
     *
     * @param {any[]} args
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
809
    public refresh(args: any[]): void {
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
        let arg: any = {};
        Object.assign(arg,args[0]);
        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}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
831
    public autoLoad(arg: any = {}): void {
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
        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);
    }

    /**
     * 加载
     *
848
     * @public
849 850 851
     * @param {*} [opt={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
852
    public load(opt: any = {}): void {
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
        if(!this.loadAction){
            this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表单loadAction参数未配置' });
            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) => {
870 871
            if (response && response.status && response.data) {
                this.$Notice.error({ title: '错误', desc: response.data.message });
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
                return;
            }
            if (!response || !response.status || !response.data) {
                this.$Notice.error({ title: '错误', desc: '系统异常' });
                return;
            }
        });
    }

    /**
     * 加载草稿
     *
     * @param {*} [opt={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
887
    public loadDraft(opt: any = {}): void {
888 889 890 891 892 893 894 895 896
        if(!this.loaddraftAction){
            this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表单loaddraftAction参数未配置' });
            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) {
897 898
                if (response.data) {
                    this.$Notice.error({ title: '错误', desc: response.data.message });
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
                }
                return;
            }

            const data = response.data;
            <#if de??>
            if(data.${appde.getCodeName()?lower_case}){
                Object.assign(this.context,{${appde.getCodeName()?lower_case}:data.${appde.getCodeName()?lower_case}})
            }
            </#if>
            this.resetDraftFormStates();
            this.onFormLoad(data,'loadDraft');
            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) => {
926 927
            if (response && response.status  && response.data) {
                this.$Notice.error({ title: '错误', desc: response.data.message });
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
                return;
            }
            if (!response || !response.status || !response.data) {
                this.$Notice.error({ title: '错误', desc: '系统异常' });
                return;
            }
        });
    }

    /**
     * 自动保存
     *
     * @param {*} [opt={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
943
    public autoSave(opt: any = {}): void {
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
        if (!this.formValidateStatus()) {
            return;
        }
        const arg: any = { ...opt };
        const data = this.getValues();
        Object.assign(arg, data);
        const action: any = Object.is(data.srfuf, '1') ? this.updateAction : this.createAction;
        if(!action){
            let actionName:any = Object.is(data.srfuf, '1')?"updateAction":"createAction";
            this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表单'+actionName+'参数未配置' });
            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) {
960 961
                if (response.data) {
                    this.$Notice.error({ title: '错误', desc: response.data.message });
962 963 964 965 966 967 968 969 970 971 972 973 974 975
                }
                return;
            }

            const data = response.data;
            this.onFormLoad(data,'autoSave');
            this.$emit('save', data);
            <#if ctrl.getControlType() == 'FORM'>
            this.$store.dispatch('viewaction/datasaved', { viewtag: this.viewtag });
            </#if>
            this.$nextTick(() => {
                this.formState.next({ type: 'save', data: data });
            });
        }).catch((response: any) => {
976 977
            if (response && response.status && response.data) {
                this.$Notice.error({ title: '错误', desc: response.data.message });
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
                return;
            }
            if (!response || !response.status || !response.data) {
                this.$Notice.error({ title: '错误', desc: '系统异常' });
                return;
            }
        });
    }

    /**
     * 保存
     *
     * @param {*} [opt={}]
     * @param {boolean} [showResultInfo] 
     * @param {boolean} [ifStateNext] formState是否下发通知
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
996
    public async save(opt: any = {}, showResultInfo?: boolean, ifStateNext: boolean = true): Promise<any> {
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
        return new Promise((resolve: any, reject: any) => {
            showResultInfo = showResultInfo === undefined ? true : false;
            if (!this.formValidateStatus()) {
                this.$Notice.error({ title: '错误', desc: '值规则校验异常' });
                return;
            }
            const arg: any = { ...opt };
            const data = this.getValues();
            Object.assign(arg, data);
            Object.assign(arg, this.context);
            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;
                }
            }
            const action: any = Object.is(data.srfuf, '1') ? this.updateAction : this.createAction;
            if(!action){
                let actionName:any = Object.is(data.srfuf, '1')?"updateAction":"createAction";
                this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表单'+actionName+'参数未配置' });
                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) {
1032 1033
                    if (response.data) {
                        this.$Notice.error({ title: '错误', desc: response.data.message });
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
                    }
                    return;
                }

                const data = response.data;
                this.onFormLoad(data,'save');
                this.$emit('save', data);
                <#if ctrl.getControlType() == 'FORM'>
                this.$store.dispatch('viewaction/datasaved', { viewtag: this.viewtag });
                </#if>
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: data });
                });
                <#if ctrl.getFormFuncMode()?lower_case != 'wizardform'>
                if (showResultInfo) {
                    this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;保存成功!' });
                }
                </#if>
                resolve(response);
            }).catch((response: any) => {
1054 1055
                if (response && response.status  && response.data) {
                    this.$Notice.error({ title: '错误', desc: response.data.message });
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
                    this.$Notice.error({ title: '错误', desc: '系统异常' });
                    reject(response);
                    return;
                }
                reject(response);
            });
        })
    }

    /**
    * 删除
    *
1072
    * @public
1073 1074 1075
    * @param {*} [opt={}]
    * @memberof ${srfclassname('${ctrl.name}')}
    */
1076
    public remove(opt:Array<any> = [],showResultInfo?: boolean): Promise<any> {
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
        return new Promise((resolve: any, reject: any) => {
            if(!this.removeAction){
                this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表单removeAction参数未配置' });
                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;
                    this.$Notice.success({ title: '', desc: (data.srfmajortext ? data.srfmajortext : '') + '&nbsp;删除成功!' });
                    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={}]
1107
     * @param {*} [localdata={}]
1108 1109 1110
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1111
    public async wfstart(data: any,localdata?:any): Promise<any> {
1112
        return new Promise((resolve: any, reject: any) => {
1113
            <#--  if(!this.WFStartAction){
1114 1115
                this.$Notice.error({ title: '错误', desc: 'WFCIDEditView视图表单WFStartAction参数未配置' });
                return;
1116
            }  -->
1117
            const _this: any = this;
1118
            const post: Promise<any> = _this.save({},false);
1119 1120 1121 1122 1123
            post.then((response:any) =>{
                const arg:any = response.data;
                if(this.viewparams){
                    Object.assign(arg,{viewparams:this.viewparams});
                }
1124
                const result: Promise<any> = this.service.wfstart(_this.WFStartAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,localdata);
1125 1126
                result.then((response: any) => {
                    if (!response || response.status !== 200) {
1127 1128 1129
                        if(response.data){
                            this.$Notice.error({ title: '', desc: '工作流启动失败, ' + response.data.message });
                        }
1130 1131 1132 1133 1134
                        return;
                    }
                    this.$Notice.info({ title: '', desc: '工作流启动成功' });
                    resolve(response);
            }).catch((response: any) => {
1135 1136
                if (response && response.status && response.data) {
                    this.$Notice.error({ title: '错误', desc: response.data.message });
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
                    this.$Notice.error({ title: '错误', desc: '系统异常' });
                    reject(response);
                    return;
                }
                reject(response);
            });
            }).catch((response: any) => {
1148 1149
                    if (response && response.status && response.data) {
                        this.$Notice.error({ title: '错误', desc: response.data.message });
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
                        reject(response);
                        return;
                    }
                    if (!response || !response.status || !response.data) {
                        this.$Notice.error({ title: '错误', desc: '系统异常' });
                        reject(response);
                        return;
                    }
                    reject(response);
            })
        });
    }

    /**
     * 工作流提交
     *
     * @param {*} [data={}]
1167
     * @param {*} [localdata={}]
1168 1169 1170
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1171
    public async wfsubmit(data: any,localdata?:any): Promise<any> {
1172
        return new Promise((resolve: any, reject: any) => {
1173
        <#--  if(!this.WFSubmitAction){
1174 1175
            this.$Notice.error({ title: '错误', desc: '${view.getName()}视图表单WFSubmitAction参数未配置' });
            return;
1176
        }  -->
1177 1178 1179 1180 1181 1182
        const _this: any = this;
        const arg: any = data[0];
        Object.assign(arg,{viewparams:this.viewparams});
        if (!arg.${ctrl.getPSAppDataEntity().getCodeName()?lower_case} || Object.is(arg.${ctrl.getPSAppDataEntity().getCodeName()?lower_case}, '')) {
            return;
        }
1183
        const post: Promise<any> = Object.is(arg.srfuf, '1')?this.service.update(this.updateAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator):this.service.add(this.createAction,JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator);
1184 1185
        post.then((response:any) =>{
                const arg:any = response.data;
1186 1187 1188 1189 1190 1191 1192
                // 保存完成UI处理
                this.onFormLoad(arg,'save');
                this.$emit('save', arg);
                this.$nextTick(() => {
                    this.formState.next({ type: 'save', data: arg });
                });
                // 准备提交参数
1193 1194 1195
                if(this.viewparams){
                    Object.assign(arg,{viewparams:this.viewparams});
                }
1196
                const result: Promise<any> = this.service.wfsubmit(_this.WFSubmitAction, JSON.parse(JSON.stringify(this.context)),arg, this.showBusyIndicator,localdata);
1197 1198
                result.then((response: any) => {
                    if (!response || response.status !== 200) {
1199 1200 1201
                        if(response.data){
                            this.$Notice.error({ title: '', desc: '工作流提交失败, ' + response.data.message });
                        }
1202 1203
                        return;
                    }
1204 1205
                    this.onFormLoad(arg,'submit');
                    this.$store.dispatch('viewaction/datasaved', { viewtag: this.viewtag });
1206 1207 1208
                    this.$Notice.info({ title: '', desc: '工作流提交成功' });
                    resolve(response);
            }).catch((response: any) => {
1209 1210
                if (response && response.status && response.data) {
                    this.$Notice.error({ title: '错误', desc: response.data.message });
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
                    reject(response);
                    return;
                }
                if (!response || !response.status || !response.data) {
                    this.$Notice.error({ title: '错误', desc: '系统异常' });
                    reject(response);
                    return;
                }
                reject(response);
            });
            }).catch((response: any) => {
1222 1223
                    if (response && response.status && response.data) {
                        this.$Notice.error({ title: '错误', desc: response.data.message });
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
                        reject(response);
                        return;
                    }
                    if (!response || !response.status || !response.data) {
                        this.$Notice.error({ title: '错误', desc: '系统异常' });
                        reject(response);
                        return;
                    }
                    reject(response);
            })
        })
    }
</#if>

    /**
     * 表单项更新
     *
     * @param {string} mode 界面行为名称
     * @param {*} [data={}] 请求数据
     * @param {string[]} updateDetails 更新项
     * @param {boolean} [showloading] 是否显示加载状态
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1248
    public updateFormItems(mode: string, data: any = {}, updateDetails: string[], showloading?: boolean): void {
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
        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) {
                this.$Notice.error({ title: '错误', desc: '表单项更新失败' });
                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));
            this.$nextTick(() => {
                this.formState.next({ type: 'updateformitem', ufimode: arg.srfufimode, data: _data });
            });
        }).catch((response: any) => {
1276 1277
            if (response && response.status && response.data) {
                this.$Notice.error({ title: '错误', desc: response.data.message });
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292
                return;
            }
            if (!response || !response.status || !response.data) {
                this.$Notice.error({ title: '错误', desc: '系统异常' });
                return;
            }
        });
    }

    /**
     * 回车事件
     *
     * @param {*} $event
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1293
    public onEnter($event: any): void {
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
        <#if ctrl.getControlType() == 'SEARCHFORM' && !ctrl.isEnableAutoSearch()>
        this.$emit('load', this.data);
        </#if>
    }

    /**
     * 保存并退出
     *
     * @param {any[]} args
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1305
    public saveAndExit(data:any[]):Promise<any>{
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
        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
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1330
    public saveAndNew(data:any[]):Promise<any>{
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
        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
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1353
    public removeAndExit(data:any[]):Promise<any>{
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
        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
    * @memberof ${srfclassname('${ctrl.codeName}')}
    */
1377
    public drdatasaved($event:any){
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
        let _this = this;
        this.drcounter--;
        if(this.drcounter > 0){
            return;
        }
        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);
                }
            }
        });
    }

    /**
     * 新建默认值
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public createDefault(){                    
        <#list ctrl.getAllPSDEFormDetails() as formdetail><#t>
        <#if formdetail.getCreateDV?? && formdetail.getCreateDV()??><#t>
        <#if !(formdetail.getCreateDV() == '')><#t>
        if (this.data.hasOwnProperty('${formdetail.getCodeName()?lower_case}')) {
        <#-- 网页请求 -->
        <#if formdetail.getCreateDVT() == 'CONTEXT'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.viewparams['${formdetail.getCreateDV()}'];
        <#-- 用户全局对象 -->
        <#elseif formdetail.getCreateDVT() == 'SESSION'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['${formdetail.getCreateDV()}'];
         <#-- 当前应用数据 -->
        <#elseif formdetail.getCreateDVT() == 'APPDATA'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['${formdetail.getCreateDV()}'];
        <#-- 当前操作用户(名称) -->
        <#elseif formdetail.getCreateDVT() == 'OPERATORNAME'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['srfusername'];
        <#-- 当前操作用户(编号) -->
        <#elseif formdetail.getCreateDVT() == 'OPERATOR'>
            this.data['${formdetail.getCodeName()?lower_case}'] = this.context['srfuserid'];
        <#else>
        <#-- 默认值 -->
1423 1424
            <#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>;
1425 1426 1427 1428 1429 1430 1431
        </#if>
        }
        </#if>
        </#if>
        </#list>
    }

1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
    /**
     * 更新默认值
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public updateDefault(){                    
        <#list ctrl.getAllPSDEFormDetails() as formdetail><#t>
        <#if formdetail.getUpdateDV?? && formdetail.getUpdateDV()??><#t>
        <#if !(formdetail.getUpdateDVT() == '')><#t>
        if (this.data.hasOwnProperty('${formdetail.getCodeName()?lower_case}') && !this.data.${formdetail.getCodeName()?lower_case}) {
        <#-- 网页请求 -->
        <#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'];
        <#else>
        <#-- 默认值 -->
1458 1459
            <#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>;
1460 1461 1462 1463 1464 1465 1466
        </#if>
        }
        </#if>
        </#if>
        </#list>
    }

1467 1468 1469 1470 1471 1472 1473 1474 1475
<#--  搜索表单:Begin  -->
<#if ctrl.getControlType() == 'SEARCHFORM'>
    <#if ctrl.getSearchButtonStyle() == 'DEFAULT'>

    /**
     * 搜索
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1476
    public onSearch() {
1477 1478 1479 1480 1481 1482 1483 1484
        this.$emit('load', this.data);
    }

    /**
     * 重置
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1485
    public onReset() {
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
        this.loadDraft();
    }
    </#if>
    <#if ctrl.getSearchButtonStyle() == 'SEARCHONLY'>

    /**
     * 搜索
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
1496
    public onSearch() {
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
        this.$emit('load', this.data);
    }

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

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