import { FormHelper, ObjectHelper } from 'rh-base/core'; import { ProcessInspectRulesDto } from './../../../qmp-model'; import { Component, OnInit, AfterContentInit, TemplateRef, ContentChildren, QueryList, Output, EventEmitter, Input } from '@angular/core'; import { RhTemplateDirective } from 'rh-base/shared'; import { UntypedFormGroup, UntypedFormBuilder } from '@angular/forms'; @Component({ selector: 'rh-inspect-rule-snippet', templateUrl: './inspect-rule-snippet.component.html', styleUrls: ['./inspect-rule-snippet.component.less'] }) export class RhInspectRuleSnippetComponent implements OnInit, AfterContentInit { @Input() rhData!: ProcessInspectRulesDto; @Output() rhOk = new EventEmitter(); @Output() rhCancel = new EventEmitter(); /** 是否显示检验单生成规则tab */ @Input() isShowGenerateTab = true; /** 是否显示送检数量生成规则tab */ @Input() isShowInspectTab = true; @ContentChildren(RhTemplateDirective) templates!: QueryList; extraTpl!: TemplateRef; titleTpl!: TemplateRef; inspectDto!: ProcessInspectRulesDto; inspectForm!: UntypedFormGroup; // currentGenerateType: 'time' | 'quantity'; currentInspectType!: 'quantity' | 'rate'; /** 是否定时生成 */ timeGenerateEanble = false; /** 是否定量生成 */ quantityGenerateEanble = false; constructor(public fb: UntypedFormBuilder) { // } ngOnInit(): void { // console.log(this.rhData); this.inspectDto = { ...this.rhData } || this.initInspectDto(); this.timeGenerateEanble = this.inspectDto.IsTimingStart as boolean; this.quantityGenerateEanble = this.inspectDto.IsQuantitativeStart as boolean; this.currentInspectType = this.inspectDto?.FixedSendInspectQty ? 'quantity' : 'rate'; this.inspectDto.inspectRuleType = this.currentInspectType; this.createInspectForm(this.inspectDto); } ngAfterContentInit() { const extraTarget = this.templates.find((ele) => ele.getType() === 'extra'); this.extraTpl = extraTarget?.template as TemplateRef; const titleTarget = this.templates.find((ele) => ele.getType() === 'title'); this.titleTpl = titleTarget?.template as TemplateRef; } initInspectDto(): ProcessInspectRulesDto { const temp = ProcessInspectRulesDto.create(); return temp; } createInspectForm(dto: ProcessInspectRulesDto) { this.inspectForm = this.fb.group({ // 生成规则 generateRule: this.fb.group({ IsTimingStart: [dto.IsTimingStart], IsQuantitativeStart: [dto.IsQuantitativeStart], CronJson: [dto.CronJson], FactoryProductionCount: [dto.FactoryProductionCount], PlanProductionCount: [dto.PlanProductionCount], ProcessProductionCount: [dto.ProcessProductionCount] }), // 送检规则 inspectRule: this.fb.group({ inspectRuleType: [dto.inspectRuleType], FixedSendInspectQty: [dto.FixedSendInspectQty], SendInspectQtyRate: [dto.SendInspectQtyRate] }) }); } submitInspectForm(event: Event) { if (event) { event.preventDefault(); } FormHelper.ValidateBeforeSubmit(this.inspectForm); if (this.inspectForm.invalid) { return; } const formValue = this.inspectForm.value; if (this.isShowGenerateTab) { ObjectHelper.MapT(formValue.generateRule, this.inspectDto); } if (this.isShowInspectTab) { ObjectHelper.MapT(formValue.inspectRule, this.inspectDto); } this.rhOk.emit(this.inspectDto); } resetInspectForm(event: Event) { if (event) { event.preventDefault(); } this.inspectDto = this.initInspectDto(); this.inspectForm.reset(this.inspectDto); } // onGenerateRuleTypeChange(type: 'time' | 'quantity') { // this.currentGenerateType = type; // } onInspectRuleTypeChange(type: 'quantity' | 'rate') { this.currentInspectType = type; if (type === 'quantity') { this.inspectForm.get('inspectRule')?.get('SendInspectQtyRate')?.patchValue(null); } else { this.inspectForm.get('inspectRule')?.get('FixedSendInspectQty')?.patchValue(null); } } onTimeGenrateEnableChange(status: boolean) { this.timeGenerateEanble = status; } onQuantityGenerateEnableChange(status: boolean) { this.quantityGenerateEanble = status; } // onSave() { // this.rhOk.emit(); // } onBack() { this.rhCancel.emit(); } }