group-statistics.component.ts 7.8 KB

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