import { Component, OnInit, ViewChild } from '@angular/core'; import { RhAndonSystemService } from '../andon-system.service'; import { DataResultT, RhBaseDto, RhSafeAny, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { MsgHelper, RhApiUrlsService, RhStorageService } from 'rh-base/core'; import { AndonCallCategoryParametersQueryDto, AndonCallHandleRulesDto, BusinessDocQueryDto } from '../../andon-module'; import { DynamicFormComponent } from 'rh-base/shared'; type status = 'add' | 'edit'; enum STATUSEMU { ADD = 'add', EDIT = 'edit' } @Component({ selector: 'rh-andon-configuration-processing-rules', templateUrl: './andon-configuration-processing-rules.component.html', styleUrls: ['./andon-configuration-processing-rules.component.css'] }) export class AndonConfigurationProcessingRulesComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; @ViewChild('editForm', { static: false }) editForm!: DynamicFormComponent; selectedIndex = 0; defaultQueryDto!: AndonCallCategoryParametersQueryDto; dataResult: RhSafeAny; editDto: RhSafeAny = AndonCallHandleRulesDto.create(); status: status = STATUSEMU.ADD; dataLoading = false; defaultRulesQueryDto!: RhBaseDto; // 表头按钮 titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'add', '新增', 'primary', false, 'file', false, null, (data) => this.addBtnFun(data as RhBaseDto), true, false, 'blue' ), new RhTableButtonInfoDto( 'to-examine', '审核', // 名字叫上传其实是绑定 bind // '添加', 'primary', false, 'audit', false, null, (data) => this.examineBtnFun(data as RhBaseDto), false, true, 'blue' // 'data => data.CallRuleLevelStatus==="Created" ' ) ]; // 表行内按钮 editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'edit', '编辑', 'primary', false, 'edit', false, null, (data) => this.editBtnFun(data as RhBaseDto), true, false, 'blue', 'data => data.CallRuleLevelStatus==="Created" ' ) ]; FormName: 'editRulesForm' | 'addRulesForm' = 'editRulesForm'; // examineData: RhSafeAny; // isShowExamineModal = false; sub: RhSafeAny = {}; //订阅 formConfig = [ { type: 'number', data: [], key: 'UnResponsePushDownTime', shouKey: 'IsUsePushDownStrategy' }, { type: 'select', data: [], selectKey: 'Text', selectValue: 'Value', key: 'UnResponsePushDownTimeUnit', shouKey: 'IsUsePushDownStrategy' }, { type: 'select', data: [], key: 'NextRuleLevelCode', selectKey: 'Value', selectValue: 'Text', display: true, shouKey: 'IsUsePushDownStrategy', /** 关联字段 */ associatedField: [{ key: 'NextRuleLevelName', value: 'Text' }] }, { type: 'select', data: [], key: 'NextRuleLevelName', selectKey: 'Text', selectValue: 'Value', shouKey: 'IsUsePushDownStrategy', /** 关联字段 */ associatedField: [{ key: 'NextRuleLevelCode', value: 'Value' }] }, { type: 'select', data: [], key: 'BusinessProcessFlowCode', selectKey: 'Value', selectValue: 'Text', display: true, shouKey: 'IsUseIntegrateBusinessFlow', associatedField: [{ key: 'BusinessProcessFlowName', value: 'Text' }] }, { type: 'select', data: [], key: 'BusinessProcessFlowName', selectKey: 'Text', selectValue: 'Value', shouKey: 'IsUseIntegrateBusinessFlow', associatedField: [{ key: 'BusinessProcessFlowCode', value: 'Value' }] } ]; /**呼叫规则等级编码 */ CallRuleLevelCode = ''; constructor( private andonSystemService: RhAndonSystemService, private apiService: RhApiUrlsService, public storageSer: RhStorageService ) {} ngOnInit(): void { // // 有关联的下拉框选择 const selectAssociatedArr = this.formConfig.filter((f) => f.associatedField && f.associatedField.length); const message = this.andonSystemService.getMessageSource().subscribe((res) => { const arrjson = JSON.parse(res); const form = this.editForm.defaultForm; // console.log(arrjson); for (const key in arrjson) { /** 下拉关联特殊处理 */ const item = arrjson[key]; const j = selectAssociatedArr.findIndex((g) => g.key == key); if (j != -1) { this.editDto[key] = item ? item[selectAssociatedArr[j].selectKey as string] : null; form.get(key)?.setValue(this.editDto[key]); selectAssociatedArr[j]?.associatedField?.forEach((field) => { this.editDto[field.key] = item ? item[field.value] : null; form.get(field.key)?.setValue(item ? item[field.value] : null); }); } else if (Object.prototype.hasOwnProperty.call(arrjson, key)) { const element = item; form.get(key)?.setValue(element); this.editDto[key] = element; } } this.andonSystemService.sendValue(arrjson); }); this.sub['message'] = message; this.getSettingEntry(); } ngAfterViewInit() { // } getSettingEntry() { this.apiService .getSettingEntry({ moduleKey: 'AndonManagement', groupKey: 'AndonCallConfiguration', paraCode: 'UnResponsePushDownTimeUnit' }) .subscribe((res) => { if (res.Success) { this.formConfig[1].data = res.Attach as RhSafeAny; } else { this.formConfig[1].data = []; } }); } /** 获取 业务流程 */ GetBusinessSelectItems(event: { CallCategoryCode: string; CallCategoryItemCode: string }) { const qty = BusinessDocQueryDto.create(); qty.BusinessType = event.CallCategoryCode; qty.IsUse = true; this.andonSystemService.GetBusinessSelectItems(qty).subscribe((res) => { if (Array.isArray(res)) { this.formConfig[4].data = res as RhSafeAny; this.formConfig[5].data = res as RhSafeAny; } else { this.formConfig[4].data = []; this.formConfig[5].data = []; } this.andonSystemService.sendValue({ BusinessProcessFlowCode: null, BusinessProcessFlowName: null }); }); } // 调用查询 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 = JSON.parse(JSON.stringify(event)); this.editDto.OpSign = 1; this.selectedIndex = 1; // this.getCallRuleLevelCodeValue(); } editBtnFun(event: RhBaseDto) { this.status = STATUSEMU.EDIT; this.editDto = JSON.parse(JSON.stringify(event)); this.editDto.OpSign = 2; // this.FormName = 'editRulesForm'; this.GetHandleRuleSelectItem( () => { this.selectedIndex = 1; }, { CallRuleLevelCode: event?.['CallRuleLevelCode'], CallCategoryCode: event['CallCategoryCode'] || '', CallCategoryItemCode: event['CallCategoryItemCode'] || '' } ); //TODO: 获取下级代码 this.GetBusinessSelectItems( event as { CallCategoryCode: string; CallCategoryItemCode: string; } ); // this.getCallRuleLevelCodeValue({ // CallRuleLevelCode: event?.CallRuleLevelCode, // CallCategoryCode: event.CallCategoryCode || '', // CallCategoryItemCode: event.CallCategoryItemCode || '' // }); } /** * 这是一坨垃圾代码,不知道当时为啥要这么写(°_o) 在表单渲染完成后获取下级规则下拉得值 */ // getCallRuleLevelCodeValue(params?: { CallRuleLevelCode: string; CallCategoryCode: string; CallCategoryItemCode: string }) { // if (this.editForm && this.editForm.defaultForm && this.editForm.defaultForm.get('IsUseIntegrateBusinessFlow')) { // this.editForm.defaultForm.get('IsUsePushDownStrategy').valueChanges.subscribe((bo: boolean) => { // // console.log(bo); // if (bo && params) { // this.andonSystemService.GetHandleRuleSelectItem(params).subscribe((res) => { // this.formConfig[2].data = res; // this.formConfig[3].data = res; // }); // // sub.unsubscribe(); // } // }); // } else { // setTimeout(() => { // console.log('settimeout垃圾代码执行'); // this.getCallRuleLevelCodeValue(params); // }, 1000); // } // } /** * 清空 呼叫类别 */ clearCallCategoryCode() { this.formConfig[2].data = []; this.formConfig[3].data = []; this.formConfig[4].data = []; this.formConfig[5].data = []; } CallCategoryCodeChange(event: { CallCategoryCode: string; CallCategoryItemCode: string }) { // 获取下拉数据 业务流程 this.GetBusinessSelectItems(event); // 获取下拉数据 下级规则等级 const params = { CallRuleLevelCode: this.editDto['CallRuleLevelCode'] || '', ...event }; this.andonSystemService.GetHandleRuleSelectItem(params).subscribe((res) => { this.formConfig[2].data = res as RhSafeAny; this.formConfig[3].data = res as RhSafeAny; // this.editDto.NextRuleLevelCode = null; // this.editForm.defaultForm.get('NextRuleLevelCode').setValue(null); // this.editDto.NextRuleLevelName = null; // this.editForm.defaultForm.get('NextRuleLevelName').setValue(null); this.andonSystemService.sendValue({ NextRuleLevelCode: null, NextRuleLevelName: null }); }); } /** * 获取下级策略 * @param collback 父传子 回调函数防止异步调用后赋值 显示不完整 * @param params */ GetHandleRuleSelectItem( collback: RhSafeAny, params?: { CallRuleLevelCode: string; CallCategoryCode: string; CallCategoryItemCode: string } ) { this.andonSystemService.GetHandleRuleSelectItem(params as RhSafeAny).subscribe((res) => { this.formConfig[2].data = res as RhSafeAny; this.formConfig[3].data = res as RhSafeAny; collback(); }); } // CallCategoryCodeChange() { // if ( // this.editForm && // this.editForm.defaultForm && // this.editForm.defaultForm.get('CallCategoryCode') // ) { // const CallCategoryCodeChange = this.editForm.defaultForm.get('CallCategoryCode').valueChanges.subscribe((data) => { // console.log('CallCategoryCode', data); // }); // } else { // setTimeout(() => { // this.CallCategoryCodeChange(); // }, 1000); // } // } 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}`); } } examineBtnFun(event: RhBaseDto) { // this.examineData = event; // this.isShowExamineModal = true; MsgHelper.ShowConfirmModal('是否进行审核', '是否审核选中的数据?', () => { // event.CheckerCode = this.storageSer.getUserSession()?.User?.UserId.toString(); if (Array.isArray(event)) { event.forEach((f) => { f.Auditor = this.storageSer.getUserSession()?.User?.UserName; }); this.andonSystemService.AuditAndonCallHandleRules(event as AndonCallHandleRulesDto[]).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`审核数据成功!`); this.getDatas(); } else { MsgHelper.ShowWarningModal(`审核失败!,${result.Message}`); } }); } else { // 当按钮在行内时审核一条 // 当按钮在行内时审核一条 event['Auditor'] = this.storageSer.getUserSession()?.User?.UserName; this.andonSystemService.AuditAndonCallHandleRule(event as AndonCallHandleRulesDto).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`审核数据成功!`); this.getDatas(); } else { MsgHelper.ShowWarningModal(`审核失败!,${result.Message}`); } }); } }); } /** 关闭审核弹窗选择审核人 */ // uploadModalexamineClose() { // this.examineData = {}; // this.isShowExamineModal = false; // } ngOnDestroy() { for (const key in this.sub) { if (Object.prototype.hasOwnProperty.call(this.sub, key)) { const element = this.sub[key]; if (element) element.unsubscribe(); } } } }