import { RhConfigManageService } from './../config-manage.service'; import { Component, OnInit, ViewChild } from '@angular/core'; import { DataResultT, RhSelectableDto, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto, RhTableButtonInfoDto, RhBaseDto, OpMode, OrderStatusParasDto, RhSafeAny } from 'rh-base/model'; import { MsgHelper, ObjectHelper } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; @Component({ selector: 'rh-order-status-paras', templateUrl: './order-status-paras.component.html', styleUrls: ['./order-status-paras.component.less'] }) export class RhOrderStatusParasComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; editDto: RhBaseDto = {}; dataLoading = false; dataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('editInfo', '编辑数据', 'default', false, 'edit', false, null, (data) => this.openEditModal(data as RhBaseDto)) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('newButton', '新建', 'primary', false, 'file', false, null, () => this.openEditModal(), true), new RhTableButtonInfoDto( 'delete', '删除数据', 'primary', true, 'delete', true, null, (datas) => { this.removeOrderStatusDatas(datas as OrderStatusParasDto[]); }, false ) ]; /** 触发动态form rhValue值变更 */ __flagIndex = 0; constructor(public operator: RhConfigManageService) { // } ngOnInit(): void { // this.editDto = this.initEditDto(); } openEditModal(data?: RhBaseDto) { // if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = this.initEditDto(); } 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}数据成功!`); this.editDto = ObjectHelper.createRhBaseDto(); if (this.editDto.OpSign === OpMode.OpEdit) { this.selectedIndex = 0; } else { // 要保留editform的一些参数需要在这边做处理 const oldValue = result.httpRequestPara as OrderStatusParasDto; const tempDto = this.initEditDto(); tempDto['BusinessTypeCode'] = oldValue?.BusinessTypeCode; tempDto['BusinessTypeName'] = oldValue?.BusinessTypeName; tempDto['IsUse'] = true; tempDto['__flag'] = this.__flagIndex++; this.editDto = tempDto; } this.getDatas(); } else { MsgHelper.ShowWarningModal(`存储数据失败!${result.Message}`); } } setInitFieldDatset(item: CodeClassModel) { const tempDatas: RhDynamicTableFieldDto[] = []; 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); } } private initEditDto(): RhBaseDto { const editDto: RhBaseDto = {}; editDto.OpSign = OpMode.OpAdd; return editDto; } private removeOrderStatusDatas(datas: OrderStatusParasDto[]) { MsgHelper.ShowGlobalLoadingMessage('正在删除数据,请稍候...'); this.operator.RemoveOrderStatusParasDatas(datas as RhBaseDto[]).subscribe( (result) => { if (result?.Success) { MsgHelper.ShowSuccessMessage(`数据删除成功!`); this.getDatas(); } else { MsgHelper.ShowWarningModal(`数据删除失败!${result.Message}`); } MsgHelper.CloseGlobalLoadingMessage(); }, () => MsgHelper.CloseGlobalLoadingMessage() ); } }