import { Component, Input ,Inject} from '@angular/core'; import { FormGroup, Validators, FormBuilder } from '@angular/forms'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { HttpService } from '@app/core/services/http.service'; import { ToastService } from '@app/core/services/toast.service'; import { I18nService } from '@app/core/services/i18n.service'; import { DialogService } from '@app/core/services/dialog.service'; @Component({ selector: 'app-wcs-requestWmsedit-handcommandedit', templateUrl: './requestWmsedit.component.html', styleUrls: ['./requestWmsedit.component.scss'] }) export class RequestWmseditComponent { private _form: FormGroup; constructor( @Inject(MAT_DIALOG_DATA) private _id: any, private _dialogService: DialogService, private _formBuilder: FormBuilder, private _httpService: HttpService, private _toastService: ToastService, private _i18nService: I18nService, private _dialogRef: MatDialogRef, ) { this._form = this._formBuilder.group({ Barcode1: [null, [Validators.required]], Barcode2: [null, [Validators.required]]//对应HTML定义的控件名称 }); this.Init(); } async Init(): Promise { //let res: any = await this._httpService.get('handcommand/devicelist'); // this._devicelist = res.items; } public get form() { return this._form; }; // console.log(); public save = async () => { if(this.form.controls.Barcode1.value==null||this.form.controls.Barcode1.value==""){ this._toastService.show(this._i18nService.translate('routes.wcs.reuquestWms.barCodeError1')); return; } if(this.form.controls.Barcode1.value.indexOf('|')!=-1){ this._toastService.show(this._i18nService.translate('routes.wcs.reuquestWms.barCodeError2')); return; } if(this.form.controls.Barcode2.value!=null&&this.form.controls.Barcode2.value!=""){ if(this.form.controls.Barcode2.value.indexOf('|')!=-1){ this._toastService.show(this._i18nService.translate('routes.wcs.reuquestWms.barCodeError3')); return; } } if (await this._dialogService.confirm(this._i18nService.translate('shared.notification.confirm'))) { const data: any = { id: this._id, barCode1: this.form.controls.Barcode1.value, barCode2: this.form.controls.Barcode2.value==null ? "":this.form.controls.Barcode2.value, }; const res = await this._httpService.post(`reuquestWms`, data).catch(async err => { switch (err.status) { case 409: this._toastService.show(this._i18nService.translate(`routes.wcs.monitor.barCodeErrorHaveApply`)); break; case 410: this._toastService.show(this._i18nService.translate(`routes.wcs.monitor.barCodeErrorHaveControlTask`)); break; case 422: this._toastService.show(this._i18nService.translate('routes.wcs.monitor.barCodeErrorHaveWcsTask')); break; case 480: this._toastService.show(this._i18nService.translate(`routes.wcs.monitor.barCodelengthError`)); case 481: this._toastService.show(this._i18nService.translate(`routes.wcs.monitor.barCodelengthError`)); break; default: break; } }) !== undefined; if (res) { this._toastService.show(this._i18nService.translate('shared.notification.success')); this._dialogRef.close(true); } } } }