socials-associate.component.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { ChangeDetectionStrategy, ViewContainerRef, ChangeDetectorRef, Component, OnInit } from '@angular/core';
  17. import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  18. import { _HttpClient } from '@delon/theme';
  19. import { format, addDays } from 'date-fns';
  20. import { NzSafeAny } from 'ng-zorro-antd/core/types';
  21. import { NzMessageService } from 'ng-zorro-antd/message';
  22. import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
  23. import { NzTableQueryParams } from 'ng-zorro-antd/table';
  24. import { logging } from 'protractor';
  25. import { SocialsAssociateService } from '../../../service/socials-associate.service';
  26. import { SocialsProviderService } from '../../../service/socials-provider.service';
  27. import { set2String } from '../../../shared/index';
  28. import { log } from 'console';
  29. @Component({
  30. selector: 'app-socials-associate',
  31. templateUrl: './socials-associate.component.html',
  32. styleUrls: ['./socials-associate.component.less']
  33. })
  34. export class SocialsAssociateComponent implements OnInit {
  35. query: {
  36. params: {
  37. providerName: String;
  38. displayName: String;
  39. employeeNumber: String;
  40. startDate: String;
  41. endDate: String;
  42. startDatePicker: Date;
  43. endDatePicker: Date;
  44. pageSize: number;
  45. pageNumber: number;
  46. pageSizeOptions: number[];
  47. };
  48. results: {
  49. records: number;
  50. rows: NzSafeAny[];
  51. };
  52. expandForm: Boolean;
  53. submitLoading: boolean;
  54. tableLoading: boolean;
  55. tableCheckedId: Set<String>;
  56. indeterminate: boolean;
  57. checked: boolean;
  58. } = {
  59. params: {
  60. providerName: '',
  61. displayName: '',
  62. employeeNumber: '',
  63. startDate: '',
  64. endDate: '',
  65. startDatePicker: addDays(new Date(), -30),
  66. endDatePicker: new Date(),
  67. pageSize: 10,
  68. pageNumber: 1,
  69. pageSizeOptions: [10, 20, 50]
  70. },
  71. results: {
  72. records: 0,
  73. rows: []
  74. },
  75. expandForm: false,
  76. submitLoading: false,
  77. tableLoading: false,
  78. tableCheckedId: new Set<String>(),
  79. indeterminate: false,
  80. checked: false
  81. };
  82. constructor(
  83. private modalService: NzModalService,
  84. private socialsProviderService: SocialsProviderService,
  85. private socialsAssociateService: SocialsAssociateService,
  86. private viewContainerRef: ViewContainerRef,
  87. private fb: FormBuilder,
  88. private msg: NzMessageService,
  89. private cdr: ChangeDetectorRef
  90. ) { }
  91. ngOnInit(): void {
  92. this.fetch();
  93. }
  94. onQueryParamsChange(tableQueryParams: NzTableQueryParams): void {
  95. this.query.params.pageNumber = tableQueryParams.pageIndex;
  96. this.query.params.pageSize = tableQueryParams.pageSize;
  97. this.fetch();
  98. }
  99. onSearch(): void {
  100. this.fetch();
  101. }
  102. onReset(): void { }
  103. onAdd(e: MouseEvent, provider: string): void {
  104. e.preventDefault();
  105. this.socialsProviderService.authorize(provider).subscribe(res => {
  106. //console.log(res.data);
  107. window.location.href = res.data;
  108. });
  109. }
  110. onDelete(e: MouseEvent, deleteId: String): void {
  111. e.preventDefault();
  112. this.socialsAssociateService.delete(deleteId).subscribe(res => {
  113. if (res.code == 0) {
  114. this.msg.success(`提交成功`);
  115. this.fetch();
  116. } else {
  117. this.msg.success(`提交失败`);
  118. }
  119. this.cdr.detectChanges();
  120. });
  121. }
  122. fetch(): void {
  123. this.query.submitLoading = true;
  124. this.query.tableLoading = true;
  125. this.query.indeterminate = false;
  126. this.query.checked = false;
  127. this.query.tableCheckedId.clear();
  128. if (this.query.expandForm) {
  129. this.query.params.endDate = format(this.query.params.endDatePicker, 'yyyy-MM-dd HH:mm:ss');
  130. this.query.params.startDate = format(this.query.params.startDatePicker, 'yyyy-MM-dd HH:mm:ss');
  131. } else {
  132. this.query.params.endDate = '';
  133. this.query.params.startDate = '';
  134. }
  135. this.socialsAssociateService.fetch(this.query.params).subscribe(res => {
  136. console.log(res.data);
  137. this.query.results.rows = res.data;
  138. this.query.submitLoading = false;
  139. this.query.tableLoading = false;
  140. this.cdr.detectChanges();
  141. });
  142. }
  143. updateTableCheckedSet(id: String, checked: boolean): void {
  144. if (checked) {
  145. this.query.tableCheckedId.add(id);
  146. } else {
  147. this.query.tableCheckedId.delete(id);
  148. }
  149. }
  150. refreshTableCheckedStatus(): void {
  151. const listOfEnabledData = this.query.results.rows.filter(({ disabled }) => !disabled);
  152. this.query.checked = listOfEnabledData.every(({ id }) => this.query.tableCheckedId.has(id));
  153. this.query.indeterminate = listOfEnabledData.some(({ id }) => this.query.tableCheckedId.has(id)) && !this.query.checked;
  154. }
  155. onTableItemChecked(id: String, checked: boolean): void {
  156. this.updateTableCheckedSet(id, checked);
  157. this.refreshTableCheckedStatus();
  158. }
  159. onTableAllChecked(checked: boolean): void {
  160. this.query.results.rows.filter(({ disabled }) => !disabled).forEach(({ id }) => this.updateTableCheckedSet(id, checked));
  161. this.refreshTableCheckedStatus();
  162. }
  163. }