import { Component, OnInit, ViewChild } from '@angular/core'; import { CodeClassModel, DataResultT, OpMode, RhBaseDto, RhDynamicComponentFieldType, RhDynamicTableFieldDto, RhSafeAny, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { ApplianceInfoDto } from './../../mdp-model'; import { RhMouldDocumentService } from '../mould-document.service'; import { MsgHelper, ObjectHelper, RhApiUrlsService } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; @Component({ selector: 'rh-appliance-document', templateUrl: './appliance-document.component.html', styleUrls: ['./appliance-document.component.css'] }) export class RhApplianceDocumentComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; dataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; dataLoading = false; selectDatas!: ApplianceInfoDto[]; editDto: RhBaseDto = {}; currentType = 'add'; // 出入库按钮在多选状态下禁用 // inAndOutButtonDisable = true; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditTab(), true), new RhTableButtonInfoDto( 'delete', '删除', 'primary', true, 'delete', false, null, (datas) => this.deleteDatas(datas as ApplianceInfoDto[]), false, true ) ]; importButton: RhTableButtonInfoDto = new RhTableButtonInfoDto( 'import', '入库', 'default', false, 'vertical-align-bottom', false, null, (data) => this.putinStorage(data as ApplianceInfoDto[]), false, false, void 0, null, false ); // exportButton: RhTableButtonInfoDto = new RhTableButtonInfoDto( // 'export', // '空器具直发', // 'danger', // 'to-top', // false, // null, // (data: ApplianceInfoDto[]) => this.emptyPutoutStorage(data), // false, // false, // null, // null, // this.inAndOutButtonDisable // ); // extraButtonDataset: RhTableButtonInfoDto[] = [this.importButton, this.exportButton]; extraButtonDataset: RhTableButtonInfoDto[] = [this.importButton]; constructor(private apiUrls: RhApiUrlsService, public operator: RhMouldDocumentService) { // } ngOnInit(): void { // } setDatas(dataset: DataResultT) { this.dataresult = dataset; } setInitFieldDataset(item: CodeClassModel) { const tempDatas: RhDynamicComponentFieldType[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } getSelectDatas(items: ApplianceInfoDto[]) { this.selectDatas = items; } dataLoadingChange(status: boolean) { this.dataLoading = status; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } openEditTab(item?: RhBaseDto) { if (item) { this.editDto = item; this.editDto.OpSign = OpMode.OpEdit; this.currentType = 'edit'; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; this.currentType = 'add'; } this.selectedIndex = 1; } closeEditTab() { this.selectedIndex = 0; } deleteDatas(datas: ApplianceInfoDto[]) { MsgHelper.ShowConfirmModal('是否删除该器具', '删除后无法恢复,是否确认?', () => { this.operator.RemoveApplianceInfoDatas(datas).subscribe((res) => { if (res && res.Success) { MsgHelper.ShowSuccessMessage('删除成功!'); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`删除失败:${res.Message}`); } }); }); } onStoreData(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功!`); if (this.editDto.OpSign === OpMode.OpEdit) { this.selectedIndex = 0; } this.editDto = ObjectHelper.createRhBaseDto(); this.getDatas(); } else { MsgHelper.ShowWarningModal(`存储数据失败!${result.Message}`); } } /*************器具出入库相关**************/ putinStorage(data: ApplianceInfoDto[]) { MsgHelper.ShowConfirmModal('是否对该器具进行入库', '确认后无法恢复,是否继续?', () => { this.operator.ApplianceInStorage(data).subscribe((res) => { if (res && res.Success) { MsgHelper.ShowSuccessMessage('器具入库成功!'); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`器具入库失败!${res.Message}`); } }); }); } //空器具直发 // emptyPutoutStorage(data: ApplianceInfoDto[]) { // if (this.selectDatas.length > 1) { // MsgHelper.ShowWarningMessage('请选择一个器具进行直发!不可批量直发!'); // return; // } // // const opData = data[0]; // //器具生产状态【启用】、器具绑定状态【未绑定】、器具出入库状态【已入库】 // //opData.ProductionStatus === 'Enable' && opData.InventoryStatus === 'InStorage' // MsgHelper.ShowConfirmModal('是否对该器具进行直发', '确认后无法恢复,是否继续?', () => { // this.operator.EmptyApplianceOutStorage(data[0]).subscribe((res) => { // if (res && res.Success) { // MsgHelper.ShowSuccessMessage('空器具直发成功!'); // this.getDatas(); // } else { // MsgHelper.ShowWarningMessage(`空器具直发失败!${res.Message}`); // } // }); // }); // } /*************器具出入库相关**************/ }