CONTROL-BASE.vue.ftl 29.6 KB
Newer Older
1 2 3 4 5 6
<#ibizinclude>
../../@MACRO/LANG_FUN.ftl
</#ibizinclude>
<template>
    ${P.getPartCode(item,'FORM').code}
</template>
7
// 基于 @CONTROL/搜索表单/CONTROL-BASE.vue.ftl 生成
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
<#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}')}Base
     */
    public getDatas(): any[] {
        return [this.data];
    }

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

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
42
    @Prop({ default: true }) public showBusyIndicator?: boolean;
43 44 45 46 47 48 49
    
    /**
     * 部件行为--loaddraft
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
50
    @Prop() public loaddraftAction!: string;
51 52 53 54 55 56 57
    
    /**
     * 部件行为--load
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
58
    @Prop() public loadAction!: string;
59 60 61 62 63 64 65

    /**
     * 视图标识
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
66
    @Prop() public viewtag!: string;
67 68 69 70 71 72 73

    /**
     * 表单状态
     *
     * @type {Subject<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
74
    public formState: Subject<any> = new Subject();
75 76 77 78 79 80 81

    /**
     * 忽略表单项值变化
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
82
    public ignorefieldvaluechange: boolean = false;
83 84 85 86

    /**
     * 数据变化
     *
87
     * @public
88 89 90
     * @type {Subject<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
91
    public dataChang: Subject<any> = new Subject();
92 93 94 95

    /**
     * 视图状态事件
     *
96
     * @public
97 98 99
     * @type {(Subscription | undefined)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
100
    public dataChangEvent: Subscription | undefined;
101 102 103 104

    /**
     * 原始数据
     *
105
     * @public
106 107 108
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
109
    public oldData: any = {};
110 111 112 113 114 115 116

    /**
     * 表单数据对象
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
117
    public data: any = {
118 119 120 121 122
        <#list ctrl.getPSDEFormItems() as item>
        ${item.getName()}: null,
        </#list>
    };

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    /**
     * 详情模型集合
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public detailsModel: any = {
        <#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>
    };
    
138 139 140 141 142 143
    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
144
    public rules: any = {
145 146 147 148 149
        <#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' },
150 151
            { 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' },
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
        ],
        </#if>
        </#list>
    }

    <#list ctrl.getPSDEFormItems() as item>
    /**
     * 监控表单属性 ${item.getName()} 值
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Watch('data.${item.getName()}')
    on${srfclassname('${item.getName()}')}Change(newVal: any, oldVal: any) {
        this.formDataChange({ name: '${item.getName()}', newVal: newVal, oldVal: oldVal });
    }

    </#list>

    /**
     * 重置表单项值
     *
175
     * @public
176 177 178
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
179
    public resetFormData({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        <#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>
    }

    /**
     * 表单逻辑
     *
195
     * @public
196 197 198
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
199
    public formLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
        <#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>
    }

    /**
     * 表单值变化
     *
220
     * @public
221 222 223 224
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
225
    public formDataChange({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
226 227 228 229 230 231
        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));
tony001's avatar
tony001 committed
232 233 234 235
        <#-- 搜索栏值变更抛值 -->
        <#if ctrl.getFormStyle() == "SEARCHBAR">
        this.$emit('valuechange',this.data);
        </#if>
236 237 238 239 240
    }

    /**
     * 表单加载完成
     *
241
     * @public
242
     * @param {*} [data={}]
243
     * @param {string} [action]
244 245
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
246
    public onFormLoad(data: any = {},action:string): void {
247
        this.setFormEnableCond(data);
248
        this.fillForm(data,action);
249 250 251 252 253 254 255 256 257 258 259 260
        <#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={}]
261
     * @param {string} [action]
262 263
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
264
    public fillForm(_datas: any = {},action:string): void {
265 266 267 268 269 270
        this.ignorefieldvaluechange = true;
        Object.keys(_datas).forEach((name: string) => {
            if (this.data.hasOwnProperty(name)) {
                this.data[name] = _datas[name];
            }
        });
271 272 273
        if(Object.is(action,'loadDraft')){
            this.createDefault();
        }
274 275 276 277 278 279 280 281
        this.$nextTick(function () {
            this.ignorefieldvaluechange = false;
        })
    }

    /**
     * 设置表单项是否启用
     *
282
     * @public
283 284 285
     * @param {*} data
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
286
    public setFormEnableCond(data: any): void {
287 288 289 290 291 292 293 294 295
        Object.values(this.detailsModel).forEach((detail: any) => {
            if (!Object.is(detail.detailType, 'FORMITEM')) {
                return;
            }
            const formItem: FormItemModel = detail;
            formItem.setEnableCond(data.srfuf);
        });
    }

296 297 298 299 300 301
    /**
     * 新建默认值
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public createDefault(){                    
<#list ctrl.getAllPSDEFormDetails() as formdetail><#t>
302
  <#if (formdetail.getCreateDV?? || formdetail.getCreateDVT??) && (formdetail.getCreateDV()?? || formdetail.getCreateDVT()??) && (formdetail.getCreateDV() !="" || formdetail.getCreateDVT() != "")><#t>
303
        if (this.data.hasOwnProperty('${formdetail.getCodeName()?lower_case}')) {
304
      <#if !(formdetail.getCreateDVT() == '')><#t>
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
      <#-- 网页请求 -->
      <#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'];
      <#-- 当前时间 -->
      <#elseif formdetail.getCreateDVT() == 'CURTIME'>
          this.data['${formdetail.getCodeName()?lower_case}'] = this.$util.dateFormat(new Date());
323 324 325
      <#-- 数据对象属性 -->
      <#elseif formdetail.getCreateDVT() == 'PARAM'>
          this.data['${formdetail.getCodeName()?lower_case}'] = this.service.getRemoteCopyData().${formdetail.getCreateDV()}?this.service.getRemoteCopyData().${formdetail.getCreateDV()}:null;
326
      </#if>
327 328 329 330 331
       <#else>
      <#-- 默认值 -->
          <#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>;
        </#if>
332 333 334 335 336
        }
  </#if>
</#list>
    }

337 338 339
    /**
     * 重置草稿表单状态
     *
340
     * @public
341 342
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
343
    public resetDraftFormStates(): void {
344 345 346 347 348 349 350 351 352 353 354
        const form: any = this.$refs.form;
        if (form) {
            form.resetFields();
        }
    }

    /**
     * 重置校验结果
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
355
    public resetValidates(): void {
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
        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}')}Base
     */
