review.component.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {
  2. Component,
  3. OnInit,
  4. Input,
  5. ViewChild,
  6. ComponentFactoryResolver
  7. } from "@angular/core";
  8. import { Router } from "@angular/router";
  9. import { InvestmentProposalForm } from "@app/models/investment-proposal-form";
  10. import { FormInvestmentProposalService } from "@app/services/form-investment-proposal.service";
  11. import { Instrument } from "@app/models/instrument";
  12. import { InvestmentProposalWorkflowService } from "@app/services/investment-proposal-workflow.service";
  13. import { InstrumentDirective } from "../instrument/instrument.directive";
  14. import { InstrumentComponent } from "../instrument/instrument.component";
  15. import { InstrumentsService } from "@app/services/instruments.service";
  16. import Swal from "sweetalert2";
  17. @Component({
  18. selector: "app-investment-proposal-review",
  19. templateUrl: "./review.component.html",
  20. styleUrls: ["./review.component.scss"]
  21. })
  22. export class InvestmentProposalReviewComponent implements OnInit {
  23. title = "Revisión de propuesta";
  24. @Input() ads: Instrument[];
  25. @Input() formData: InvestmentProposalForm;
  26. @ViewChild(InstrumentDirective, { static: true })
  27. adHost: InstrumentDirective;
  28. isFormValid: boolean = false;
  29. general: any;
  30. instrument: any;
  31. complement: any;
  32. final: any;
  33. workType: string;
  34. form: any;
  35. currentAdIndex = -1;
  36. interval: any;
  37. indexDynamicComponent: number;
  38. constructor(
  39. private router: Router,
  40. private formDataService: FormInvestmentProposalService,
  41. private componentFactoryResolver: ComponentFactoryResolver,
  42. private instrumentService: InvestmentProposalWorkflowService,
  43. private loadInstrumentsService: InstrumentsService
  44. ) {}
  45. ngOnInit() {
  46. this.formData = this.formDataService.getFormData();
  47. this.isFormValid = this.formDataService.isFormValid();
  48. this.ads = this.loadInstrumentsService.getInstruments();
  49. this.formData.instrumentos;
  50. this.indexDynamicComponent = this.ads.findIndex(
  51. x => x.component.name == this.formData.instrumentos
  52. );
  53. if (this.indexDynamicComponent >= 0) {
  54. this.loadComponent();
  55. } else {
  56. console.log("No existe el componente");
  57. }
  58. this.general = this.formDataService.getGeneralInfo();
  59. this.instrument = this.formDataService.getWork();
  60. this.complement = this.formDataService.getComplementInfo();
  61. this.final = {};
  62. Object.assign(this.final, this.general, this.instrument, this.complement);
  63. console.log("Result feature loaded!");
  64. console.log(this.final);
  65. }
  66. loadComponent() {
  67. this.currentAdIndex = this.indexDynamicComponent % this.ads.length;
  68. const adItem = this.ads[this.currentAdIndex];
  69. const componentFactory = this.componentFactoryResolver.resolveComponentFactory(
  70. adItem.component
  71. );
  72. const viewContainerRef = this.adHost.viewContainerRef;
  73. viewContainerRef.clear();
  74. const componentRef = viewContainerRef.createComponent(componentFactory);
  75. (<InstrumentComponent>componentRef.instance).data = adItem.data;
  76. (<InstrumentComponent>componentRef.instance).summary = true;
  77. }
  78. approve_proposal() {
  79. (async () => {
  80. const { value: formValues } = await Swal.fire({
  81. title: "<h3>Aprobar propuesta de inversión</h3>",
  82. icon: "info",
  83. input: "textarea",
  84. showCancelButton: true,
  85. confirmButtonText: "Aprobar propuesta",
  86. cancelButtonText: "Cancelar",
  87. inputValidator: value => {
  88. if (!value) {
  89. return "Debe ingresar un comentario";
  90. }
  91. }
  92. });
  93. if (formValues) {
  94. Swal.fire(JSON.stringify(formValues));
  95. }
  96. })();
  97. }
  98. dismiss_proposal() {
  99. (async () => {
  100. const { value: formValues } = await Swal.fire({
  101. title: "<h3>Rechazar propuesta de inversión</h3>",
  102. icon: "info",
  103. input: "textarea",
  104. showCancelButton: true,
  105. confirmButtonText: "Rechazar propuesta",
  106. confirmButtonColor: "#C82333",
  107. cancelButtonText: "Cancelar",
  108. inputValidator: value => {
  109. if (!value) {
  110. return "Debe ingresar un comentario";
  111. }
  112. }
  113. });
  114. if (formValues) {
  115. Swal.fire(JSON.stringify(formValues));
  116. }
  117. })();
  118. }
  119. }