personnel-effectiveness-statistics.component.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import { TabService } from '../../services/tab.service';
  2. import { debounceTime } from 'rxjs/operators';
  3. import { Subject } from 'rxjs';
  4. import { NzMessageService } from 'ng-zorro-antd/message';
  5. import { Component, OnInit, HostListener, AfterViewInit, ViewChild } from "@angular/core";
  6. import { MainService } from 'src/app/services/main.service';
  7. import { ActivatedRoute } from '@angular/router';
  8. import { CustomChangeDateComponent } from '../../components/custom-change-date/custom-change-date.component';
  9. @Component({
  10. selector: "app-personnel-effectiveness-statistics",
  11. templateUrl: "./personnel-effectiveness-statistics.component.html",
  12. styleUrls: ["./personnel-effectiveness-statistics.component.less"],
  13. })
  14. export class PersonnelEffectivenessStatisticsComponent implements OnInit, AfterViewInit {
  15. @ViewChild('customChangeDate', { static: false }) customChangeDateComponent!: CustomChangeDateComponent;
  16. constructor(
  17. private mainService: MainService,
  18. private message: NzMessageService,
  19. private route: ActivatedRoute,
  20. private tabService: TabService,
  21. ) {}
  22. listOfData: any[] = []; //表格数据
  23. listOfDataEnd: any[] = []; //表格合计
  24. pageIndex: number = 1; //表格当前页码
  25. pageSize: number = 30; //表格每页展示条数
  26. listLength: number = 0; //表格总数据量
  27. matchUserCouont:number = 1;//排除异常人员
  28. searchTimerSubject = new Subject();
  29. ngOnInit() {
  30. this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
  31. let fun = v[0];
  32. fun.call(this, v[1]);
  33. });
  34. }
  35. ngAfterViewInit(){
  36. this.initSessionData();
  37. this.getQueryParams();
  38. setTimeout(() => {
  39. this.search();
  40. }, 0)
  41. this.onResize();
  42. }
  43. tableHeight:number = 0;
  44. @HostListener('window:resize')
  45. onResize(): void {
  46. setTimeout(() => {
  47. this.tableHeight = window.innerHeight - (document.querySelector('.searchDataWrap') as HTMLElement).offsetHeight - 64 - 36 - 48 - 8 - (document.querySelector('.ant-table-header') as HTMLElement).offsetHeight - 55 - this.getMoreFilter + 14;
  48. }, 0)
  49. }
  50. getQueryParams(){
  51. let queryParams = this.tabService.getQueryParams();
  52. this.tabService.clearQueryParams();
  53. if(queryParams.dateRange){
  54. this.dateRange = queryParams.dateRange;
  55. this.customChangeDateComponent.initByDate(this.dateRange);
  56. }
  57. }
  58. get getMoreFilter(){
  59. let flag = this.fieldConfig.fields.groupDTO || this.fieldConfig.fields.userDTO || this.fieldConfig.fields.category1DTO || this.fieldConfig.fields.category2DTO || this.fieldConfig.fields.category3DTO || this.fieldConfig.fields.buildingDTO || this.fieldConfig.fields.floorDTO || this.fieldConfig.fields.companyDTO || this.fieldConfig.fields.sourceDTO || this.fieldConfig.fields.repairDeptDTO;
  60. return flag ? 37 : 0;
  61. }
  62. // 初始化缓存数据
  63. queryType:any;
  64. hosId:any;
  65. dutyId:any;
  66. parentDutyId:any;
  67. initSessionData(){
  68. let newStatistics = JSON.parse(sessionStorage.getItem('newStatistics'));
  69. let queryType:any = newStatistics.queryType;
  70. let hosId:any = newStatistics.hospitalId;
  71. let dutyId:any = newStatistics.dutyId;
  72. queryType = queryType ? +queryType : undefined;
  73. hosId = hosId ? +hosId : undefined;
  74. dutyId = dutyId ? +dutyId : undefined;
  75. this.queryType = queryType;
  76. if(queryType == 1){
  77. this.hosId = undefined;
  78. this.dutyId = undefined;
  79. this.parentDutyId = undefined;
  80. }else if(queryType == 2){
  81. this.hosId = hosId;
  82. this.dutyId = undefined;
  83. this.parentDutyId = undefined;
  84. }else if(queryType == 3){
  85. this.hosId = undefined;
  86. this.dutyId = dutyId;
  87. this.parentDutyId = undefined;
  88. }else if(queryType == 4){
  89. this.hosId = undefined;
  90. this.dutyId = undefined;
  91. this.parentDutyId = dutyId;
  92. }
  93. }
  94. get getHosId(){
  95. return this.parentDutyId || this.dutyId || this.hosId;
  96. }
  97. // 表格数据
  98. loading1 = false;
  99. getList(num?: number, field?: string, sort?: string) {
  100. if (num !== undefined) {
  101. this.pageIndex = num;
  102. }
  103. let postData:any = {
  104. idx: this.pageIndex - 1,
  105. sum: this.pageSize,
  106. treeLevel: 1,
  107. startDate: this.customChangeDateComponent.startDate || undefined,
  108. endDate: this.customChangeDateComponent.endDate || undefined,
  109. hosId: this.hosId || undefined,
  110. dutyId: this.dutyId || undefined,
  111. parentDutyId: this.parentDutyId || undefined,
  112. matchUserCouont: this.matchUserCouont || undefined,
  113. groupId: this.fieldConfig.fields.userId ? undefined : (this.fieldConfig.fields.groupId || undefined),
  114. userId: this.fieldConfig.fields.userId || undefined,
  115. categoryId: this.fieldConfig.fields.categoryId || undefined,
  116. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  117. buildingId: this.fieldConfig.fields.buildingId || undefined,
  118. placeId: this.fieldConfig.fields.floorId || undefined,
  119. companyId: this.fieldConfig.fields.companyId || undefined,
  120. sourceId: this.fieldConfig.fields.sourceId || undefined,
  121. repairDeptId: this.fieldConfig.fields.repairDeptId || undefined,
  122. };
  123. if (field && sort) {
  124. postData.sort = `${field} ${sort === "ascend" ? `asc` : `desc`}`
  125. }
  126. this.loading1 = true;
  127. this.mainService
  128. .postCustom("itsm/report", "incidentWorkOrderUser", postData)
  129. .subscribe((result) => {
  130. this.loading1 = false;
  131. this.listOfData = result.dataList.filter((v, i) => { return i != result.dataList.length - 1 });
  132. this.listOfDataEnd = result.dataList.filter((v, i) => { return i == result.dataList.length - 1 });
  133. this.listLength = result.totalCount;
  134. });
  135. }
  136. // 列表排序
  137. sortCurrent:any = {};
  138. sortCurrentKey: string = "";
  139. sortCurrentValue: string | null = "";
  140. sort(e) {
  141. const { key, value } = e;
  142. this.sortCurrentKey = key;
  143. this.sortCurrentValue = value;
  144. this.getList(this.pageIndex, this.sortCurrentKey, this.sortCurrentValue);
  145. }
  146. // 搜索
  147. search() {
  148. this.getList(1, this.sortCurrentKey, this.sortCurrentValue);
  149. }
  150. // 日期选择
  151. dateRange: any = [];
  152. // 导出
  153. excelExportLoading:any = false;
  154. excelExport(){
  155. this.excelExportLoading = this.message.loading("导出中..", {
  156. nzDuration: 0,
  157. }).messageId;
  158. let postData:any = {
  159. treeLevel: 1,
  160. startDate: this.customChangeDateComponent.startDate || undefined,
  161. endDate: this.customChangeDateComponent.endDate || undefined,
  162. hosId: this.hosId || undefined,
  163. dutyId: this.dutyId || undefined,
  164. parentDutyId: this.parentDutyId || undefined,
  165. matchUserCouont: this.matchUserCouont || undefined,
  166. groupId: this.fieldConfig.fields.userId ? undefined : (this.fieldConfig.fields.groupId || undefined),
  167. userId: this.fieldConfig.fields.userId || undefined,
  168. categoryId: this.fieldConfig.fields.categoryId || undefined,
  169. hierarchy: this.fieldConfig.fields.hierarchy || undefined,
  170. buildingId: this.fieldConfig.fields.buildingId || undefined,
  171. placeId: this.fieldConfig.fields.floorId || undefined,
  172. companyId: this.fieldConfig.fields.companyId || undefined,
  173. sourceId: this.fieldConfig.fields.sourceId || undefined,
  174. repairDeptId: this.fieldConfig.fields.repairDeptId || undefined,
  175. };
  176. if (this.sortCurrentKey && this.sortCurrentValue) {
  177. postData.sort = `${this.sortCurrentKey} ${this.sortCurrentValue === "ascend" ? `asc` : `desc`}`
  178. }
  179. this.mainService
  180. .postExportCustom("itsm/export", "incidentWorkOrderUser", postData)
  181. .subscribe((data) => {
  182. this.message.remove(this.excelExportLoading);
  183. this.excelExportLoading = false;
  184. this.message.success('导出成功');
  185. var file = new Blob([data], {
  186. type: "application/vnd.ms-excel",
  187. });
  188. //trick to download store a file having its URL
  189. var fileURL = URL.createObjectURL(file);
  190. var a = document.createElement("a");
  191. a.href = fileURL;
  192. a.target = "_blank";
  193. a.download = `${this.route.parent.routeConfig.data.title}.xls`;
  194. document.body.appendChild(a);
  195. a.click();
  196. },(err) => {
  197. this.message.remove(this.excelExportLoading);
  198. this.excelExportLoading = false;
  199. this.message.error('导出失败');
  200. });
  201. }
  202. // 重置
  203. reset(){
  204. this.sortCurrentKey = "";
  205. this.sortCurrentValue = "";
  206. this.sortCurrent = {};
  207. this.dateRange = []
  208. this.matchUserCouont = 1;
  209. this.fieldConfig.fields = {groupId: undefined, userId: undefined, categoryId: undefined, buildingId: undefined, floorId: undefined, companyId: undefined, sourceId: undefined, repairDeptId: undefined};
  210. this.customChangeDateComponent.resetByDate();
  211. setTimeout(_=>{
  212. this.search();
  213. })
  214. }
  215. // 详细搜索
  216. fieldConfig:any = {
  217. fields: {groupId: undefined, userId: undefined, categoryId: undefined, buildingId: undefined, floorId: undefined, companyId: undefined, sourceId: undefined, repairDeptId: undefined},
  218. config: {groupAndUser: true, category123: true, buildingAndFloor: true, company: true, source: true, repairDept: true},
  219. }
  220. showSearchMore:boolean = false;
  221. showMore(){
  222. this.showSearchMore = true;
  223. }
  224. cancelEvent(){
  225. this.showSearchMore = false;
  226. }
  227. submitEvent(fields){
  228. this.showSearchMore = false;
  229. this.fieldConfig.fields = fields;
  230. console.log('this.fieldConfig.fields:', this.fieldConfig.fields)
  231. this.search();
  232. this.onResize();
  233. }
  234. }