business-classify-statistics.component.ts 7.9 KB

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