371
    public fillValidates(fieldErrors: any[]): void {
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
        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}')}Base
     */
389
    public formValidateStatus(): boolean {
390 391 392 393 394 395 396 397 398 399 400 401 402 403
        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}')}Base
     */
404
    public getValues(): any {
405 406 407 408 409 410 411 412 413 414
        return this.data;
    }

    /**
     * 表单项值变更
     *
     * @param {{ name: string, value: any }} $event
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
415
    public onFormItemValueChange($event: { name: string, value: any }): void {
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
        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}')}Base
     */
433
    public setDataItemValue(name: string, value: any): void {
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
        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}')}Base
	 */
453
    public ${formdetail.getName()}_click($event: any): void {
454 455 456 457 458 459 460 461 462 463 464 465 466 467
        <#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}')}Base
	 */
468
    public ${formdetail.getName()}_click($event: any): void {
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 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
    <#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)) {
517
                        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>` });
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
                        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}')}Base
     */
552
    public groupUIActionClick($event: any): void {
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
        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}')}Base
     */
575
    public created(): void {
576 577 578 579 580 581 582 583
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
     */    
584
    public afterCreated(){
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
        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)) {
                    this.loadDraft(data);
                }
            });
        }
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
608
    public destroyed() {
609 610 611 612 613 614 615 616
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
617
    public afterDestroy() {
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        if (this.dataChangEvent) {
            this.dataChangEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

    /**
     * 自动加载
     *
     * @param {*} [arg={}]
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
636
    public autoLoad(arg: any = {}): void {
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
        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);
    }

    /**
     * 加载
     *
653
     * @public
654 655 656
     * @param {*} [opt={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
657
    public load(opt: any = {}): void {
658
        if(!this.loadAction){
659
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.searchForm.notConfig.loadAction') as string) });
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
            return;
        }
        const arg: any = { ...opt };
        Object.assign(arg,{viewparams:this.viewparams});
        const get: Promise<any> = this.service.get(this.loadAction,JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
        get.then((response: any) => {
            if (response && response.status === 200) {
                const data = response.data;
                this.$emit('load', data);
                this.$nextTick(() => {
                    this.formState.next({ type: 'load', data: data });
                });
            }
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
            if (!response || !response.status || !response.data) {
678
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
679 680 681 682 683 684 685 686 687 688 689 690 691 692
                return;
            }

            const { data: _data } = response;
            this.$Notice.error({ title: _data.title, desc: _data.message });
        });
    }

    /**
     * 加载草稿
     *
     * @param {*} [opt={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
Mosher's avatar
Mosher committed
693
    public async loadDraft(opt: any = {},mode?:string): Promise<any> {
694
        if(!this.loaddraftAction){
695
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '${view.getName()}' + (this.$t('app.searchForm.notConfig.loaddraftAction') as string) });
696 697 698
            return;
        }
        const arg: any = { ...opt } ;
Mosher's avatar
Mosher committed
699 700 701 702 703 704
        Object.assign(arg, { viewparams:this.viewparams });
        if (!(await this.handleCtrlEvents('onbeforeloaddraft', { data: arg }))) {
            return;
        }
        try {
            const response = await this.service.loadDraft(this.loaddraftAction,JSON.parse(JSON.stringify(this.context)), arg, this.showBusyIndicator);
705
            if (!response.status || response.status !== 200) {
Mosher's avatar
Mosher committed
706 707 708
                if (!(await this.handleCtrlEvents('onloaddrafterror', { data: response && response.data ? response.data : arg }))) {
                    return;
                }
709 710
                if (response.data && response.data.message) {
                    this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.data.message });
711
                }
Mosher's avatar
Mosher committed
712 713 714
                return response;
            }
            if (!(await this.handleCtrlEvents('onloaddraftsuccess', { data: response.data }))) {
715 716 717 718
                return;
            }
            const data = response.data;
            this.resetDraftFormStates();
719
            this.onFormLoad(data,'loadDraft');
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
            setTimeout(() => {
                const form: any = this.$refs.form;
                if (form) {
                    form.fields.forEach((field: any) => {
                        field.validateMessage = "";
                        field.validateState = "";
                        field.validateStatus = false;
                    });
                }
            });
            if(Object.is(mode,'RESET')){
                if (!this.formValidateStatus()) {
                    return;
                }
            }
            this.$emit('load', data);
            this.$nextTick(() => {
                this.formState.next({ type: 'load', data: data });
            });
Mosher's avatar
Mosher committed
739 740 741 742 743
            return response;
        } catch(response: any) {
            if (!(await this.handleCtrlEvents('onloaddrafterror', { data: response && response.data ? response.data : arg }))) {
                return;
            }
744 745 746 747
            if (response && response.status === 401) {
                return;
            }
            if (!response || !response.status || !response.data) {
748
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: (this.$t('app.commonWords.sysException') as string) });
749 750 751 752 753
                return;
            }

            const { data: _data } = response;
            this.$Notice.error({ title: _data.title, desc: _data.message });
Mosher's avatar
Mosher committed
754
        }
755 756 757 758 759 760 761 762 763 764 765 766
    }

    /**
     * 表单项更新
     *
     * @param {string} mode 界面行为名称
     * @param {*} [data={}] 请求数据
     * @param {string[]} updateDetails 更新项
     * @param {boolean} [showloading] 是否显示加载状态
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
767
    public updateFormItems(mode: string, data: any = {}, updateDetails: string[], showloading?: boolean): void {
768 769 770 771 772 773 774 775 776
        
    }

    /**
     * 回车事件
     *
     * @param {*} $event
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
777
    public onEnter($event: any): void {
778 779 780 781
        <#if ctrl.getControlType() == 'SEARCHFORM' && !ctrl.isEnableAutoSearch()>
        if (!this.formValidateStatus()) {
            return;
        }
tony001's avatar
tony001 committed
782
        this.$emit('search', this.data);
783 784 785 786 787 788 789 790 791 792 793
        </#if>
    }
<#--  搜索表单:Begin  -->
<#if ctrl.getControlType() == 'SEARCHFORM'>
    <#if ctrl.getSearchButtonStyle() == 'DEFAULT'>

    /**
     * 搜索
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
794
    public onSearch() {
795 796 797
        if (!this.formValidateStatus()) {
            return;
        }
Mosher's avatar
Mosher committed
798 799 800 801 802
        this.handleCtrlEvents('onsearch', { }).then((result: boolean) => {
            if (result) {
                this.$emit('search', this.data);
            }
        })
803 804 805 806 807 808 809
    }

    /**
     * 重置
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
810
    public onReset() {
Mosher's avatar
Mosher committed
811 812 813 814 815
        this.handleCtrlEvents('onreset', { }).then((result: boolean) => {
            if (result) {
                this.loadDraft({},'RESET');
            }
        })
816 817 818 819 820 821 822 823 824
    }
    </#if>
    <#if ctrl.getSearchButtonStyle() == 'SEARCHONLY'>

    /**
     * 搜索
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
825
    public onSearch() {
826 827 828
        if (!this.formValidateStatus()) {
            return;
        }
Mosher's avatar
Mosher committed
829 830 831 832 833
        this.handleCtrlEvents('onsearch', { }).then((result: boolean) => {
            if (result) {
                this.$emit('search', this.data);
            }
        })
834 835 836 837 838 839 840 841 842 843 844
    }
    </#if>
</#if>
<#--  搜索表单:End  -->
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

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