import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { RhSupplierDocumentService } from './../supplier-document.service'; import { SupplierInfoQueryDto, OrderStatusParasQueryDto, OrderStatusParasDto, SupplierInfoDto, SupplierShippingParameterBatchStoreDto, ExtSupplierQueryDto, ExtSupplierInfo, SupplierInfoExtProperyQueryDto } from './../../mdp-model'; import { Component, OnInit, ViewChild } from '@angular/core'; import { DataResultT, RhSelectableDto, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto, RhTableButtonInfoDto, RhBaseDto, OpMode, RhSafeAny, RhInterfaceLocationDto, RhDynamicComponentFieldType } from 'rh-base/model'; import { DynamicFormComponent } from 'rh-base/shared'; import { MsgHelper, FormHelper, ObjectHelper, RhApiUrlsService } from 'rh-base/core'; type EditModeType = 'edit' | 'setting'; type displayDto = RhSelectableDto & { name: string; displayName: string; }; @Component({ selector: 'rh-suppliter-info-setting', templateUrl: './suppliter-info-setting.component.html', styleUrls: ['./suppliter-info-setting.component.less'] }) export class RhSuppliterInfoSettingComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; editDto: RhBaseDto = {}; dataLoading = false; dataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; supplierDatas: SupplierInfoDto[] = []; supplierDataset!: displayDto[]; checkedSupplierDataset: displayDto[] = []; selectedData!: SupplierInfoDto; batchValue: RhBaseDto = {}; businessType: OrderStatusParasDto[] = []; // FIXME: // setttingLoading = false; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditModal(data as RhBaseDto), true) // new RhTableButtonInfoDto('setting', '配置', 'default', 'setting', false, null, (data) => this.openSettingModal(data as RhBaseDto), true) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditModal(), true), new RhTableButtonInfoDto('setting', '扩展配置', 'default', false, 'setting', false, null, () => this.openSettingModal(), true) ]; extraButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('sync', '同步', 'primary', false, 'sync', false, null, () => this.openSyncModal(), true) ]; editMode: EditModeType = 'edit'; // 同步供应商信息 syncSupplierList: ExtSupplierInfo[] = []; selectedSyncSuppliers: SupplierInfoDto[] = []; isShowSyncModal = false; extDataLoading = false; // 批量配置 batchStoreForm!: UntypedFormGroup; batchStoreDto!: SupplierShippingParameterBatchStoreDto; submitBatchDatasLoading = false; /** 选中的业务类型 */ selectedBusinessType!: string; constructor(private operator: RhSupplierDocumentService, private fb: UntypedFormBuilder, private apiUrl: RhApiUrlsService) { // } ngOnInit(): void { this.getSupplierDatas(); this.getSupplierBusinessType(); this.batchStoreDto = this.initBatchStoreDto(); this.createBatchStoreForm(this.batchStoreDto); } //#region 基础crud openEditModal(data?: RhBaseDto) { // this.editMode = 'edit'; if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; } this.selectedIndex = 1; } closeEditModal() { // this.selectedIndex = 0; } setDatas(dataset: DataResultT) { this.dataresult = dataset; } dataLoadingChange(status: boolean) { this.dataLoading = status; } 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}`); } } setInitFieldDatset(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]; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } //调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } //#endregion 基础crud // //#region 扩展配置tab private getSupplierDatas() { const queryDto = SupplierInfoQueryDto.create(); queryDto.Mode = 8; this.operator.GetSupplierInfoDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.supplierDatas = result.Attach; this.supplierDataset = result.Attach.map((ele) => { return { name: ele.SupplierCode as string, displayName: ele.SupplierName as string }; }); } else { this.supplierDatas = []; this.supplierDataset = []; MsgHelper.ShowWarningMessage(`获取供应商列表失败!`); } }); } // 获取BusinessType getSupplierBusinessType() { const queryDto = OrderStatusParasQueryDto.create(); queryDto.BusinessTypeCode = 'SupplierBusinessType'; this.operator.GetOrderStatusParasDatas(queryDto).subscribe((result) => { if (result && result.Success) { this.businessType = result.Attach.reverse(); /** 选中业务类型默认为第一个 */ this.selectedBusinessType = this.businessType[0].OrderStatusName as string; } else { this.businessType = []; this.selectedBusinessType = ''; } }); } initParConfigDtos() { this.businessType.forEach((ele) => { ele.ParDto = {}; ele.ParDto.OpSign = OpMode.OpEdit; }); } openSettingModal() { this.initParConfigDtos(); this.editMode = 'setting'; this.selectedIndex = 1; // 默认选中第一条数据 this.supplierDataset[0].select = true; this.onSelectSupplierData(this.supplierDataset[0]); } closeSettingModal() { this.selectedIndex = 0; this.checkedSupplierDataset = []; this.supplierDataset.forEach((item) => { item.select = false; item.check = false; }); } // 获取数据的通用方法(参数类型和对应接口进行匹配) getParConfigFormData(business: string) { const queryDto = SupplierInfoExtProperyQueryDto.create(); queryDto.SupplierCode = this.selectedData.SupplierCode; const index = this.businessType.findIndex((ele) => ele.OrderStatusName === business); switch (business) { // 报工参数 case 'ShippingParameter': // this.getParameterData('GetSupplierShippingParameterData', index); this.operator.GetSupplierShippingParameterData(queryDto).subscribe((result) => { if (result && result.Success) { this.businessType[index].ParDto = result.Attach; ObjectHelper.MapT(this.selectedData, this.businessType[index].ParDto); } else { this.businessType[index].ParDto = {}; } this.businessType[index].ParDto.OpSign = OpMode.OpEdit; }); break; default: this.businessType[index].ParDto = {}; this.businessType[index].ParDto.OpSign = OpMode.OpEdit; break; } } getParameterData(interfaceName: string, index: number) { const interfaceDto: RhInterfaceLocationDto = { interfaceType: 'post', port: 52880, controllerName: 'SupplierWebApi', interfaceName: interfaceName }; this.apiUrl .httpHandler(interfaceDto, { SupplierCode: this.selectedData.SupplierCode }) .subscribe((result) => { if (result && result.Success) { this.businessType[index].ParDto = result.Attach; ObjectHelper.MapT(this.selectedData, this.businessType[index].ParDto); // console.log(ele.ParDto); } else { this.businessType[index].ParDto = {}; } this.businessType[index].ParDto.OpSign = OpMode.OpEdit; }); } onSelectSupplierData(item: displayDto) { this.supplierDataset.forEach((ele) => (ele.check = false)); this.checkedSupplierDataset = []; this.selectedData = this.supplierDatas.find((ele) => ele.SupplierCode === item.name) as SupplierInfoDto; this.getParConfigFormData(this.selectedBusinessType); } onStoreSettingData(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`配置成功`); } else { MsgHelper.ShowWarningModal(`配置失败!${result.Message}`); } } onCheckSupplierData() { this.checkedSupplierDataset = []; this.batchValue['SupplierInfoDtos'] = []; this.checkedSupplierDataset = this.supplierDataset.filter((ele) => ele.check); if (this.checkedSupplierDataset.length > 0) { this.supplierDataset.forEach((ele) => (ele.select = false)); this.checkedSupplierDataset.forEach((ele) => { const dto = this.supplierDatas.find((item) => item.SupplierCode === ele.name); this.batchValue['SupplierInfoDtos'].push(dto); this.batchValue = { ...this.batchValue }; }); } else { this.clearDtos(); } } clearDtos() { this.businessType.forEach((ele) => (ele.ParDto = {})); this.businessType = [...this.businessType]; this.supplierDataset.forEach((ele) => (ele.check = false)); this.checkedSupplierDataset = []; } // 批量配置 initBatchStoreDto(): SupplierShippingParameterBatchStoreDto { const dto = SupplierShippingParameterBatchStoreDto.create(); return dto; } createBatchStoreForm(dto: SupplierShippingParameterBatchStoreDto) { this.batchStoreForm = this.fb.group({ RequireShippingPlanConfirm: [false] }); } resetBatchStoreForm($event: Event | null) { if ($event) { $event.preventDefault(); } this.batchStoreDto = this.initBatchStoreDto(); this.batchStoreForm.reset(this.batchStoreDto); } submitBatchStoreForm($event: Event) { if ($event) { $event.preventDefault(); } this.submitBatchDatasLoading = true; FormHelper.YGSubmitForm( this.batchStoreDto, this.batchStoreForm, (dto) => { this.operator.StoreSupplierShippingParameterDatas(dto as RhSafeAny).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`批量配置成功`); this.clearDtos(); this.resetBatchStoreForm(null); } else { MsgHelper.ShowWarningMessage(`批量配置失败:${result.Message}`); } this.submitBatchDatasLoading = false; }); }, () => { this.submitBatchDatasLoading = false; } ); } //#endregion // //#region ************ 同步供应商信息 ************** openSyncModal() { this.loadSupplierFromOtherSystems(); this.isShowSyncModal = true; } closeSyncModal() { this.syncSupplierList.forEach((ele) => (ele.select = false)); this.isShowSyncModal = false; } // 载入供应商信息 loadSupplierFromOtherSystems() { const queryDto = ExtSupplierQueryDto.create(); queryDto.Mode = 8; this.extDataLoading = true; this.operator.GetExtSupplierInfo(queryDto).subscribe( (result) => { if (result && result.Success) { this.syncSupplierList = result.Attach; } else { this.syncSupplierList = []; MsgHelper.ShowWarningModal(`获取第三方用户数据失败!${result.Message}`); } this.extDataLoading = false; }, () => (this.extDataLoading = false) ); } // 获取所选供应商信息 getSelectedDataset(dtos: SupplierInfoDto[]) { this.selectedSyncSuppliers = dtos; } itemSelectStatusChange(dto: SupplierInfoDto) { (this.syncSupplierList.find((ele) => ele.SupplierCode === dto.SupplierCode) as ExtSupplierInfo).select = false; } // 保存所选供应商信息 saveSuppliers() { this.operator.StoreSupplierInfoDatas(this.selectedSyncSuppliers).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`保存成功!`); this.syncSupplierList = []; this.getDatas(); this.closeSyncModal(); } else { MsgHelper.ShowWarningModal(`保存失败!${result.Message}`); } }); } //#endregion // /** 切换tab页动作 */ selectedTabChange(business: string) { if (this.selectedBusinessType === 'business') { return; } else { this.selectedBusinessType = business; this.getParConfigFormData(business); } } }