Broker System for Supercredit
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

81 行
2.0KB

  1. import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
  2. import {LoanModel} from '../models/loan.model';
  3. import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
  4. import {ListAllLoansComponent} from '../list-all-loans/list-all-loans.component';
  5. @Component({
  6. selector: 'app-loan-select',
  7. templateUrl: './loan-select.component.html',
  8. styleUrls: ['./loan-select.component.scss'],
  9. providers: [
  10. {
  11. provide: NG_VALUE_ACCESSOR,
  12. multi: true,
  13. useExisting: LoanSelectComponent
  14. }
  15. ]
  16. })
  17. export class LoanSelectComponent implements OnInit, ControlValueAccessor {
  18. @ViewChild('list', {static: false} ) list: ListAllLoansComponent;
  19. @Input() Max = 1; // we do not support multiple loan selection at the moment
  20. @Input() readOnly = false;
  21. @Output() valueChange: EventEmitter<LoanModel> = new EventEmitter<LoanModel>();
  22. public Loan: LoanModel; // for multiple selection ,it has to be array; we don't support it now.
  23. // popup
  24. public showPopup = false;
  25. public Offset = { left: 10, top: 48 };
  26. // formControl state
  27. private disabled = false;
  28. private touched = false;
  29. // Control Value Accessor
  30. onChange = (Loan) => {}; // empty
  31. onTouched = () => {};
  32. constructor() { }
  33. ngOnInit(): void {
  34. console.log('init loan-select', this);
  35. }
  36. writeValue(loan: LoanModel): void {
  37. this.Loan = loan;
  38. }
  39. registerOnChange(onChange: any): void {
  40. this.onChange = onChange;
  41. }
  42. registerOnTouched(onTouched: any): void {
  43. this.onTouched = onTouched;
  44. }
  45. private markAsTouched(): void {
  46. if (!this.touched) {
  47. this.onTouched();
  48. this.touched = true;
  49. }
  50. }
  51. onLoanSelected(loan: LoanModel): void {
  52. if (this.Loan.Id !== loan.Id){
  53. this.valueChange.emit(loan);
  54. this.onChange(loan);
  55. this.Loan = loan;
  56. }
  57. this.Loan = loan;
  58. this.markAsTouched();
  59. this.onTouched();
  60. this.showPopup = false;
  61. }
  62. public onToggle(): void {
  63. this.showPopup = !this.showPopup;
  64. }
  65. }