epg-clone.component.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
  2. import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  3. import { NzMessageService } from 'ng-zorro-antd/message';
  4. import { firstValueFrom } from 'rxjs';
  5. import { FormUtils } from 'src/app/lib/utils/form-utils';
  6. import { EpgService } from './epg.service';
  7. @Component({
  8. selector: 'app-epg-copy',
  9. template: `
  10. <div style="color: orange; margin-bottom: 10px">
  11. <i nz-icon nzType="info-circle" nzTheme="outline"></i>
  12. <ng-container i18n>克隆源: {{srcEpg.epgId}}, 请输入新的EPG信息: </ng-container>
  13. </div>
  14. <form [formGroup]="form" autocomplete="off" (ngSubmit)="onSubmit()" novalidate class="form-horizontal ">
  15. <nz-form-item>
  16. <nz-form-control i18n-nzErrorTip nzErrorTip="请输入新epgId">
  17. <nz-input-group nzPrefixIcon="user">
  18. <input nz-input formControlName="epgId" i18n-placeholder placeholder="新 EPG id">
  19. </nz-input-group>
  20. </nz-form-control>
  21. </nz-form-item>
  22. <nz-form-item>
  23. <nz-form-control i18n-nzErrorTip nzErrorTip="请输入描述信息">
  24. <nz-input-group nzPrefixIcon="user">
  25. <input nz-input formControlName="desc" i18n-placeholder placeholder="描述">
  26. </nz-input-group>
  27. </nz-form-control>
  28. </nz-form-item>
  29. <div class="d-flex flex-row-reverse">
  30. <button nz-button nzType="primary" nzBlock type="submit" [disabled]="isLoading" i18n>拷贝</button>
  31. </div>
  32. </form>
  33. `,
  34. styles: [
  35. ]
  36. })
  37. export class EpgCloneComponent implements OnInit {
  38. @Input() srcEpg: any;
  39. @Output() onSuccess = new EventEmitter<any>();
  40. @Output() onError = new EventEmitter<any>();
  41. form: FormGroup;
  42. isLoading = false;
  43. constructor(
  44. private epgService: EpgService,
  45. private fb: FormBuilder,
  46. private message: NzMessageService,
  47. ) { }
  48. ngOnInit(): void {
  49. this.form = this.fb.group({
  50. epgId: [null, [Validators.required]],
  51. desc: [null],
  52. })
  53. }
  54. onSubmit() {
  55. if (this.form.invalid) {
  56. FormUtils.markAsDirty(this.form);
  57. return;
  58. }
  59. this.isLoading = true;
  60. let data = Object.assign({}, this.form.value, { columns: this.srcEpg.columns, status: this.srcEpg.status });
  61. firstValueFrom(this.epgService.epgAdd(data))
  62. .then(res => {
  63. this.onSuccess.emit(data);
  64. this.message.success($localize`添加成功, 请继续完善栏目信息`);
  65. })
  66. .catch(err => {
  67. this.message.error(err.error?.message || err.message);
  68. this.onError.emit(err);
  69. }).then(() => {
  70. this.isLoading = false;
  71. })
  72. }
  73. }