You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
347 lines
14 KiB
347 lines
14 KiB
import { Component } from '@angular/core';
|
|
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
|
|
import { MatDialogRef } 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';
|
|
import { identifierModuleUrl } from '@angular/compiler';
|
|
|
|
@Component({
|
|
selector: 'app-wcs-autocommand-autocommandedit',
|
|
templateUrl: './autocommandedit.component.html',
|
|
styleUrls: ['./autocommandedit.component.scss']
|
|
})
|
|
export class AutocommandeditComponent {
|
|
|
|
private _form: FormGroup;
|
|
private _tasktypelist: any[];
|
|
private _startdevice: any[];
|
|
private _startZ: any[];
|
|
private _startX: any[];
|
|
private _startY: any[];
|
|
private _enddevice: any[];
|
|
private _endZ: any[];
|
|
private _endX: any[];
|
|
private _endY: any[];
|
|
|
|
public startdevicehide: boolean = true;
|
|
public startZXYhide: boolean = true;
|
|
public enddevicehide: boolean = true;
|
|
public endZXYhide: boolean = true;
|
|
|
|
private _saveyesno: boolean = true;
|
|
|
|
|
|
constructor(
|
|
private _dialogService: DialogService,
|
|
private _formBuilder: FormBuilder,
|
|
private _httpService: HttpService,
|
|
private _toastService: ToastService,
|
|
private _i18nService: I18nService,
|
|
private _dialogRef: MatDialogRef<AutocommandeditComponent>
|
|
) {
|
|
this._form = this._formBuilder.group({
|
|
barcode: [null, [Validators.required]],
|
|
tasktypelist: [null, [Validators.required]],
|
|
startdevice: [null, [Validators.required]],
|
|
startZ: [null, [Validators.required]],
|
|
startX: [null, [Validators.required]],
|
|
startY: [null, [Validators.required]],
|
|
enddevice: [null, [Validators.required]],
|
|
endZ: [null, [Validators.required]],
|
|
endX: [null, [Validators.required]],
|
|
endY: [null, [Validators.required]],
|
|
pallettype: [null, [Validators.required]],
|
|
});
|
|
|
|
this.Init();
|
|
|
|
}
|
|
async Init(): Promise<void> {
|
|
|
|
let res: any = await this._httpService.get('autocommand/tasktypelist');
|
|
this._tasktypelist = res.items;
|
|
}
|
|
public async tasktypeSelected(e: any): Promise<void> {
|
|
if (e) {
|
|
|
|
if (e.value == 1) {
|
|
this.startZXYhide = false;
|
|
this.endZXYhide = true;
|
|
|
|
/* let res: any = await this._httpService.get(`autocommand/startdevicelist?tasktype=${e.value}`);
|
|
this._startdevice = res.items; */
|
|
|
|
}
|
|
else if (e.value == 2) {
|
|
this.startZXYhide = true;
|
|
this.endZXYhide = false;
|
|
|
|
/* let res: any = await this._httpService.get(`autocommand/startdevicelist?tasktype=${e.value}`);
|
|
this._startdevice = res.items; */
|
|
|
|
}
|
|
else if (e.value == 3) {
|
|
this.startZXYhide = true;
|
|
this.endZXYhide = true;
|
|
|
|
}
|
|
else if (e.value == 4) {
|
|
/* this.startZXYhide=true;
|
|
this.endZXYhide=true; */
|
|
this.startZXYhide = false;
|
|
this.endZXYhide = false;
|
|
|
|
}
|
|
else {
|
|
//目前数据库就定义了这四种类型 要是新增类型 在增加一个else if
|
|
//此处只是防止忘记修改做的提示
|
|
this._dialogService.confirm(this._i18nService.translate('routes.wcs.autocommand.nohavethistype'))
|
|
}
|
|
|
|
let res: any = await this._httpService.get(`autocommand/startdevicelist?tasktype=${e.value}`);
|
|
this._startdevice = res.items;
|
|
|
|
this.form.controls['startdevice'].setValue(null);
|
|
this.form.controls['enddevice'].setValue(null);
|
|
this.form.controls['startZ'].setValue(null);
|
|
this.form.controls['startX'].setValue(null);
|
|
this.form.controls['startY'].setValue(null);
|
|
this.form.controls['endZ'].setValue(null);
|
|
this.form.controls['endX'].setValue(null);
|
|
this.form.controls['endY'].setValue(null);
|
|
|
|
|
|
}
|
|
}
|
|
public async startdeviceSelected(etasktype: any, estartdevice: any): Promise<void> {
|
|
if (etasktype && estartdevice) {
|
|
|
|
this._startX = [{ id: "", name: "" }];
|
|
this._startY = [{ id: "", name: "" }];
|
|
this._startZ = [{ id: "", name: "" }];
|
|
|
|
let res: any = await this._httpService.get(`autocommand/enddevicelist?tasktype=${etasktype.value}&startdevice=${estartdevice.value}`);
|
|
this._enddevice = res.items;
|
|
|
|
if (this._startdevice.find(item => item.id == estartdevice.value).devicekind == "10") {
|
|
//选择的是巷道 要加载Z
|
|
let res: any = await this._httpService.get(`autocommand/startzxy?startdevice=${estartdevice.value}`);
|
|
|
|
this._startZ = res.items;
|
|
}
|
|
|
|
this.form.controls['enddevice'].setValue(null);
|
|
this.form.controls['startZ'].setValue(null);
|
|
this.form.controls['startX'].setValue(null);
|
|
this.form.controls['startY'].setValue(null);
|
|
this.form.controls['endZ'].setValue(null);
|
|
this.form.controls['endX'].setValue(null);
|
|
this.form.controls['endY'].setValue(null);
|
|
}
|
|
}
|
|
public async enddeviceSelected(etasktype: any, eenddevice: any): Promise<void> {
|
|
|
|
if (etasktype && eenddevice) {
|
|
|
|
if (this._enddevice.find(item => item.id == eenddevice.value).devicekind == "10") {
|
|
//选择的是巷道 要加载Z
|
|
let res: any = await this._httpService.get(`autocommand/startzxy?startdevice=${eenddevice.value}`);
|
|
|
|
this._endZ = res.items;
|
|
}
|
|
this.form.controls['endZ'].setValue(null);
|
|
this.form.controls['endX'].setValue(null);
|
|
this.form.controls['endY'].setValue(null);
|
|
}
|
|
}
|
|
// 选择起始排Z,填充起始列X
|
|
public async startZSelected(estartdevice: any, estartZ: any): Promise<void> {
|
|
|
|
if (estartZ && estartdevice) {
|
|
|
|
let res: any = await this._httpService.get(`autocommand/startzxy?startdevice=${estartdevice.value}&z=${estartZ.value}`);
|
|
this._startX = res.items;
|
|
|
|
this.form.controls['startX'].setValue(null);
|
|
this.form.controls['startY'].setValue(null);
|
|
}
|
|
|
|
}
|
|
// 选择起始列X,填充起始层Y
|
|
public async startXSelected(estartdevice: any, estartZ: any, estartX: any): Promise<void> {
|
|
// 检查所有必要的参数是否都已提供
|
|
if (estartZ && estartdevice && estartX) {
|
|
|
|
let res: any = await this._httpService.get(`autocommand/startzxy?startdevice=${estartdevice.value}&z=${estartZ.value}&x=${estartX.value}`);
|
|
//debugger
|
|
|
|
this._startY = res.items;
|
|
|
|
this.form.controls['startY'].setValue(null);
|
|
}
|
|
}
|
|
public async endZSelected(eenddevice: any, eendZ: any): Promise<void> {
|
|
|
|
if (eenddevice && eendZ) {
|
|
|
|
let res: any = await this._httpService.get(`autocommand/startzxy?startdevice=${eenddevice.value}&z=${eendZ.value}`);
|
|
|
|
this._endX = res.items;
|
|
|
|
this.form.controls['endX'].setValue(null);
|
|
this.form.controls['endY'].setValue(null);
|
|
}
|
|
}
|
|
public async endXSelected(eenddevice: any, eendZ: any, eendX: any): Promise<void> {
|
|
|
|
if (eenddevice && eendZ && eendX) {
|
|
let res: any = await this._httpService.get(`autocommand/startzxy?startdevice=${eenddevice.value}&z=${eendZ.value}&x=${eendX.value}`);
|
|
|
|
this._endY = res.items;
|
|
|
|
this.form.controls['endY'].setValue(null);
|
|
}
|
|
}
|
|
|
|
|
|
public get form() {
|
|
return this._form;
|
|
};
|
|
public get tasktypelist() {
|
|
return this._tasktypelist;
|
|
};
|
|
public get startdevice() {
|
|
return this._startdevice;
|
|
};
|
|
public get startZ() {
|
|
return this._startZ;
|
|
};
|
|
public get startX() {
|
|
return this._startX;
|
|
};
|
|
public get startY() {
|
|
return this._startY;
|
|
};
|
|
public get enddevice() {
|
|
return this._enddevice;
|
|
};
|
|
public get endZ() {
|
|
return this._endZ;
|
|
};
|
|
public get endX() {
|
|
return this._endX;
|
|
};
|
|
public get endY() {
|
|
return this._endY;
|
|
};
|
|
|
|
// 下达自动任务,确定按钮
|
|
public save = async () => {
|
|
|
|
// 必须项目校验
|
|
if (this.form.controls.barcode.value == null || this.form.controls.tasktypelist.value == null
|
|
|| this.form.controls.startdevice.value == null || this.form.controls.enddevice.value == null) {
|
|
|
|
this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.error`));
|
|
this._saveyesno = false;
|
|
}
|
|
else {
|
|
|
|
// 条码校验
|
|
var barcode = this.form.controls.barcode.value;
|
|
var length = barcode.length;
|
|
// var pallettype = this.form.controls.pallettype.value;
|
|
// if(pallettype !=1 || pallettype !=2){
|
|
// this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.palletTypeeerror`));
|
|
// this._saveyesno = false;
|
|
// }
|
|
//add for JXYN
|
|
if (length > 20) {//条码长度判断 根据不同现场情况 需要改一下
|
|
this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.barCodeerror`));
|
|
this._saveyesno = false;
|
|
}
|
|
else if (this.form.controls.tasktypelist.value == 1) {
|
|
|
|
if (this.form.controls.endZ.value == null || this.form.controls.endX.value == null
|
|
|| this.form.controls.endY.value == null ||this.form.controls.pallettype == null) {
|
|
|
|
this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.error`));
|
|
this._saveyesno = false;
|
|
}
|
|
else {
|
|
this._saveyesno = true;
|
|
}
|
|
}
|
|
else if (this.form.controls.tasktypelist.value == 2) {
|
|
|
|
if (this.form.controls.startZ.value == null || this.form.controls.startX.value == null
|
|
|| this.form.controls.startY.value == null||this.form.controls.pallettype == null) {
|
|
|
|
this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.error`));
|
|
this._saveyesno = false;
|
|
}
|
|
else {
|
|
this._saveyesno = true;
|
|
}
|
|
}
|
|
else if (this.form.controls.tasktypelist.value == 3) {
|
|
|
|
if (this.form.controls.endZ.value == null || this.form.controls.endX.value == null
|
|
|| this.form.controls.endY.value == null || this.form.controls.startZ.value == null
|
|
|| this.form.controls.startX.value == null || this.form.controls.startY.value == null) {
|
|
|
|
this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.error`));
|
|
this._saveyesno = false;
|
|
}
|
|
else {
|
|
this._saveyesno = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (this._saveyesno) {
|
|
if (await this._dialogService.confirm(this._i18nService.translate('shared.notification.confirm'))) {
|
|
const data: any = {
|
|
barcode: this.form.controls.barcode.value,
|
|
pallettype: this.form.controls.pallettype.value==null ? "0" :this.form.controls.pallettype.value,
|
|
tasktype: this.form.controls.tasktypelist.value,
|
|
startdevice: this.form.controls.startdevice.value,
|
|
startZ: this.form.controls.startZ.value == null ? "0" : this.form.controls.startZ.value,
|
|
startX: this.form.controls.startX.value == null ? "0" : this.form.controls.startX.value,
|
|
startY: this.form.controls.startY.value == null ? "0" : this.form.controls.startY.value,
|
|
enddevice: this.form.controls.enddevice.value,
|
|
endZ: this.form.controls.endZ.value == null ? "0" : this.form.controls.endZ.value,
|
|
endX: this.form.controls.endX.value == null ? "0" : this.form.controls.endX.value,
|
|
endY: this.form.controls.endY.value == null ? "0" : this.form.controls.endY.value,
|
|
};
|
|
|
|
// call the Server HttpPost method
|
|
const res = await this._httpService.post(`autocommand`, data).catch(async err => {
|
|
switch (err.status) {
|
|
case 408:
|
|
this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.palletTypeeerror`));
|
|
break;
|
|
case 409:
|
|
this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.barCodeerror`));
|
|
break;
|
|
case 410:
|
|
this._toastService.show(this._i18nService.translate(`routes.wcs.autocommand.systemerror`));
|
|
break;
|
|
case 422:
|
|
this._toastService.show(this._i18nService.translate('routes.wcs.autocommand.systemerror'));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}) !== undefined;
|
|
if (res) {
|
|
this._toastService.show(this._i18nService.translate('shared.notification.success'));
|
|
this._dialogRef.close(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|