import { Component, Input, OnInit, ViewChild } from '@angular/core'; import { MsgHelper } from 'rh-base/core'; import { DataResultT, RhBaseDto, RhSafeAny, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { AndonCallCategoryParametersQueryDto } from '../../andon-module'; import { DynamicFormComponent } from 'rh-base/shared'; type status = 'add' | 'edit'; enum STATUSEMU { ADD = 'add', EDIT = 'edit' } @Component({ selector: 'rh-andon-configuration-call-category-parameters', templateUrl: './andon-configuration-call-category-parameters.component.html', styleUrls: ['./andon-configuration-call-category-parameters.component.css'] }) export class AndonConfigurationCallCategoryParametersComponent implements OnInit { @Input() rhType: 'bind' | '' = ''; @Input() rhBtnItems: RhTableButtonInfoDto[] = []; @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; defaultQueryDto!: AndonCallCategoryParametersQueryDto; dataResult: RhSafeAny; editDto: RhBaseDto = {}; status: status = STATUSEMU.ADD; dataLoading = false; // 表头按钮 titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'add', '新增', 'primary', false, 'file', false, null, (data) => this.addBtnFun(data as RhBaseDto), true, false, 'blue' ) ]; // 表行内按钮 editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'edit', '编辑', 'primary', false, 'edit', false, null, (data) => this.editBtnFun(data as RhBaseDto), true, false, 'blue' ) ]; FormName: 'editForm' | 'addForm' = 'editForm'; constructor() { // } ngOnInit(): void { setTimeout(() => { if (this.rhType === 'bind') { this.titleButtonDataset = []; this.editButtonDataset = this.rhBtnItems; } }, 10); } // 调用查询 getDatas(option?: RhTableQueryOptionDto) { // console.log(this.queryFormCmt); setTimeout(() => { this.queryFormCmt.submitDefaultForm(null, option); }); } /** * form查询完成上弹事件绑定方法 * @param dataset */ resultDataChange(dataset: RhBaseDto[]) { this.dataResult = dataset; } /** * * @param status */ dataLoadingChange(status: boolean) { this.dataLoading = status; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } addBtnFun(event: RhBaseDto) { this.status = STATUSEMU.ADD; this.editDto = event; this.editDto.OpSign = 1; // this.FormName = 'addForm'; this.selectedIndex = 1; } editBtnFun(event: RhBaseDto) { this.status = STATUSEMU.EDIT; this.editDto = event; this.editDto.OpSign = 2; // this.FormName = 'editForm'; this.selectedIndex = 1; } closeEditModal() { // this.selectedIndex = 0; } onStoreData(result: DataResultT) { if (result && result.Success) { const msg = this.status == 'add' ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功!`); this.selectedIndex = 0; this.editDto = {}; this.getDatas(); } else { MsgHelper.ShowWarningModal(`存储数据失败!${result.Message}`); } } }